protobin 0.0.27__tar.gz → 0.0.28__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.27
3
+ Version: 0.0.28
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
@@ -0,0 +1,17 @@
1
+ from protobin import Protocol
2
+
3
+
4
+ class ProtobinLoader(object):
5
+ __instance = None
6
+ protocols = {}
7
+
8
+ def __new__(cls):
9
+ if ProtobinLoader.__instance is None:
10
+ ProtobinLoader.__instance = object.__new__(cls)
11
+ return ProtobinLoader.__instance
12
+
13
+ def get(self, path):
14
+ if path not in self.protocols:
15
+ # print('load protocol', path)
16
+ self.protocols[path] = Protocol(file=path)
17
+ return self.protocols[path]
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "protobin"
7
- version = "0.0.27"
7
+ version = "0.0.28"
8
8
  authors = [
9
9
  { name="Daniel Robles", email="drm.electronic@gmail.com" },
10
10
  ]
@@ -5,6 +5,7 @@ import json
5
5
  import yaml
6
6
  from protobin import Protocol
7
7
  from protobin.errors import InputError, FormatError
8
+ from protobin.singleton import ProtobinLoader
8
9
 
9
10
  DATA = {
10
11
  'positions': [
@@ -642,4 +643,12 @@ report:
642
643
  binary = b'\x00\x00\x00\x00\x00\x00\x00!\x08\x01\x00\x00\x01\x93\x92\x82\xb5\xa0\x00\xd2\x1bB\x12\xf8\xcb\xbf[\x00\xc2\x01\n\x10\x00\x0c\x00\x00\x00\x00\x00\x00\x01\x00\x00=G'
643
644
  client = Protocol(file='codec8.json')
644
645
  header, recv = client.decode(binary)
645
- print(header, recv)
646
+ print(header, recv)
647
+
648
+ def test_singleton(self):
649
+ loader = ProtobinLoader()
650
+ loader.get('codec8.json')
651
+ loader.get('codec8.json')
652
+ loader.get('codec8.json')
653
+ loader.get('codec8.json')
654
+ loader.get('codec8.json')
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes