xaal.lib 0.7.7__py3-none-any.whl → 0.7.9__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.
xaal/lib/test.py CHANGED
@@ -7,8 +7,8 @@ from xaal.lib import tools
7
7
  import logging
8
8
 
9
9
 
10
- ADDR="b8bec7ca-f955-11e6-9031-82ed25e6aaaa"
11
- ADDR=tools.get_random_uuid()
10
+ ADDR='b8bec7ca-f955-11e6-9031-82ed25e6aaaa'
11
+ ADDR=tools.get_random_uuid()
12
12
 
13
13
  def dump_hex(name,data):
14
14
  print("%s : " % name,end='=')
@@ -23,30 +23,30 @@ def test_pysodium():
23
23
  from xaal.lib import messages
24
24
  import pysodium
25
25
 
26
- payload = "FooBar".encode("utf-8")
26
+ payload = 'FooBar'.encode("utf-8")
27
27
  ad = '[]'
28
28
 
29
29
  data = messages.build_timestamp()
30
30
  nonce = messages.build_nonce(data)
31
31
  key = tools.pass2key("My Friend Goo")
32
-
33
- dump_hex("Payload",payload)
34
- dump_hex("Key",key)
32
+
33
+ dump_hex('Payload',payload)
34
+ dump_hex('Key',key)
35
35
 
36
36
  ciph = pysodium.crypto_aead_chacha20poly1305_encrypt(payload, ad, nonce, key)
37
- dump_hex("Ciph",ciph)
38
-
37
+ dump_hex('Ciph',ciph)
38
+
39
39
  pjson = pysodium.crypto_aead_chacha20poly1305_decrypt(ciph, ad, nonce, key)
40
40
  print(pjson)
41
41
 
42
-
42
+
43
43
  def test_device():
44
44
  from xaal.lib.devices import Device
45
45
  addr = ADDR
46
46
  dev = Device("foo.basic",addr)
47
- dev.vendor_id = "ACME"
47
+ dev.vendor_id = 'ACME'
48
48
  dev.url="http://acmefactory.blogspot.fr/"
49
- dev.hw_id = "0x201"
49
+ dev.hw_id = '0x201'
50
50
  print(dev.getDescription())
51
51
  return dev
52
52
 
@@ -59,7 +59,7 @@ def test_msg():
59
59
 
60
60
  def test_encode():
61
61
  from xaal.lib.messages import MessageFactory
62
- key = tools.pass2key("FooBar")
62
+ key = tools.pass2key('FooBar')
63
63
  factory = MessageFactory(key)
64
64
  m2 = factory.build_msg()
65
65
  print(factory.decode_msg(m2))
@@ -68,10 +68,10 @@ def test_log():
68
68
  logger = logging.getLogger(__name__)
69
69
  logger.info("This is an INFO msg")
70
70
  logger.debug("This is an DEBUG msg")
71
-
71
+
72
72
 
73
73
  def test_engine():
74
- from xaal.lib.core import Engine
74
+ from xaal.lib.engine import Engine
75
75
  engine = Engine()
76
76
  engine.run()
77
77
 
@@ -87,7 +87,7 @@ def test_crypto_decoding_error():
87
87
  dev = xaal.lib.Device("test.basic",addr)
88
88
  eng = xaal.lib.Engine()
89
89
  eng.add_devices([dev,])
90
- eng.msg_factory.cipher_key = tools.pass2key("FakeKey")
90
+ eng.msg_factory.cipher_key = tools.pass2key('FakeKey')
91
91
  eng.start()
92
92
  eng.loop()
93
93
 
@@ -95,14 +95,14 @@ def test_crypto_decoding_error():
95
95
  def test_attr():
96
96
  dev = xaal.lib.Device("test.basic",ADDR)
97
97
  dev.url = "http://linux.org"
98
- dev.vendor_id = "ACME"
98
+ dev.vendor_id = 'ACME'
99
99
  dev.product_id = "Full Fake Device"
