netzob.Common.Utils package

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: list

This 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

class SortableObject[source]

Bases: object

priority()[source]

netzob.Common.Utils.SortedTypedList module

netzob.Common.Utils.TypedList module

class TypedList(membersTypes, *args)[source]

Bases: collections.abc.MutableSequence

A 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'>
check(v)[source]
insert(i, v)[source]

netzob.Common.Utils.all module

Module contents