airsmodel 0.2.44__tar.gz → 0.2.45__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: airsmodel
3
- Version: 0.2.44
3
+ Version: 0.2.45
4
4
  Summary: ARLAS Item Registration Service Model
5
5
  Home-page: UNKNOWN
6
6
  Author: Gisaïa
@@ -6,7 +6,7 @@ with open("README.md", "r") as fh:
6
6
 
7
7
  setuptools.setup(
8
8
  name="airsmodel",
9
- version="0.2.44",
9
+ version="0.2.45",
10
10
  author="Gisaïa",
11
11
  description="ARLAS Item Registration Service Model",
12
12
  long_description=long_description,
@@ -0,0 +1,121 @@
1
+ import json
2
+ import datetime
3
+
4
+ from airs.core.models.model import Item
5
+
6
+
7
+ def serialize_datetime(obj):
8
+ if isinstance(obj, datetime.datetime):
9
+ return int(obj.timestamp())
10
+ raise TypeError("Type not serializable")
11
+
12
+
13
+ def to_airs_item(item: Item) -> Item:
14
+ """ Takes an item and makes sure to map the namespace fields to AIRS Item. Keys can contain : as namespace seperator
15
+
16
+ Args:
17
+ item (Item): The item (with : namespace separator)
18
+
19
+ Returns:
20
+ item: The airs item
21
+ """
22
+ dictionary = item.model_dump(exclude_unset=True, by_alias=True, exclude_none=True)
23
+ return Item(**__replaceKeys(dictionary, ":", "__"))
24
+
25
+
26
+ def to_dict(item: Item) -> dict:
27
+ """ create a dictionnary from the Item. Keys contain : as namespace seperator
28
+
29
+ Args:
30
+ item (Item): The item
31
+
32
+ Returns:
33
+ dict: The dictionary. Keys contain : as namespace seperator
34
+ """
35
+ dictionary = item.model_dump(exclude_unset=True, by_alias=True, exclude_none=True)
36
+ return __replaceKeys(dictionary, "__", ":")
37
+
38
+
39
+ def to_airs_dict(item: Item) -> dict:
40
+ """ create a dictionnary from the Item. Keys contain __ as namespace seperator
41
+
42
+ Args:
43
+ item (Item): The item
44
+
45
+ Returns:
46
+ dict: The dictionary. Keys contain __ as namespace seperator
47
+ """
48
+ dictionary = item.model_dump(exclude_unset=True, by_alias=False, exclude_none=True)
49
+ return dictionary
50
+
51
+
52
+ def to_airs_json(item: Item) -> str:
53
+ """ create a json from the Item. Keys contain __ as namespace seperator
54
+
55
+ Args:
56
+ item (Item): The item
57
+
58
+ Returns:
59
+ str: the json. Keys contain __ as namespace seperator
60
+ """
61
+ return json.dumps(to_airs_dict(item), indent=2, default=serialize_datetime)
62
+
63
+
64
+ def to_json(item: Item) -> str:
65
+ """ create a json from the Item. Keys contain : as namespace seperator
66
+
67
+ Args:
68
+ item (Item): The item
69
+
70
+ Returns:
71
+ str: the json. Keys contain : as namespace seperator
72
+ """
73
+ return json.dumps(to_dict(item), indent=2, default=serialize_datetime)
74
+
75
+
76
+ def item_from_json_file(jsonfile) -> Item:
77
+ """ load a json file containing an Item
78
+
79
+ Args:
80
+ jsonfile (file): the json file
81
+
82
+ Returns:
83
+ Item: _description_
84
+ """
85
+ return Item(**__replaceKeys(json.load(jsonfile), ":", "__"))
86
+
87
+
88
+ def item_from_json(json_string: str) -> Item:
89
+ """ load a json Item
90
+
91
+ Args:
92
+ json_string (str): the Item as json
93
+
94
+ Returns:
95
+ Item: the Item
96
+ """
97
+ return Item(**__replaceKeys(json.loads(json_string), ":", "__"))
98
+
99
+
100
+ def item_from_dict(object: dict) -> Item:
101
+ """ load a dict Item
102
+
103
+ Args:
104
+ object (dict): the Item as dict
105
+
106
+ Returns:
107
+ Item: the Item
108
+ """
109
+ return Item(**__replaceKeys(object, ":", "__"))
110
+
111
+
112
+ def __replaceKeys(o, before: str, after: str):
113
+ if type(o) is dict:
114
+ d = {}
115
+ for key in o:
116
+ d[key.replace(before, after)] = __replaceKeys(o[key], before, after)
117
+ return d
118
+ if type(o) is list:
119
+ return list(map(lambda elt: __replaceKeys(elt, before, after), o))
120
+ else:
121
+ return o
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: airsmodel
3
- Version: 0.2.44
3
+ Version: 0.2.45
4
4
  Summary: ARLAS Item Registration Service Model
5
5
  Home-page: UNKNOWN
6
6
  Author: Gisaïa
@@ -1,107 +0,0 @@
1
- import json
2
-
3
- from airs.core.models.model import Item
4
-
5
-
6
- def to_airs_item(item: Item)->Item:
7
- """ Takes an item and makes sure to map the namespace fields to AIRS Item. Keys can contain : as namespace seperator
8
-
9
- Args:
10
- item (Item): The item (with : namespace separator)
11
-
12
- Returns:
13
- item: The airs item
14
- """
15
- dictionary=item.model_dump(exclude_unset=True, by_alias=True, exclude_none=True)
16
- return Item(**__replaceKeys(dictionary, ":", "__"))
17
-
18
-
19
- def to_dict(item: Item)->dict:
20
- """ create a dictionnary from the Item. Keys contain : as namespace seperator
21
-
22
- Args:
23
- item (Item): The item
24
-
25
- Returns:
26
- dict: The dictionary. Keys contain : as namespace seperator
27
- """
28
- dictionary=item.model_dump(exclude_unset=True, by_alias=True, exclude_none=True)
29
- return __replaceKeys(dictionary, "__", ":")
30
-
31
- def to_airs_dict(item: Item)->dict:
32
- """ create a dictionnary from the Item. Keys contain __ as namespace seperator
33
-
34
- Args:
35
- item (Item): The item
36
-
37
- Returns:
38
- dict: The dictionary. Keys contain __ as namespace seperator
39
- """
40
- dictionary=item.model_dump(exclude_unset=True, by_alias=False, exclude_none=True)
41
- return dictionary
42
-
43
- def to_airs_json(item: Item)->str:
44
- """ create a json from the Item. Keys contain __ as namespace seperator
45
-
46
- Args:
47
- item (Item): The item
48
-
49
- Returns:
50
- str: the json. Keys contain __ as namespace seperator
51
- """
52
- return json.dumps(to_airs_dict(item), default=str, indent=2)
53
-
54
- def to_json(item: Item)->str:
55
- """ create a json from the Item. Keys contain : as namespace seperator
56
-
57
- Args:
58
- item (Item): The item
59
-
60
- Returns:
61
- str: the json. Keys contain : as namespace seperator
62
- """
63
- return json.dumps(to_dict(item), default=str, indent=2)
64
-
65
- def item_from_json_file(jsonfile)->Item:
66
- """ load a json file containing an Item
67
-
68
- Args:
69
- jsonfile (file): the json file
70
-
71
- Returns:
72
- Item: _description_
73
- """
74
- return Item(**__replaceKeys(json.load(jsonfile), ":", "__"))
75
-
76
- def item_from_json(json_string:str)->Item:
77
- """ load a json Item
78
-
79
- Args:
80
- json_string (str): the Item as json
81
-
82
- Returns:
83
- Item: the Item
84
- """
85
- return Item(**__replaceKeys(json.loads(json_string), ":", "__"))
86
-
87
- def item_from_dict(object:dict)->Item:
88
- """ load a dict Item
89
-
90
- Args:
91
- object (dict): the Item as dict
92
-
93
- Returns:
94
- Item: the Item
95
- """
96
- return Item(**__replaceKeys(object, ":", "__"))
97
-
98
- def __replaceKeys(o, before:str, after:str):
99
- if type(o) is dict:
100
- d={}
101
- for key in o:
102
- d[key.replace(before, after)]=__replaceKeys(o[key], before, after)
103
- return d
104
- if type(o) is list:
105
- return list(map(lambda elt:__replaceKeys(elt, before, after), o))
106
- else:
107
- return o
File without changes
File without changes