pycupra 0.1.11__py3-2ndver-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.
- pycupra/__init__.py +8 -0
- pycupra/__version__.py +6 -0
- pycupra/connection.py +1895 -0
- pycupra/const.py +195 -0
- pycupra/dashboard.py +1527 -0
- pycupra/exceptions.py +87 -0
- pycupra/firebase.py +90 -0
- pycupra/firebase_messaging/__init__.py +30 -0
- pycupra/firebase_messaging/android_checkin.proto +96 -0
- pycupra/firebase_messaging/android_checkin_pb2.py +36 -0
- pycupra/firebase_messaging/android_checkin_pb2.pyi +257 -0
- pycupra/firebase_messaging/checkin.proto +155 -0
- pycupra/firebase_messaging/checkin_pb2.py +31 -0
- pycupra/firebase_messaging/checkin_pb2.pyi +424 -0
- pycupra/firebase_messaging/const.py +32 -0
- pycupra/firebase_messaging/fcmpushclient.py +812 -0
- pycupra/firebase_messaging/fcmregister.py +519 -0
- pycupra/firebase_messaging/mcs.proto +328 -0
- pycupra/firebase_messaging/mcs_pb2.py +65 -0
- pycupra/firebase_messaging/mcs_pb2.pyi +1118 -0
- pycupra/firebase_messaging/py.typed +0 -0
- pycupra/utilities.py +116 -0
- pycupra/vehicle.py +3453 -0
- pycupra-0.1.11.dist-info/METADATA +13 -0
- pycupra-0.1.11.dist-info/RECORD +28 -0
- pycupra-0.1.11.dist-info/WHEEL +5 -0
- pycupra-0.1.11.dist-info/licenses/LICENSE +201 -0
- pycupra-0.1.11.dist-info/top_level.txt +1 -0
File without changes
|
pycupra/utilities.py
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
from datetime import date, datetime
|
2
|
+
from base64 import b64encode
|
3
|
+
from string import ascii_letters as letters, digits
|
4
|
+
from sys import argv
|
5
|
+
from os import environ as env
|
6
|
+
from os.path import join, dirname, expanduser
|
7
|
+
from itertools import product
|
8
|
+
import json
|
9
|
+
import logging
|
10
|
+
import re
|
11
|
+
|
12
|
+
_LOGGER = logging.getLogger(__name__)
|
13
|
+
|
14
|
+
|
15
|
+
def read_config():
|
16
|
+
"""Read config from file."""
|
17
|
+
for directory, filename in product(
|
18
|
+
[
|
19
|
+
dirname(argv[0]),
|
20
|
+
expanduser("~"),
|
21
|
+
env.get("XDG_CONFIG_HOME", join(expanduser("~"), ".config")),
|
22
|
+
],
|
23
|
+
["seat.conf", ".seat.conf"],
|
24
|
+
):
|
25
|
+
try:
|
26
|
+
config = join(directory, filename)
|
27
|
+
_LOGGER.debug("checking for config file %s", config)
|
28
|
+
with open(config) as config:
|
29
|
+
return dict(
|
30
|
+
x.split(": ")
|
31
|
+
for x in config.read().strip().splitlines()
|
32
|
+
if not x.startswith("#")
|
33
|
+
)
|
34
|
+
except (IOError, OSError):
|
35
|
+
continue
|
36
|
+
return {}
|
37
|
+
|
38
|
+
|
39
|
+
def json_loads(s):
|
40
|
+
return json.loads(s, object_hook=obj_parser)
|
41
|
+
|
42
|
+
|
43
|
+
def obj_parser(obj):
|
44
|
+
"""Parse datetime."""
|
45
|
+
for key, val in obj.items():
|
46
|
+
try:
|
47
|
+
obj[key] = datetime.strptime(val, "%Y-%m-%dT%H:%M:%S%z")
|
48
|
+
except (TypeError, ValueError):
|
49
|
+
pass
|
50
|
+
return obj
|
51
|
+
|
52
|
+
|
53
|
+
def find_path(src, path):
|
54
|
+
"""Simple navigation of a hierarchical dict structure using XPATH-like syntax.
|
55
|
+
|
56
|
+
>>> find_path(dict(a=1), 'a')
|
57
|
+
1
|
58
|
+
|
59
|
+
>>> find_path(dict(a=1), '')
|
60
|
+
{'a': 1}
|
61
|
+
|
62
|
+
>>> find_path(dict(a=None), 'a')
|
63
|
+
|
64
|
+
|
65
|
+
>>> find_path(dict(a=1), 'b')
|
66
|
+
Traceback (most recent call last):
|
67
|
+
...
|
68
|
+
KeyError: 'b'
|
69
|
+
|
70
|
+
>>> find_path(dict(a=dict(b=1)), 'a.b')
|
71
|
+
1
|
72
|
+
|
73
|
+
>>> find_path(dict(a=dict(b=1)), 'a')
|
74
|
+
{'b': 1}
|
75
|
+
|
76
|
+
>>> find_path(dict(a=dict(b=1)), 'a.c')
|
77
|
+
Traceback (most recent call last):
|
78
|
+
...
|
79
|
+
KeyError: 'c'
|
80
|
+
|
81
|
+
"""
|
82
|
+
if not path:
|
83
|
+
return src
|
84
|
+
if isinstance(path, str):
|
85
|
+
path = path.split(".")
|
86
|
+
return find_path(src[path[0]], path[1:])
|
87
|
+
|
88
|
+
|
89
|
+
def is_valid_path(src, path):
|
90
|
+
"""
|
91
|
+
>>> is_valid_path(dict(a=1), 'a')
|
92
|
+
True
|
93
|
+
|
94
|
+
>>> is_valid_path(dict(a=1), '')
|
95
|
+
True
|
96
|
+
|
97
|
+
>>> is_valid_path(dict(a=1), None)
|
98
|
+
True
|
99
|
+
|
100
|
+
>>> is_valid_path(dict(a=1), 'b')
|
101
|
+
False
|
102
|
+
"""
|
103
|
+
try:
|
104
|
+
find_path(src, path)
|
105
|
+
return True
|
106
|
+
except KeyError:
|
107
|
+
return False
|
108
|
+
|
109
|
+
|
110
|
+
def camel2slug(s):
|
111
|
+
"""Convert camelCase to camel_case.
|
112
|
+
|
113
|
+
>>> camel2slug('fooBar')
|
114
|
+
'foo_bar'
|
115
|
+
"""
|
116
|
+
return re.sub("([A-Z])", "_\\1", s).lower().lstrip("_")
|