Skip to content

Commit 5e114eb

Browse files
committed
black code style
1 parent 4c05484 commit 5e114eb

15 files changed

Lines changed: 1285 additions & 219 deletions

cstruct/__init__.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,13 @@
2424
# IN THE SOFTWARE.
2525
#
2626

27-
__author__ = 'Andrea Bonomi <andrea.bonomi@gmail.com>'
27+
__author__ = 'Andrea Bonomi <andrea.bonomi@gmail.com>'
2828
__license__ = 'MIT'
2929
__version__ = '2.1'
3030
__date__ = '15 August 2013'
3131

3232
import struct
33-
from typing import (
34-
Any,
35-
Dict,
36-
Type
37-
)
33+
from typing import Any, Dict, Type
3834
from .base import (
3935
LITTLE_ENDIAN,
4036
BIG_ENDIAN,
@@ -44,7 +40,7 @@
4440
TYPEDEFS,
4541
C_TYPE_TO_FORMAT,
4642
CHAR_ZERO,
47-
EMPTY_BYTES_STRING
43+
EMPTY_BYTES_STRING,
4844
)
4945
from .abstract import CStructMeta, AbstractCStruct
5046
from .cstruct import CStruct
@@ -62,9 +58,10 @@
6258
'undef',
6359
'typedef',
6460
'sizeof',
65-
'parse'
61+
'parse',
6662
]
6763

64+
6865
def define(key: str, value: Any) -> None:
6966
"""
7067
Define a constant that can be used in the C struct
@@ -74,6 +71,7 @@ def define(key: str, value: Any) -> None:
7471
"""
7572
DEFINES[key] = value
7673

74+
7775
def undef(key: str) -> None:
7876
"""
7977
Undefine a symbol that was previously defined with define
@@ -82,6 +80,7 @@ def undef(key: str) -> None:
8280
"""
8381
del DEFINES[key]
8482

83+
8584
def typedef(type_: str, alias: str) -> None:
8685
"""
8786
Define an alias name for a data type
@@ -91,6 +90,7 @@ def typedef(type_: str, alias: str) -> None:
9190
"""
9291
TYPEDEFS[alias] = type_
9392

93+
9494
def sizeof(type_: str) -> int:
9595
"""
9696
Return the size of the type.
@@ -116,7 +116,8 @@ def sizeof(type_: str) -> int:
116116
else:
117117
return struct.calcsize(ttype)
118118

119-
def parse(__struct__: str , __cls__: Type[Any] = None, **kargs: Any) -> AbstractCStruct:
119+
120+
def parse(__struct__: str, __cls__: Type[Any] = None, **kargs: Any) -> AbstractCStruct:
120121
"""
121122
Return a new class mapping a C struct/union definition.
122123
@@ -130,4 +131,3 @@ def parse(__struct__: str , __cls__: Type[Any] = None, **kargs: Any) -> Abstract
130131
if __cls__ is None:
131132
__cls__ = CStruct
132133
return __cls__.parse(__struct__, **kargs)
133-

cstruct/abstract.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,12 @@
2828
from typing import cast, Any, BinaryIO, Optional, Type, Union
2929
from .base import STRUCTS
3030
import hashlib
31-
from .c_parser import (parse_struct, parse_def, Tokens)
31+
from .c_parser import parse_struct, parse_def, Tokens
3232

33-
__all__ = [
34-
'CStructMeta',
35-
'AbstractCStruct'
36-
]
33+
__all__ = ['CStructMeta', 'AbstractCStruct']
3734

38-
class CStructMeta(ABCMeta):
3935

36+
class CStructMeta(ABCMeta):
4037
def __new__(cls, name: str, bases, dct):
4138
__struct__ = dct.get("__struct__", None)
4239
dct['__cls__'] = bases[0]
@@ -60,16 +57,16 @@ def __len__(cls) -> int:
6057

6158
@property
6259
def size(cls) -> int:
63-
""" Structure size (in bytes) """
60+
"""Structure size (in bytes)"""
6461
return cls.__size__
6562

63+
6664
# Workaround for Python 2.x/3.x metaclass, thanks to
6765
# http://mikewatkins.ca/2008/11/29/python-2-and-3-metaclasses/#using-the-metaclass-in-python-2-x-and-3-x
68-
_CStructParent = CStructMeta('_CStructParent', (object, ), {})
66+
_CStructParent = CStructMeta('_CStructParent', (object,), {})
6967

