Stefan Schuermans
PCB element Python types
Stefan Schuermans commited 8a9acb1 at 2021-02-17 19:13:39
"""
Types representing entities of GNU PCB files.
"""
import collections
class Struct:
"""
Base class for struct-like Python objects
"""
_attrs = collections.OrderedDict() # attribute name: str -> default value
def __init__(self, **kwargs):
for name, def_val in self._attrs.items():
setattr(self, name, def_val)
for name, val in kwargs.items():
if name not in self._attrs:
raise ValueError(
f'{type(self).__name__:s} does not have attribute {name:s}'
)
setattr(self, name, val)
def __repr__(self) -> str:
vals = ', '.join([
f'{name:s}={repr(getattr(self, name)):s}'
for name in self._attrs.keys()
])
return f'{type(self).__name__:s}({vals:s})'
def _compare(self, other) -> int:
if self._attrs != other._attrs:
raise ValueError(f'{type(self).__name__:s} cannot be'
f' compared to {type(other).__name__:s}')
for name in self._attrs:
s = getattr(self, name)
o = getattr(other, name)
if s < o:
return -1
if s > o:
return 1
return 0
def __eq__(self, other) -> bool:
return self._compare(other) == 0
def __ne__(self, other) -> bool:
return self._compare(other) != 0
def __lt__(self, other) -> bool:
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX