protobin 0.0.38__tar.gz → 0.0.39__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.4
2
2
  Name: protobin
3
- Version: 0.0.38
3
+ Version: 0.0.39
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
@@ -21,7 +21,7 @@ class InputError(BaseError):
21
21
  pass
22
22
 
23
23
 
24
- class ParserError(BaseError):
24
+ class DecodeError(BaseError):
25
25
  pass
26
26
 
27
27
 
@@ -3,7 +3,7 @@ import datetime
3
3
  import math
4
4
  from typing import Union, List
5
5
 
6
- from protobin.errors import ParserError, FormatError
6
+ from protobin.errors import DecodeError, FormatError
7
7
 
8
8
 
9
9
  # removed for python 3.8
@@ -50,7 +50,7 @@ class FieldBase:
50
50
  def ensure_length(self, binary):
51
51
  if self.bytes:
52
52
  if len(binary) < self.bytes:
53
- raise ParserError(f'Binary has not enough data for {self}')
53
+ raise DecodeError(f'Binary has not enough data for {self}')
54
54
 
55
55
  def from_binary(self, binary):
56
56
  raise NotImplementedError()
@@ -398,7 +398,10 @@ class StringField(FieldBase):
398
398
  return f'StringField<key: {self.key}, bytes: {self.bytes}>'
399
399
 
400
400
  def from_binary(self, binary):
401
- return binary.decode('utf')
401
+ try:
402
+ return binary.decode('utf')
403
+ except UnicodeEncodeError:
404
+ raise DecodeError(f"Can't decode string: {binary}")
402
405
 
403
406
  def split(self, binary):
404
407
  if self.bytes:
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "protobin"
7
- version = "0.0.38"
7
+ version = "0.0.39"
8
8
  authors = [
9
9
  { name="Daniel Robles", email="drm.electronic@gmail.com" },
10
10
  ]
@@ -14,7 +14,7 @@
14
14
  "crc_size": 2,
15
15
  "header": "P",
16
16
  "fields": {
17
- "bus_number": {"type": "string"},
17
+ "padron": {"type": "string"},
18
18
  "company": {"type": "string"},
19
19
  "route": {"type": "string"}
20
20
  }
@@ -14,7 +14,7 @@
14
14
  "crc_size": 2,
15
15
  "header": "P",
16
16
  "fields": {
17
- "bus_number": {"type": "string"},
17
+ "padron": {"type": "string"},
18
18
  "company": {"type": "string"},
19
19
  "route": {"type": "string"}
20
20
  }
@@ -727,3 +727,11 @@ report:
727
727
  binary = client.encode(data, 'login_status')
728
728
  print(binary)
729
729
  self.assertEqual(b'P=\x03110\x04roma\x04IO37\x19\x8f', binary)
730
+
731
+ def test_teltonika_login_urbanito(self):
732
+ client = Protocol(file='codec8.json', server=None)
733
+ data = {'company': 'urbanito', 'route': '9802'}
734
+ binary = client.encode(data, 'login_status')
735
+ print(binary)
736
+ self.assertEqual(b'P=\x00\x08urbanito\x049802+\xbf', binary)
737
+
File without changes
File without changes
File without changes
File without changes
File without changes