7068

7169
class AbstractCStruct(_CStructParent):
72-
7370
def __init__(self, buffer=None, **kargs) -> None:
7471
if buffer is not None:
7572
self.unpack(buffer)
@@ -135,16 +132,16 @@ def clear(self) -> None:
135132
self.unpack(None)
136133

137134
def __len__(self) -> int:
138-
""" Structure size (in bytes) """
135+
"""Structure size (in bytes)"""
139136
return cast(int, self.__size__)
140137

141138
@property
142139
def size(self) -> int:
143-
""" Structure size (in bytes) """
140+
"""Structure size (in bytes)"""
144141
return self.__size__
145142

146143
def __eq__(self, other: Any) -> bool:
147-
return (isinstance(other, self.__class__) and self.__dict__ == other.__dict__)
144+
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
148145

149146
def __ne__(self, other: Any) -> bool:
150147
return not self.__eq__(other)

cstruct/base.py

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
'TYPEDEFS',
3737
'C_TYPE_TO_FORMAT',
3838
'EMPTY_BYTES_STRING',
39-
'CHAR_ZERO'
39+
'CHAR_ZERO',
4040
]
4141

4242
# little-endian, std. size & alignment
@@ -46,53 +46,50 @@
4646
# native order, size & alignment
4747
NATIVE_ORDER = '@'
4848

49-
STRUCTS: Dict[str, Type[Any]] = {
50-
}
49+
STRUCTS: Dict[str, Type[Any]] = {}
5150

52-
DEFINES: Dict[str, Any] = {
53-
}
51+
DEFINES: Dict[str, Any] = {}
5452

5553
TYPEDEFS: Dict[str, str] = {
56-
'short int': 'short',
57-
'unsigned short int': 'unsigned short',
58-
'ushort': 'unsigned short',
59-
'long int': 'long',
60-
'unsigned long int': 'unsigned long',
61-
'int8_t': 'int8',
62-
'uint8_t': 'uint8',
63-
'int16_t': 'int16',
64-
'uint16_t': 'uint16',
65-
'int32_t': 'int32',
66-
'uint32_t': 'uint32',
67-
'int64_t': 'int64',
68-
'uint64_t': 'uint64',
54+
'short int': 'short',
55+
'unsigned short int': 'unsigned short',
56+
'ushort': 'unsigned short',
57+
'long int': 'long',
58+
'unsigned long int': 'unsigned long',
59+
'int8_t': 'int8',
60+
'uint8_t': 'uint8',
61+
'int16_t': 'int16',
62+
'uint16_t': 'uint16',
63+
'int32_t': 'int32',
64+
'uint32_t': 'uint32',
65+
'int64_t': 'int64',
66+
'uint64_t': 'uint64',
6967
}
7068

7169
C_TYPE_TO_FORMAT: Dict[str, str] = {
72-
'char': 's',
73-
'signed char': 'b',
74-
'unsigned char': 'B',
75-
'short': 'h',
76-
'unsigned short': 'H',
77-
'int': 'i',
78-
'unsigned int': 'I',
79-
'long': 'l',
80-
'unsigned long': 'L',
81-
'long long': 'q',
82-
'unsigned long long': 'Q',
83-
'float': 'f',
84-
'double': 'd',
85-
'void *': 'P',
86-
'int8': 'b',
87-
'uint8': 'B',
88-
'int16': 'h',
89-
'uint16': 'H',
90-
'int32': 'i',
91-
'uint32': 'I',
92-
'int64': 'q',
93-
'uint64': 'Q',
70+
'char': 's',
71+
'signed char': 'b',
72+
'unsigned char': 'B',
73+
'short': 'h',
74+
'unsigned short': 'H',
75+
'int': 'i',
76+
'unsigned int': 'I',
77+
'long': 'l',
78+
'unsigned long': 'L',
79+
'long long': 'q',
80+
'unsigned long long': 'Q',
81+
'float': 'f',
82+
'double': 'd',
83+
'void *': 'P',
84+
'int8': 'b',
85+
'uint8': 'B',
86+
'int16': 'h',
87+
'uint16': 'H',
88+
'int32': 'i',
89+
'uint32': 'I',
90+
'int64': 'q',
91+
'uint64': 'Q',
9492
}
9593

9694
EMPTY_BYTES_STRING = bytes()
9795
CHAR_ZERO = bytes('\0', 'ascii')
98-

0 commit comments

Comments
 (0)