frost-sta-client 1.1.48__py2.py3-none-any.whl → 1.1.49__py2.py3-none-any.whl

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,5 +1,5 @@
1
1
  __title__ = 'frost_sta_client'
2
- __version__ = '1.1.48'
2
+ __version__ = '1.1.49'
3
3
  __license__ = 'LGPL3'
4
4
  __author__ = 'Fraunhofer IOSB'
5
5
  __copyright__ = 'Fraunhofer IOSB'
frost_sta_client/utils.py CHANGED
@@ -1,119 +1,122 @@
1
- # Copyright (C) 2021 Fraunhofer Institut IOSB, Fraunhoferstr. 1, D 76131
2
- # Karlsruhe, Germany.
3
- #
4
- # This program is free software: you can redistribute it and/or modify
5
- # it under the terms of the GNU Lesser General Public License as published by
6
- # the Free Software Foundation, either version 3 of the License, or
7
- # (at your option) any later version.
8
- #
9
- # This program is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- # GNU Lesser General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU Lesser General Public License
15
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
-
17
- import jsonpickle
18
- import datetime
19
- from dateutil.parser import isoparse
20
- import geojson
21
- import logging
22
- import sys
23
- import frost_sta_client.model.ext.entity_list
24
-
25
-
26
- def extract_value(location):
27
- try:
28
- value = int(location[location.find('(')+1: location.find(')')])
29
- except ValueError:
30
- value = str(location[location.find('(')+2: location.find(')')-1])
31
- return value
32
-
33
- def transform_entity_to_json_dict(entity):
34
- json_str = jsonpickle.encode(entity, unpicklable=False)
35
- return jsonpickle.decode(json_str)
36
-
37
- def class_from_string(string):
38
- module_name, class_name = string.rsplit(".", 1)
39
- return getattr(sys.modules[module_name], class_name)
40
-
41
- def transform_json_to_entity(json_response, entity_class):
42
- cl = class_from_string(entity_class)
43
- obj = cl()
44
- obj.__setstate__(json_response)
45
- return obj
46
-
47
- def transform_json_to_entity_list(json_response, entity_class):
48
- entity_list = frost_sta_client.model.ext.entity_list.EntityList(entity_class)
49
- result_list = []
50
- if isinstance(json_response, dict):
51
- try:
52
- response_list = json_response['value']
53
- entity_list.next_link = json_response.get("@iot.nextLink", None)
54
- entity_list.count = json_response.get("@iot.count", None)
55
- except AttributeError as e:
56
- raise e
57
- elif isinstance(json_response, list):
58
- response_list = json_response
59
- else:
60
- raise ValueError("expected json as a dict or list to transform into entity list")
61
- entity_list.entities = [transform_json_to_entity(item, entity_list.entity_class) for item in response_list]
62
- return entity_list
63
-
64
-
65
- def check_datetime(value, time_entity):
66
- try:
67
- parse_datetime(value)
68
- except ValueError as e:
69
- logging.error(f"error during {time_entity} check")
70
- raise e
71
- return value
72
-
73
-
74
- def parse_datetime(value) -> str:
75
- if value is None:
76
- return value
77
- if isinstance(value, str):
78
- if '/' in value:
79
- try:
80
- times = value.split('/')
81
- if len(times) != 2:
82
- raise ValueError("If the time interval is provided as a string,"
83
- " it should be in isoformat")
84
- result = [isoparse(times[0]),
85
- isoparse(times[1])]
86
- except ValueError:
87
- raise ValueError("If the time entity interval is provided as a string,"
88
- " it should be in isoformat")
89
- result = result[0].isoformat() + '/' + result[1].isoformat()
90
- return result
91
- else:
92
- try:
93
- result = isoparse(value)
94
- except ValueError:
95
- raise ValueError("If the phenomenon time is provided as string, it should be in isoformat")
96
- result = result.isoformat()
97
- return result
98
- if isinstance(value, datetime.datetime):
99
- return value.isoformat()
100
- if isinstance(value, list) and all(isinstance(v, datetime.datetime) for v in value):
101
- return value[0].isoformat() + value[1].isoformat()
102
- else:
103
- raise ValueError('time entities should consist of one or two datetimes')
104
-
105
-
106
- def process_area(value):
107
- if not isinstance(value, dict):
108
- raise ValueError("geojsons can only be handled as dictionaries!")
109
- if value.get("type", None) is None or value.get("coordinates", None) is None:
110
- raise ValueError("Both type and coordinates need to be specified in the dictionary")
111
- if value["type"] == "Point":
112
- return geojson.geometry.Point(value["coordinates"])
113
- if value["type"] == "Polygon":
114
- return geojson.geometry.Polygon(value["coordinates"])
115
- if value["type"] == "Geometry":
116
- return geojson.geometry.Geometry(value["coordinates"])
117
- if value["type"] == "LineString":
118
- return geojson.geometry.LineString(value["coordinates"])
119
- raise ValueError("can only handle geojson of type Point, Polygon, Geometry or LineString")
1
+ # Copyright (C) 2021 Fraunhofer Institut IOSB, Fraunhoferstr. 1, D 76131
2
+ # Karlsruhe, Germany.
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU Lesser General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ import jsonpickle
18
+ import datetime
19
+ from dateutil.parser import isoparse
20
+ import geojson
21
+ import logging
22
+ import sys
23
+ import frost_sta_client.model.ext.entity_list
24
+
25
+
26
+ def extract_value(location):
27
+ try:
28
+ value = int(location[location.find('(')+1: location.find(')')])
29
+ except ValueError:
30
+ value = str(location[location.find('(')+2: location.find(')')-1])
31
+ return value
32
+
33
+ def transform_entity_to_json_dict(entity):
34
+ try:
35
+ data = entity.__getstate__()
36
+ except AttributeError:
37
+ data = entity.__dict__
38
+ return data
39
+
40
+ def class_from_string(string):
41
+ module_name, class_name = string.rsplit(".", 1)
42
+ return getattr(sys.modules[module_name], class_name)
43
+
44
+ def transform_json_to_entity(json_response, entity_class):
45
+ cl = class_from_string(entity_class)
46
+ obj = cl()
47
+ obj.__setstate__(json_response)
48
+ return obj
49
+
50
+ def transform_json_to_entity_list(json_response, entity_class):
51
+ entity_list = frost_sta_client.model.ext.entity_list.EntityList(entity_class)
52
+ result_list = []
53
+ if isinstance(json_response, dict):
54
+ try:
55
+ response_list = json_response['value']
56
+ entity_list.next_link = json_response.get("@iot.nextLink", None)
57
+ entity_list.count = json_response.get("@iot.count", None)
58
+ except AttributeError as e:
59
+ raise e
60
+ elif isinstance(json_response, list):
61
+ response_list = json_response
62
+ else:
63
+ raise ValueError("expected json as a dict or list to transform into entity list")
64
+ entity_list.entities = [transform_json_to_entity(item, entity_list.entity_class) for item in response_list]
65
+ return entity_list
66
+
67
+
68
+ def check_datetime(value, time_entity):
69
+ try:
70
+ parse_datetime(value)
71
+ except ValueError as e:
72
+ logging.error(f"error during {time_entity} check")
73
+ raise e
74
+ return value
75
+
76
+
77
+ def parse_datetime(value) -> str:
78
+ if value is None:
79
+ return value
80
+ if isinstance(value, str):
81
+ if '/' in value:
82
+ try:
83
+ times = value.split('/')
84
+ if len(times) != 2:
85
+ raise ValueError("If the time interval is provided as a string,"
86
+ " it should be in isoformat")
87
+ result = [isoparse(times[0]),
88
+ isoparse(times[1])]
89
+ except ValueError:
90
+ raise ValueError("If the time entity interval is provided as a string,"
91
+ " it should be in isoformat")
92
+ result = result[0].isoformat() + '/' + result[1].isoformat()
93
+ return result
94
+ else:
95
+ try:
96
+ result = isoparse(value)
97
+ except ValueError:
98
+ raise ValueError("If the phenomenon time is provided as string, it should be in isoformat")
99
+ result = result.isoformat()
100
+ return result
101
+ if isinstance(value, datetime.datetime):
102
+ return value.isoformat()
103
+ if isinstance(value, list) and all(isinstance(v, datetime.datetime) for v in value):
104
+ return value[0].isoformat() + value[1].isoformat()
105
+ else:
106
+ raise ValueError('time entities should consist of one or two datetimes')
107
+
108
+
109
+ def process_area(value):
110
+ if not isinstance(value, dict):
111
+ raise ValueError("geojsons can only be handled as dictionaries!")
112
+ if value.get("type", None) is None or value.get("coordinates", None) is None:
113
+ raise ValueError("Both type and coordinates need to be specified in the dictionary")
114
+ if value["type"] == "Point":
115
+ return geojson.geometry.Point(value["coordinates"])
116
+ if value["type"] == "Polygon":
117
+ return geojson.geometry.Polygon(value["coordinates"])
118
+ if value["type"] == "Geometry":
119
+ return geojson.geometry.Geometry(value["coordinates"])
120
+ if value["type"] == "LineString":
121
+ return geojson.geometry.LineString(value["coordinates"])
122
+ raise ValueError("can only handle geojson of type Point, Polygon, Geometry or LineString")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: frost_sta_client
3
- Version: 1.1.48
3
+ Version: 1.1.49
4
4
  Summary: a client library to facilitate interaction with a FROST SensorThingsAPI Server
