File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,14 +7,16 @@ authors = [
77 {
name =
" GuangChen23333" ,
email =
" [email protected] " }
88]
99readme = " README.md"
10+ requires-python = " >=3.8"
11+ dynamic = [" dependencies" ]
1012
1113[tool .poetry ]
1214packages = [
1315 { include = " structovo" , from = " src" }
1416]
1517
1618[tool .poetry .dependencies ]
17- python = " ^3.12 "
19+ python = " >=3.8, <4.0 "
1820
1921[build-system ]
2022requires = [" poetry-core" ]
Original file line number Diff line number Diff line change 1- from enum import StrEnum
1+ from enum import Enum
22
3-
4- class Endianness (StrEnum ):
3+ class Endianness (Enum ):
54 BIG = '>'
65 LITTLE = '<'
76 NETWORK = '!'
Original file line number Diff line number Diff line change 1- from typing import TypeVar
1+ from typing import TypeVar , Optional
22from ._types import BaseType , FixedString
33from ._enums import Endianness
44
77
88class Pack :
99 @classmethod
10- def build (cls , endianness : Endianness = Endianness .NATIVE ) -> bytes :
10+ def build (cls , endianness : Optional [ Endianness ] = Endianness .NATIVE ) -> bytes :
1111 anns = cls .__annotations__
1212 data = cls .__dict__
1313
1414 result_list = []
1515
1616 for key , type_class in anns .items ():
17- if not issubclass (type_class , BaseType ):
18- raise ValueError (f"{ type_class } is not an instance of structovo.BaseType" )
17+ if not issubclass (type_class , BaseType ) and not type_class is bytes :
18+ raise ValueError (f"{ type_class } is not an instance of bytes or structovo.BaseType" )
1919
20- if type_class is FixedString :
20+ if type_class is bytes :
21+ result_list .append (data .get (key ))
22+ continue
23+
24+ elif type_class is FixedString :
2125 try :
2226 value : FixedString = FixedString (data [key ][0 ], data [key ][1 ])
2327 except IndexError :
2428 raise ValueError ('Using x: FixedString = (value: bytes, length: int)' )
29+
2530 else :
2631 value : BaseType = type_class (data .get (key ))
2732
You can’t perform that action at this time.
0 commit comments