netzob.Common.Utils package¶
Subpackages¶
Submodules¶
netzob.Common.Utils.Decorators module¶
-
NetzobLogger(klass)[source]¶ This class decorator adds (if necessary) an instance of the logger (self.__logger) to the attached class and removes from the getState the logger.
-
typeCheck(*types)[source]¶ Decorator which reduces the amount of code to type-check attributes.
Its allows to replace the following code:
@id.setter def id(self, id): if not isinstance(id, uuid.UUID): raise TypeError("Invalid types for argument id, must be an UUID") self.__id = id
with:
@id.setter @typeCheck(uuid.UUID) def id(self, id): self.__id = id
Note
set type = “SELF” to check the type of the self parameter
Warning
if argument is None, the type checking is not executed on it.
netzob.Common.Utils.MatrixList module¶
-
class
MatrixList[source]¶ Bases:
listThis type of list has been created to represent it as matrix which means its a list of list.
The __str__ method has been redefined to propose a nice representation of its content.
-
headers¶ A list of sorted strings. Each string will be displayed as a column header
-
netzob.Common.Utils.SortableObject module¶
netzob.Common.Utils.SortedTypedList module¶
netzob.Common.Utils.TypedList module¶
-
class
TypedList(membersTypes, *args)[source]¶ Bases:
collections.abc.MutableSequenceA strong typed list based on collections.MutableSequence.
The idea is to verify members type when editing the list. By using this class instead of the typical list, we enforce members type.
>>> typedList = TypedList(str) >>> typedList.append("toto") >>> typedList.extend(["titi", "tata"]) >>> len(typedList) 3 >>> typedList[1] 'titi' >>> typedList.append(3) Traceback (most recent call last): TypeError: Invalid type for argument, expecting: <type 'str'> >>> typedList.extend(["tutu", 5]) Traceback (most recent call last): TypeError: Invalid type for argument, expecting: <type 'str'>