5
5
  Home-page: https://github.com/FraunhoferIOSB/FROST-Python-Client
6
6
  Author: Fraunhofer IOSB
@@ -1,6 +1,6 @@
1
1
  frost_sta_client/__init__.py,sha256=N0Rs6kwdPcpyz0p-Tfq2PYIAIIZsMmnSC0QXus_AmP0,1789
2
- frost_sta_client/__version__.py,sha256=5YVnrD-mRpv_hnD-BaKoRSM5HeJWnlcqol-5z0A_F68,355
3
- frost_sta_client/utils.py,sha256=hY9JO0F4jIXODXFu7xdFw2b6hGhYQky_UZI0UDRBPaI,4845
2
+ frost_sta_client/__version__.py,sha256=ivlB8oJyiH--NyghDqejsdHw4ZWEylIr37Lk9oOIbh8,355
3
+ frost_sta_client/utils.py,sha256=YA8B3SkG0RFFumSPPH65rJ2BHrADzKtcCKXVKAUVG54,4747
4
4
  frost_sta_client/dao/__init__.py,sha256=RKxbQ3WLVygWyz_Kb-SzO7CfUdffq7LqtJHcHSOHmgo,221
5
5
  frost_sta_client/dao/actuator.py,sha256=WxRjeetR50Pb9AbhCdtc1VRSl09pgzfA2DsPBBZy-3E,1099
