Welcome to iofree’s documentation!¶
iofree package¶
iofree is an easy-to-use and powerful library to help you implement network protocols and binary parsers.
-
class
iofree.
Parser
(gen: Generator)[source]¶ Bases:
object
-
property
has_result
¶
-
respond
(*, data: bytes = b'', close: bool = False, exc: Optional[Exception] = None, result: Any = <object object>) → None[source]¶ produce some event data to interact with a stream: data: bytes to send to the peer close: whether the socket should be closed exc: raise an exception to break the loop result: result to return
-
property
-
iofree.
get_parser
() → iofree.Parser[source]¶ get current parser object
-
iofree.
parser
(generator_func: Generator) → Generator[source]¶ decorator function to wrap a generator
-
iofree.
peek
(nbytes: int = 1, *, from_=None) → bytes[source]¶ peek many bytes without taking them away from buffer
-
iofree.
read
(nbytes: int = 0, *, from_=None) → bytes[source]¶ if nbytes = 0, read as many as possible, empty bytes is valid; if nbytes > 0, read exactly
nbytes
-
iofree.
read_int
(nbytes: int, byteorder: str = 'big', *, signed=False, from_=None) → int[source]¶ read some bytes as integer
-
iofree.
read_raw_struct
(struct_obj: Struct, *, from_=None) → tuple[source]¶ read raw struct formatted data
-
iofree.
read_until
(data: bytes, *, return_tail: bool = True, from_=None) → bytes[source]¶ read until some bytes appear
Submodules¶
iofree.exceptions module¶
iofree.schema module¶
-
class
iofree.schema.
BinarySchema
(*args)[source]¶ Bases:
object
The main class for users to define their own binary structures
-
classmethod
get_parser
() → iofree.Parser[source]¶
-
classmethod
parse
(data: bytes, *, strict=True) → iofree.schema.BinarySchema[source]¶
-
classmethod
-
class
iofree.schema.
Bytes
(length)[source]¶ Bases:
iofree.schema.Unit
-
class
iofree.schema.
Convert
(unit: Union[iofree.schema.BinarySchemaMetaclass, iofree.schema.Unit], *, encode: Callable = None, decode: Callable = None)[source]¶ Bases:
iofree.schema.Unit
-
class
iofree.schema.
EndWith
(bytes_)[source]¶ Bases:
iofree.schema.Unit
-
iofree.schema.
Group
(**fields: Dict[str, Union[iofree.schema.BinarySchemaMetaclass, iofree.schema.Unit]]) → iofree.schema.BinarySchema[source]¶
-
class
iofree.schema.
IntUnit
(length: int, byteorder: str, signed: bool = False)[source]¶ Bases:
iofree.schema.Unit
-
class
iofree.schema.
LengthPrefixedBytes
(length_unit: iofree.schema.StructUnit)[source]¶ Bases:
iofree.schema.Unit
-
class
iofree.schema.
LengthPrefixedObject
(length_unit: iofree.schema.StructUnit, object_unit: Union[iofree.schema.BinarySchemaMetaclass, iofree.schema.Unit])[source]¶
-
class
iofree.schema.
LengthPrefixedObjectList
(length_unit: iofree.schema.StructUnit, object_unit: Union[iofree.schema.BinarySchemaMetaclass, iofree.schema.Unit])[source]¶ Bases:
iofree.schema.Unit
-
class
iofree.schema.
LengthPrefixedString
(length_unit: iofree.schema.StructUnit, encoding='utf-8')[source]¶ Bases:
iofree.schema.Unit
-
class
iofree.schema.
MustEqual
(unit, value)[source]¶ Bases:
iofree.schema.Unit
-
class
iofree.schema.
SizedIntEnum
(size_unit: iofree.schema.StructUnit, enum_class)[source]¶ Bases:
iofree.schema.Unit
-
class
iofree.schema.
String
(length, encoding='utf-8')[source]¶ Bases:
iofree.schema.Bytes
-
class
iofree.schema.
StructUnit
(format_: str)[source]¶ Bases:
iofree.schema.Unit
-
class
iofree.schema.
Switch
(ref: str, cases: Mapping[Any, Union[iofree.schema.BinarySchemaMetaclass, iofree.schema.Unit]])[source]¶ Bases:
iofree.schema.Unit