100
- dev.info = "FooBar"
101
- dev.hw_id = "ffd0001"
100
+ dev.info = 'FooBar'
101
+ dev.hw_id = 'ffd0001'
102
102
  #dev.alive_period = 100
103
103
 
104
- attr0 = dev.new_attribute("attr0",10)
105
- attr1 = dev.new_attribute("attr1",False)
104
+ attr0 = dev.new_attribute('attr0',10)
105
+ attr1 = dev.new_attribute('attr1',False)
106
106
 
107
107
  eng = xaal.lib.Engine()
108
108
  eng.add_devices([dev,])
@@ -111,12 +111,12 @@ def test_attr():
111
111
  attr0.value = attr0.value + 1
112
112
 
113
113
  eng.add_timer(update,60)
114
-
114
+
115
115
  #eng.loop()
116
116
  eng.run()
117
-
118
117
 
119
-
118
+
119
+
120
120
  def run():
121
121
 
122
122
  logger = tools.get_logger(__name__,logging.DEBUG,"%s.log" % __name__)
@@ -128,13 +128,11 @@ def run():
128
128
  #test_alive()
129
129
  #test_crypto_decoding_error()
130
130
  test_attr()
131
-
132
-
131
+
132
+
133
133
 
134
134
  if __name__ == '__main__':
135
135
  try:
136
136
  run()
137
137
  except KeyboardInterrupt:
138
138
  print("Bye bye...")
139
-
140
-
xaal/lib/tools.py CHANGED
@@ -18,101 +18,114 @@
18
18
  # along with xAAL. If not, see <http://www.gnu.org/licenses/>.
19
19
  #
20
20
 
21
+ import functools
21
22
  import os
22
23
  import re
24
+ import sys
25
+ from typing import Optional, Union
23
26
 
24
27
  import pysodium
25
-
26
- import sys
27
- import functools
28
28
  from configobj import ConfigObj
29
29
 
30
- from . import config
30
+ from .config import config
31
31
  from .bindings import UUID
32
32
 
33
- XAAL_DEVTYPE_PATTERN = '^[a-zA-Z][a-zA-Z0-9_-]*\\.[a-zA-Z][a-zA-Z0-9_-]*$'
33
+ XAAL_DEVTYPE_PATTERN = "^[a-zA-Z][a-zA-Z0-9_-]*\\.[a-zA-Z][a-zA-Z0-9_-]*$"
34
34
 
35
- def get_cfg_filename(name, cfg_dir=config.conf_dir):
36
- if name.startswith('xaal.'):
35
+
36
+ def get_cfg_filename(name: str, cfg_dir: str = config.conf_dir) -> str:
37
+ if name.startswith("xaal."):
37
38
  name = name[5:]
38
- filename = '%s.ini' % name
39
+ filename = "%s.ini" % name
39
40
  if not os.path.isdir(cfg_dir):
40
41
  print("Your configuration directory doesn't exist: [%s]" % cfg_dir)
41
42
  return os.path.join(cfg_dir, filename)
42
43
 
43
- def load_cfg_file(filename):
44
- """ load .ini file and return it as dict"""
44
+
45
+ def load_cfg_file(filename: str) -> Optional[ConfigObj]:
46
+ """load .ini file and return it as dict"""
45
47
  if os.path.isfile(filename):
46
- return ConfigObj(filename,indent_type=' ',encoding="utf8")
48
+ return ConfigObj(filename, indent_type=" ", encoding='utf8')
47
49
  return None
48
50
 
49
- def load_cfg(app_name):
51
+
52
+ def load_cfg(app_name: str) -> Optional[ConfigObj]:
50
53
  filename = get_cfg_filename(app_name)
51
54
  return load_cfg_file(filename)
52
55
 
53
- def load_cfg_or_die(app_name):
56
+
57
+ def load_cfg_or_die(app_name: str) -> ConfigObj:
54
58
  cfg = load_cfg(app_name)
55
59
  if not cfg:
