trx_toolkit: make codec.py work with EOL Python 3.5
Our build system is based on Debian 9 and EOL Python 3.5, so we have to maintain backwards compatibility (sigh). Some type hints moved to comments, some had to be commented out completely. Hopefully, we can 'un-vandalize' the code by reverting this change once there will be no requirement to support EOL stuff. Change-Id: I7211cfbb7549b6e700aa3dd44464ff762fd51185 Related: OS#4006, SYS#4895
This commit is contained in:
parent
a772337e27
commit
33f456dda3
|
@ -55,17 +55,17 @@ class Field(Codec):
|
||||||
''' Base class representing one field in a Message. '''
|
''' Base class representing one field in a Message. '''
|
||||||
|
|
||||||
# Default length (0 means the whole buffer)
|
# Default length (0 means the whole buffer)
|
||||||
DEF_LEN: int = 0
|
DEF_LEN = 0 # type: int
|
||||||
|
|
||||||
# Default parameters
|
# Default parameters
|
||||||
DEF_PARAMS: dict = { }
|
DEF_PARAMS = { } # type: dict
|
||||||
|
|
||||||
# Presence of a field during decoding and encoding
|
# Presence of a field during decoding and encoding
|
||||||
get_pres: Callable[[dict], bool]
|
## get_pres: Callable[[dict], bool]
|
||||||
# Length of a field for self.from_bytes()
|
# Length of a field for self.from_bytes()
|
||||||
get_len: Callable[[dict, bytes], int]
|
## get_len: Callable[[dict, bytes], int]
|
||||||
# Value of a field for self.to_bytes()
|
# Value of a field for self.to_bytes()
|
||||||
get_val: Callable[[dict], Any]
|
## get_val: Callable[[dict], Any]
|
||||||
|
|
||||||
def __init__(self, name: str, **kw) -> None:
|
def __init__(self, name: str, **kw) -> None:
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -201,7 +201,7 @@ class BitFieldSet(Field):
|
||||||
}
|
}
|
||||||
|
|
||||||
# To be defined by derived types
|
# To be defined by derived types
|
||||||
STRUCT: Tuple['BitField', ...] = ()
|
STRUCT = () # type: Tuple['BitField', ...]
|
||||||
|
|
||||||
def __init__(self, **kw) -> None:
|
def __init__(self, **kw) -> None:
|
||||||
Field.__init__(self, self.__class__.__name__, **kw)
|
Field.__init__(self, self.__class__.__name__, **kw)
|
||||||
|
@ -248,8 +248,8 @@ class BitField:
|
||||||
''' One field in a BitFieldSet. '''
|
''' One field in a BitFieldSet. '''
|
||||||
|
|
||||||
# Special fields for BitFieldSet
|
# Special fields for BitFieldSet
|
||||||
offset: int = 0
|
offset = 0 # type: int
|
||||||
mask: int = 0
|
mask = 0 # type: int
|
||||||
|
|
||||||
class Spare:
|
class Spare:
|
||||||
''' Spare filling in a BitFieldSet. '''
|
''' Spare filling in a BitFieldSet. '''
|
||||||
|
@ -272,7 +272,7 @@ class BitField:
|
||||||
self.bl = bl
|
self.bl = bl
|
||||||
|
|
||||||
# (Optional) fixed value for encoding and decoding
|
# (Optional) fixed value for encoding and decoding
|
||||||
self.val: Optional[int] = kw.get('val', None)
|
self.val = kw.get('val', None) # type: Optional[int]
|
||||||
|
|
||||||
def enc_val(self, vals: dict) -> int:
|
def enc_val(self, vals: dict) -> int:
|
||||||
if self.val is None:
|
if self.val is None:
|
||||||
|
@ -291,11 +291,11 @@ class BitField:
|
||||||
class Envelope:
|
class Envelope:
|
||||||
''' A group of related fields. '''
|
''' A group of related fields. '''
|
||||||
|
|
||||||
STRUCT: Tuple[Codec, ...] = ()
|
STRUCT = () # type: Tuple[Codec, ...]
|
||||||
|
|
||||||
def __init__(self, check_len: bool = True):
|
def __init__(self, check_len: bool = True):
|
||||||
# TODO: ensure uniqueue field names in self.STRUCT
|
# TODO: ensure uniqueue field names in self.STRUCT
|
||||||
self.c: dict = { }
|
self.c = { } # type: dict
|
||||||
self.check_len = check_len
|
self.check_len = check_len
|
||||||
|
|
||||||
def __getitem__(self, key: str) -> Any:
|
def __getitem__(self, key: str) -> Any:
|
||||||
|
@ -368,7 +368,7 @@ class Sequence:
|
||||||
''' A sequence of repeating elements (e.g. TLVs). '''
|
''' A sequence of repeating elements (e.g. TLVs). '''
|
||||||
|
|
||||||
# The item of sequence
|
# The item of sequence
|
||||||
ITEM: Optional[Envelope] = None
|
ITEM = None # type: Optional[Envelope]
|
||||||
|
|
||||||
def __init__(self, **kw) -> None:
|
def __init__(self, **kw) -> None:
|
||||||
if (self.ITEM is None) and ('item' not in kw):
|
if (self.ITEM is None) and ('item' not in kw):
|
||||||
|
|
Loading…
Reference in New Issue