|
|
@@ -2,35 +2,23 @@ from collections import namedtuple
|
|
|
from enum import IntFlag, IntEnum
|
|
|
from struct import Struct
|
|
|
|
|
|
-
|
|
|
-class XAPRequest(namedtuple('XAPRequest', 'token length data')):
|
|
|
- fmt = Struct('<HB61s')
|
|
|
-
|
|
|
- def __new__(cls, *args):
|
|
|
- return super().__new__(cls, *args)
|
|
|
-
|
|
|
- @staticmethod
|
|
|
- def from_bytes(data):
|
|
|
- return XAPRequest._make(XAPRequest.fmt.unpack(data))
|
|
|
-
|
|
|
- def to_bytes(self):
|
|
|
- return self.fmt.pack(*list(self))
|
|
|
-
|
|
|
-
|
|
|
-class XAPResponse(namedtuple('XAPResponse', 'token flags length data')):
|
|
|
- fmt = Struct('<HBB60s')
|
|
|
+{% set type_definitions = [{'name':'XAPRequest', 'members': 'token length data', 'fmt':'<HB61s'}, {'name':'XAPResponse', 'members': 'token flags length data', 'fmt':'<HBB60s'}] %}
|
|
|
+{% for item in type_definitions -%}
|
|
|
+class {{ item.name }}(namedtuple('{{ item.name }}', '{{ item.members }}')):
|
|
|
+ fmt = Struct('{{ item.fmt }}')
|
|
|
|
|
|
def __new__(cls, *args):
|
|
|
return super().__new__(cls, *args)
|
|
|
|
|
|
- @staticmethod
|
|
|
- def from_bytes(data):
|
|
|
- return XAPResponse._make(XAPResponse.fmt.unpack(data))
|
|
|
+ @classmethod
|
|
|
+ def from_bytes(cls, data):
|
|
|
+ return cls._make(cls.fmt.unpack(data))
|
|
|
|
|
|
def to_bytes(self):
|
|
|
return self.fmt.pack(*list(self))
|
|
|
|
|
|
|
|
|
+{% endfor -%}
|
|
|
class XAPSecureStatus(IntEnum):
|
|
|
LOCKED = 0x00
|
|
|
UNLOCKING = 0x01
|