56
60
  print("Unable to load config file %s" % get_cfg_filename(app_name))
57
61
  sys.exit(-1)
58
62
  return cfg
59
63
 
60
- def new_cfg(app_name):
64
+
65
+ def new_cfg(app_name: str) -> ConfigObj:
61
66
  filename = get_cfg_filename(app_name)
62
- cfg = ConfigObj(filename,indent_type=' ')
63
- cfg['config'] = {}
64
- cfg['config']['addr']=get_random_uuid().str
67
+ cfg = ConfigObj(filename, indent_type=" ")
68
+ cfg['config'] = {'addr' : get_random_uuid().str}
65
69
  return cfg
66
70
 
67
- def get_random_uuid():
71
+
72
+ def get_random_uuid() -> UUID:
68
73
  return UUID.random()
69
74
 
70
- def get_random_base_uuid(digit=2):
75
+
76
+ def get_random_base_uuid(digit=2) -> UUID:
71
77
  return UUID.random_base(digit)
72
78
 
73
- def get_uuid(val):
74
- if isinstance(val,UUID):
79
+
80
+ def get_uuid(val: Union[UUID, str]) -> Optional[UUID]:
81
+ if isinstance(val, UUID):
75
82
  return val
76
- if isinstance(val,str):
83
+ if isinstance(val, str):
77
84
  return str_to_uuid(val)
78
85
  return None
79
86
 
80
- def str_to_uuid(val):
81
- """ return an xAAL address for a given string"""
87
+
88
+ def str_to_uuid(val: str) -> Optional[UUID]:
89
+ """return an xAAL address for a given string"""
82
90
  try:
83
91
  return UUID(val)
84
92
  except ValueError:
85
93
  return None
86
94
 
87
- def bytes_to_uuid(val):
95
+
96
+ def bytes_to_uuid(val: bytes) -> Optional[UUID]:
88
97
  try:
89
98
  return UUID(bytes=val)
90
99
  except ValueError:
91
100
  return None
92
101
 
93
- def is_valid_uuid(val):
94
- return isinstance(val,UUID)
95
102
 
96
- def is_valid_address(val):
103
+ def is_valid_uuid(val: UUID) -> bool:
104
+ return isinstance(val, UUID)
105
+
106
+
107
+ def is_valid_address(val: UUID) -> bool:
97
108
  return is_valid_uuid(val)
98
109
 
110
+
99
111
  @functools.lru_cache(maxsize=128)
100
- def is_valid_dev_type(val):
101
- if not isinstance(val,str):
112
+ def is_valid_dev_type(val: str) -> bool:
113
+ if not isinstance(val, str):
102
114
  return False
103
- if re.match(XAAL_DEVTYPE_PATTERN,val):
104
- return True
115
+ if re.match(XAAL_DEVTYPE_PATTERN, val):
116
+ return True
105
117
  return False
106
118
 
107
- def pass2key(passphrase):
119
+
120
+ def pass2key(passphrase: str) -> bytes:
108
121
  """Generate key from passphrase using libsodium
109
122
  crypto_pwhash_scryptsalsa208sha256 func
110
123
  salt: buffer of zeros
111
124
  opslimit: crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE
112
125
  memlimit: crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE
113
126
  """
114
- buf = passphrase.encode('utf-8')
115
- KEY_BYTES = pysodium.crypto_pwhash_scryptsalsa208sha256_SALTBYTES #32
127
+ buf = passphrase.encode("utf-8")
128
+ KEY_BYTES = pysodium.crypto_pwhash_scryptsalsa208sha256_SALTBYTES # 32
116
129
  # this should be:
117
130
  # salt = bytes(KEY_BYTES)
118
131
  # but due to bytes() stupid stuff in py2 we need this awfull stuff
@@ -122,8 +135,9 @@ def pass2key(passphrase):
122
135
  key = pysodium.crypto_pwhash_scryptsalsa208sha256(KEY_BYTES, buf, salt, opslimit, memlimit)
123
136
  return key
124
137
 
