Construct 2.00 (RC1) released
sebulba
tomerfiliba at gmail.com
Tue Dec 19 23:42:23 CET 2006
http://pyconstruct.wikispaces.com
Construct is a library for parsing and building (AKA packing and
unpacking) of data structures such as in-memory structures, file
formats, or network protocols. Unlike other libraries, Construct is
_declarative_, meaning you define the data structure, and not the code
that parses/builds it. As a result, constructs can do both parsing and
building, with no extra code. The library comes with many built-in
primitives, and a large inventory of protocols and file formats.
A full tutorial can be found on the site. Note: the docs are
work-in-progress until the final 2.0 release will be made in the next
two weeks.
If you wish to get a quick taste of the library, consider the following
snippet:
>>> from construct import *
>>>
>>>
>>> ethernet_header = Struct("ethernet_header",
... Bytes("dest", 6),
... Bytes("source", 6),
... Enum(UBInt16("type"),
... IP = 0x0800,
... ARP = 0x0806,
... X25 = 0x0805
... )
... )
>>>
>>>
>>> print ethernet_header.parse("ABCDEF123456\x08\x00")
Container:
dest = 'ABCDEF'
source = '123456'
type = 'IP'
>>>
>>>
>>> ethernet_header.build(Container(dest = "aaabbb", source = "333444", type = "X25"))
'aaabbb333444\x08\x05'
-tomer
More information about the Python-announce-list
mailing list