6
6
  frost_sta_client/dao/base.py,sha256=uAx1qSnXX2jwoZrjXjPW47bp-c-jMUyX8SpmY0eXM84,9209
@@ -40,8 +40,8 @@ frost_sta_client/query/query.py,sha256=hXd-ffYf2HDZ5aqVA5lW5XtoijIr4-4mTfevdRDz2
40
40
  frost_sta_client/service/__init__.py,sha256=au1GqHe1OB7Iq-i90plqmIrH-7wBE7ogDoQ2uX03Fj0,109
41
41
  frost_sta_client/service/auth_handler.py,sha256=qahYUK7Z0kGvbUcdtpodIA9sngYCfJz2jqKpLVGA8Z4,1117
42
42
  frost_sta_client/service/sensorthingsservice.py,sha256=H2wM4v5oPvJ6eBfvdkbYyLI4V1vaWpbAuq-Q_fGo3-A,4621
43
- frost_sta_client-1.1.48.dist-info/licenses/LICENSE,sha256=LPNKwDiu5awG-TPd0dqYJuC7k4PBPY4LCI_O0LSpW1s,7814
44
- frost_sta_client-1.1.48.dist-info/METADATA,sha256=2Hbvx_temj3FhEP5LUoU9StTu7ljdK81xXs-PdQia_M,5905
45
- frost_sta_client-1.1.48.dist-info/WHEEL,sha256=9bhjOwO--Rs91xaPcBdlYFUmIudhuXqFlPriQeYQITw,109
46
- frost_sta_client-1.1.48.dist-info/top_level.txt,sha256=c35-3D_K1E_y8fcadqI3j6kGQ7HBrkOqCNie5Rv64KI,17
47
- frost_sta_client-1.1.48.dist-info/RECORD,,
43
+ frost_sta_client-1.1.49.dist-info/licenses/LICENSE,sha256=LPNKwDiu5awG-TPd0dqYJuC7k4PBPY4LCI_O0LSpW1s,7814
44
+ frost_sta_client-1.1.49.dist-info/METADATA,sha256=5-EuYzZh_RwqShdQaV5Bmsm9nCsb-Z0cUO3GjBUiKWk,5905
45
+ frost_sta_client-1.1.49.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
46
+ frost_sta_client-1.1.49.dist-info/top_level.txt,sha256=c35-3D_K1E_y8fcadqI3j6kGQ7HBrkOqCNie5Rv64KI,17
47
+ frost_sta_client-1.1.49.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (77.0.1)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py2-none-any
5
5
  Tag: py3-none-any