138
+
125
139
  @functools.lru_cache(maxsize=128)
126
- def reduce_addr(addr):
140
+ def reduce_addr(addr: UUID) -> str:
127
141
  """return a string based addred without all digits"""
128
142
  tmp = addr.str
129
143
  return tmp[:5] + '..' + tmp[-5:]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xaal.lib
3
- Version: 0.7.7
3
+ Version: 0.7.9
4
4
  Summary: Official Python stack for xAAL protocol
5
5
  Author-email: Jerome Kerdreux <Jerome.Kerdreux@imt-atlantique.fr>
6
6
  License: GPL License
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python
12
12
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
13
13
  Classifier: Topic :: Home Automation
14
14
  Description-Content-Type: text/x-rst
15
- Requires-Dist: cbor2 ==5.4.2
15
+ Requires-Dist: cbor2==5.4.2
16
16
  Requires-Dist: pysodium
17
17
  Requires-Dist: configobj
18
18
  Requires-Dist: coloredlogs
@@ -0,0 +1,22 @@
1
+ xaal/__init__.py,sha256=jv2YF__bseklT3OWEzlqJ5qE24c4aWd5F4r0TTjOrWQ,65
2
+ xaal/lib/__init__.py,sha256=yI2lG7uSbedjp1h2FCdcAUGzkyuJxYyNbK13SHvwNew,491
3
+ xaal/lib/__main__.py,sha256=xsVqqoIh3UeJIXxeexSfmGSUP4YxUcibdZExjEzk4lE,30
4
+ xaal/lib/aioengine.py,sha256=3l5wCRV9ZySfJOpKxDD_yO81NtL1v246mMveR28q9ms,13959
5
+ xaal/lib/aiohelpers.py,sha256=O1oQX8XHxuvCL1ual509chjoR52AwV_ZGqeAbSlvFrE,1010
6
+ xaal/lib/aionetwork.py,sha256=WSYwxwEHJaQDlfVocX8ow2tAtssWcH9LxPAazx4Qx_o,2547
7
+ xaal/lib/bindings.py,sha256=V77bFfeVFj0GyGuwH8b4k7qSyA7zApZYJ8QTjq_3DwI,2140
8
+ xaal/lib/cbor.py,sha256=XX0zgTU0uwQD9QXctGLT4lEISohi1whMUdyWKMevH8c,1647
9
+ xaal/lib/config.py,sha256=KR28xC8NGyGjvFD9QcAoWfwyf7xcXDEP7aSenNmaRzM,3019
10
+ xaal/lib/core.py,sha256=WUdG1k7H589FpVbTkotHX574KiSYISZ622eWy3Af3B0,11985
11
+ xaal/lib/devices.py,sha256=CaUH3i_xTQD0W63fW93glI-Ck2_YVvMpdn8y7BqQqzw,10696
12
+ xaal/lib/engine.py,sha256=oFiBIma5M6Qv0W2wMmWdyCRuu7BwqR-DRUvqWfajh-A,8141
13
+ xaal/lib/exceptions.py,sha256=4cKKkDDcZIPyVrLv3Q19apbn_pIqDGqXb1s1d2sZnpI,573
14
+ xaal/lib/helpers.py,sha256=lPtEwP82Ssd9igmxJGq2UzmPVCyRBMHULBBVyAH4Blg,2827
15
+ xaal/lib/messages.py,sha256=FpdIZ5flzUfgXaVVptv_tirvq5jL__mjUGimExwK9Z0,12388
16
+ xaal/lib/network.py,sha256=oHpyHXkFT31RS6UKMZstC33dgC_sTtYKzfpgugY26oU,3277
17
+ xaal/lib/test.py,sha256=GTjIwdqRupdqO4lNhAnc4iH0azfCCMN9BEpJpgAUors,2944
18
+ xaal/lib/tools.py,sha256=Py_RUmLcOVjYDcm7muQ6jZPJLdOKzBfOKstX73K4Jqg,4157
19
+ xaal.lib-0.7.9.dist-info/METADATA,sha256=sqdfCDzjK0rQ-rmIYzAoK3-e62injIc0HOgpapB0Fe4,4350
20
+ xaal.lib-0.7.9.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
21
+ xaal.lib-0.7.9.dist-info/top_level.txt,sha256=UZ2WDkN02ztkh1OrsjrW8Kmj4n3WqC0BQxaEYOYfWa0,5
22
+ xaal.lib-0.7.9.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.3.0)
2
+ Generator: setuptools (75.6.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,22 +0,0 @@
1
- xaal/__init__.py,sha256=jv2YF__bseklT3OWEzlqJ5qE24c4aWd5F4r0TTjOrWQ,65
2
- xaal/lib/__init__.py,sha256=MMXBicq9vNn6yCzBPcqZfTXk329NEL-qTM95jXUMymE,471
3
- xaal/lib/__main__.py,sha256=xsVqqoIh3UeJIXxeexSfmGSUP4YxUcibdZExjEzk4lE,30
4
- xaal/lib/aioengine.py,sha256=3MTG9aGKekVvsWhYaehZqZem6YmPng4UqGfDoRTaC2E,13100
5
- xaal/lib/aiohelpers.py,sha256=2a310wSXzbg9SGYzrTfcHbaZ8PWEe9rLteDmS2i62kU,1007
6
- xaal/lib/aionetwork.py,sha256=pH-5kf8o4FHsbvs-oFf5guAgYaEu0aosyTuI3k8xt2M,2484
7
- xaal/lib/bindings.py,sha256=EkDJJ_iBQbC7UzsjHfoXAjpGSwC613hrIm5ubrkcw4k,1994
8
- xaal/lib/cbor.py,sha256=yOTAo3TBO7m8KU_ffccJdOZmiJF5tfY7H8nC1XfMIS8,1630
9
- xaal/lib/config.py,sha256=jNAEXCswWsKrVab3hycupQn4aYt4c61eq628ow_I2ZI,1736
10
- xaal/lib/core.py,sha256=VfaisNREUse-zMrilJuKf6NLVO9HugL1U_I4M7BFzKQ,10806
11
- xaal/lib/devices.py,sha256=TXj7qk6raa8aU1wkMeA5HYsWF0MFFjs0_JTxN_r6_MQ,9558
12
- xaal/lib/engine.py,sha256=p2of6IPQB0It0RNu5fkJHHp615K_2rgzHfuWOpvJ6Is,7539
13
- xaal/lib/exceptions.py,sha256=ZKDKGlm_F48K_0NlaV1fa0Z-a4ZnOxT7NU8c8MKSJAc,504
14
- xaal/lib/helpers.py,sha256=mXxVxv7fTV9O9xO1BROhVYBTmdviMl6qx3Il8q1ox8w,2679
15
- xaal/lib/messages.py,sha256=W7RdHOtX_DT0bCeJAzs0p4KkU5KXofZUCMQYQsOuFF8,11571
16
- xaal/lib/network.py,sha256=3HWuQ0afQ-X6_-En2rFeqYJ0Scy5IEHfd0qTldxxCFo,3130
17
- xaal/lib/test.py,sha256=laVbgG4HtQquxDzixAG-Cka-HO4kpb7YUsLL267mGPU,3006
18
- xaal/lib/tools.py,sha256=qLZZOfA1VvQWJjGR46JWdAwWzv8Uog2TUTw7lK34CZg,3832
19
- xaal.lib-0.7.7.dist-info/METADATA,sha256=LJ4Ry8elEPVz7ONsef6BEEzpofShCqsgurcs8yiKLBQ,4351
20
- xaal.lib-0.7.7.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
21
- xaal.lib-0.7.7.dist-info/top_level.txt,sha256=UZ2WDkN02ztkh1OrsjrW8Kmj4n3WqC0BQxaEYOYfWa0,5
22
- xaal.lib-0.7.7.dist-info/RECORD,,