protobin 0.0.9__tar.gz → 0.0.10__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.9
3
+ Version: 0.0.10
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
@@ -25,11 +25,13 @@ class FieldEnum(enum.StrEnum):
25
25
 
26
26
  class FieldBase:
27
27
  bytes: int | None
28
- key: Union[str, List[str]]
28
+ keys: List[str] | None
29
+ key: str
29
30
  type: FieldEnum
30
31
 
31
32
  def __init__(self, k, js):
32
33
  self.key = k
34
+ self.keys = None
33
35
  self.type = js['type']
34
36
  self.bytes = js.get('bytes')
35
37
 
@@ -79,7 +81,6 @@ class FieldBase:
79
81
  return binary[1:binary[0] + 1], binary[binary[0] + 1:]
80
82
 
81
83
 
82
-
83
84
  class FieldArray(FieldBase):
84
85
  length: int
85
86
 
@@ -203,7 +204,9 @@ class FieldDate(FieldBase):
203
204
  self.bytes = 3
204
205
 
205
206
  def to_binary(self, val: datetime.datetime | str):
206
- if isinstance(val, str):
207
+ if val is None:
208
+ val = datetime.datetime(2000, 1, 1)
209
+ elif isinstance(val, str):
207
210
  val = datetime.datetime.strptime(val, '%Y-%m-%d').date()
208
211
  return bytes([
209
212
  self.to_nible(val.day),
@@ -254,7 +257,7 @@ class FieldFlags(FieldBase):
254
257
 
255
258
  def __init__(self, k, js):
256
259
  super().__init__(k, js)
257
- self.key = self.key.split(',')
260
+ self.keys = self.key.split(',')
258
261
  self.length = len(self.key)
259
262
  self.bytes = math.ceil(self.length / 8)
260
263
 
@@ -268,15 +271,15 @@ class FieldFlags(FieldBase):
268
271
  for b in bits:
269
272
  flags.append(b == '1')
270
273
  val = {}
271
- order = -len(self.key)
272
- for k in self.key:
274
+ order = -len(self.keys)
275
+ for k in self.keys:
273
276
  val[k] = flags[order]
274
277
  order += 1
275
278
  return val
276
279
 
277
280
  def to_binary(self, data):
278
- bits = '0' * (8 - (len(self.key) % 8))
279
- for k in self.key:
281
+ bits = '0' * (8 - (len(self.keys) % 8))
282
+ for k in self.keys:
280
283
  bits += '1' if data[k] else '0'
281
284
  return int(bits, 2).to_bytes(self.bytes, 'big', signed=False)
282
285
 
@@ -34,8 +34,8 @@ class Format:
34
34
  data = {}
35
35
  for f in self.input_fields:
36
36
  val, binary = f.decode(binary)
37
- if isinstance(f.key, list):
38
- for k in f.key:
37
+ if f.keys:
38
+ for k in f.keys:
39
39
  data[k] = val[k]
40
40
  else:
41
41
  data[f.key] = val
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "protobin"
7
- version = "0.0.9"
7
+ version = "0.0.10"
8
8
  authors = [
9
9
  { name="Daniel Robles", email="drm.electronic@gmail.com" },
10
10
  ]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes