protobin 0.0.23__tar.gz → 0.0.25__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.3
2
2
  Name: protobin
3
- Version: 0.0.23
3
+ Version: 0.0.25
4
4
  Summary: Python library for encode and decode data in protobin format
5
5
  Project-URL: Homepage, https://github.com/drmelectronic/protobin-python
6
6
  Project-URL: Bug Tracker, https://github.com/drmelectronic/protobin-python/issues
@@ -6,28 +6,30 @@ from typing import Union, List
6
6
  from protobin.errors import ParserError, FormatError
7
7
 
8
8
 
9
- class FieldEnum(enum.StrEnum):
10
- ARRAY = 'array'
11
- BITS = 'bits'
12
- BOOL = 'bool'
13
- CHAR = 'char'
14
- DATE = 'date'
15
- DATETIME = 'datetime'
16
- ID = 'id'
17
- FLAGS = 'flags'
18
- FLOAT = 'float'
19
- SIGNED = 'signed'
20
- STRING = 'string'
21
- TIME = 'time'
22
- TIMESTAMP = 'timestamp'
23
- UNSIGNED = 'unsigned'
9
+ # removed for python 3.8
10
+ # class FieldEnum(enum.StrEnum):
11
+ # ARRAY = 'array'
12
+ # BITS = 'bits'
13
+ # BOOL = 'bool'
14
+ # CHAR = 'char'
15
+ # DATE = 'date'
16
+ # DATETIME = 'datetime'
17
+ # ID = 'id'
18
+ # FLAGS = 'flags'
19
+ # FLOAT = 'float'
20
+ # SIGNED = 'signed'
21
+ # STRING = 'string'
22
+ # TIME = 'time'
23
+ # TIMESTAMP = 'timestamp'
24
+ # UNSIGNED = 'unsigned'
24
25
 
25
26
 
26
27
  class FieldBase:
27
- bytes: int | None
28
- keys: List[str] | None
29
- key: str
30
- type: FieldEnum
28
+ # removed for python 3.8
29
+ # bytes: int | None
30
+ # keys: List[str] | None
31
+ # key: str
32
+ # type: FieldEnum
31
33
 
32
34
  def __init__(self, k, js):
33
35
  self.key = k
@@ -231,7 +233,9 @@ class DateField(FieldBase):
231
233
  def __repr__(self):
232
234
  return f'DateField<key: {self.key}>'
233
235
 
234
- def to_binary(self, val: datetime.datetime | str):
236
+ # removed for python 3.8
237
+ # def to_binary(self, val: datetime.datetime | str):
238
+ def to_binary(self, val):
235
239
  if val is None:
236
240
  return bytes([0] * 3)
237
241
  elif isinstance(val, str):
@@ -260,7 +264,9 @@ class DateTimeField(FieldBase):
260
264
  def __repr__(self):
261
265
  return f'DateTimeField<key: {self.key}>'
262
266
 
263
- def to_binary(self, val: datetime.datetime | str):
267
+ # removed for python 3.8
268
+ # def to_binary(self, val: datetime.datetime | str):
269
+ def to_binary(self, val):
264
270
  if val is None:
265
271
  return bytes([0] * 6)
266
272
  elif not isinstance(val, datetime.datetime):
@@ -420,7 +426,9 @@ class TimeField(FieldBase):
420
426
  def __repr__(self):
421
427
  return f'TimeField<key: {self.key}, bytes: {self.bytes}>'
422
428
 
423
- def to_binary(self, val: datetime.datetime | datetime.time | str):
429
+ # removed for python 3.8
430
+ # def to_binary(self, val: datetime.datetime | datetime.time | str):
431
+ def to_binary(self, val):
424
432
  if val is None:
425
433
  return bytes([0] * 2)
426
434
  elif isinstance(val, str):
@@ -455,7 +463,9 @@ class TimestampField(FieldBase):
455
463
  def __repr__(self):
456
464
  return f'TimestampField<key: {self.key}>'
457
465
 
458
- def to_binary(self, val: datetime.datetime | str):
466
+ # removed for python 3.8
467
+ # def to_binary(self, val: datetime.datetime | str):
468
+ def to_binary(self, val):
459
469
  if val is None:
460
470
  return bytes([0] * 8)
461
471
  timestamp = val.timestamp() * (10 ** self.decimals)
@@ -42,7 +42,9 @@ class Format:
42
42
  if self.header:
43
43
  binary += self.header.encode('utf') + b'='
44
44
  elif self.codec:
45
- binary += self.codec.to_bytes()
45
+ # added for python 3.8
46
+ # binary += self.codec.to_bytes()
47
+ binary += self.codec.to_bytes(1, 'big')
46
48
  for f in self.output_fields:
47
49
  binary += f.encode(data)
48
50
  return binary
@@ -99,7 +101,9 @@ class Protocol:
99
101
  return self.formats[self.headers[h.decode('utf')]]
100
102
 
101
103
  def get_codec(self, h):
102
- return self.formats[self.codecs[int.from_bytes(h)]]
104
+ # added for python 3.8
105
+ # return self.formats[self.codecs[int.from_bytes(h)]]
106
+ return self.formats[self.codecs[int.from_bytes(h, 'big')]]
103
107
 
104
108
  def encode(self, data, format_key):
105
109
  if format_key not in self.formats:
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "protobin"
7
- version = "0.0.23"
7
+ version = "0.0.25"
8
8
  authors = [
9
9
  { name="Daniel Robles", email="drm.electronic@gmail.com" },
10
10
  ]
@@ -563,7 +563,6 @@ report:
563
563
  header, recv = server.decode(binary)
564
564
  self.assertEqual(recv, data)
565
565
 
566
-
567
566
  def test_teltonika_position_hex(self):
568
567
  hexdata = '000000000000003608010000016B40D8EA30010000000000000000000000000000000105021503010101425E0F01F10000601A014E0000000000000000010000C7CF'
569
568
  binary = bytes.fromhex(hexdata)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes