dingsda


Namedingsda JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttp://dingsda.readthedocs.org
SummaryA powerful declarative symmetric parser/builder for binary data with XML de- and encoding
upload_time2023-09-19 02:12:15
maintainer
docs_urlNone
authorTim Blume
requires_python>=3.10
licenseMIT
keywords dingsda construct declarative data structure struct binary symmetric parser builder parsing building pack unpack packer unpacker xml
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            DingsDa 0.1
===================

DingsDa is a powerful **declarative** and **symmetrical** parser and builder for binary data.
It is a fork of Construct 2.1, which removes the parser generator features, but adds preprocessing and XML de- and
encoding. It is build mainly with reverse engineering data formats in mind.

Instead of writing *imperative code* to parse a piece of data, you declaratively define a *data structure* that describes your data. As this data structure is not code, you can use it in one direction to *parse* data into Pythonic objects, and in the other direction, to *build* objects into binary data.

The library provides both simple, atomic constructs (such as integers of various sizes), as well as composite ones which allow you form hierarchical and sequential structures of increasing complexity. Construct features **bit and byte granularity**, easy debugging and testing, an **easy-to-extend subclass system**, and lots of primitive constructs to make your work easier:

* Fields: raw bytes or numerical types
* Structs and Sequences: combine simpler constructs into more complex ones
* Bitwise: splitting bytes into bit-grained fields
* Adapters: change how data is represented
* Arrays/Ranges: duplicate constructs
* Meta-constructs: use the context (history) to compute the size of data
* If/Switch: branch the computational path based on the context
* On-demand (lazy) parsing: read and parse only what you require
* Pointers: jump from here to there in the data stream
* Tunneling: prefix data with a byte count or compress it


Example
---------

A ``Struct`` is a collection of ordered, named fields::

    >>> format = Struct(
    ...     "signature" / Const(b"BMP"),
    ...     "width" / Int8ub,
    ...     "height" / Int8ub,
    ...     "pixels" / Array(this.width * this.height, Byte),
    ... )
    >>> format.build(dict(width=3,height=2,pixels=[7,8,9,11,12,13]))
    b'BMP\x03\x02\x07\x08\t\x0b\x0c\r'
    >>> format.parse(b'BMP\x03\x02\x07\x08\t\x0b\x0c\r')
    Container(signature=b'BMP')(width=3)(height=2)(pixels=[7, 8, 9, 11, 12, 13])

A ``Sequence`` is a collection of ordered fields, and differs from ``Array`` and ``GreedyRange`` in that those two are homogenous::

    >>> format = Sequence(PascalString(Byte, "utf8"), GreedyRange(Byte))
    >>> format.build([u"lalaland", [255,1,2]])
    b'\nlalaland\xff\x01\x02'
    >>> format.parse(b"\x004361789432197")
    ['', [52, 51, 54, 49, 55, 56, 57, 52, 51, 50, 49, 57, 55]]

Most constructs can be build into XML and parsed back from XML:

    >>> s = Struct(
    ...    "a" / Int32ul,
    ...    "b" / Int32ul,
    ...    "s" / Struct(
    ...        "c" / Int32ul,
    ...        "d" / Int32ul,
    ...    ),
    ...    )
    >>> data = {"a": 1, "b": 2, "s": {"c": 3, "d": 4}}
    >>> xml = s.toET(obj=data, name="test")
    >>> assert(ET.tostring(xml) == b'<test a="1" b="2"><s c="3" d="4" /></test>')

    >>> s = "test" / Struct(
    ...     "a" / Int32ul,
    ...     "b" / Int32ul,
    ... )
    >>> xml = ET.fromstring(b'<test a="1" b="2" />')
    >>> obj = s.fromET(xml=xml)
    >>> assert(obj == {"a": 1, "b": 2})

However some constructs, like Switch or FocusedSeq have some caveats,
because they use the XML tag name for identifying the corresponding construct.

This is mainly build for easy and quick describing of datastructures with an
easy, human readable and changeable XML representation, rather than completeness of
all possible constructs.

            

Raw data

            {
    "_id": null,
    "home_page": "http://dingsda.readthedocs.org",
    "name": "dingsda",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "dingsda,construct,declarative,data structure,struct,binary,symmetric,parser,builder,parsing,building,pack,unpack,packer,unpacker,xml",
    "author": "Tim Blume",
    "author_email": "dingsda@3nd.io",
    "download_url": "https://files.pythonhosted.org/packages/a2/f6/5f01178aea4210ea47f91603d468a7af0c302d9117d92ff3be1891c4e472/dingsda-0.2.0.tar.gz",
    "platform": "POSIX",
    "description": "DingsDa 0.1\n===================\n\nDingsDa is a powerful **declarative** and **symmetrical** parser and builder for binary data.\nIt is a fork of Construct 2.1, which removes the parser generator features, but adds preprocessing and XML de- and\nencoding. It is build mainly with reverse engineering data formats in mind.\n\nInstead of writing *imperative code* to parse a piece of data, you declaratively define a *data structure* that describes your data. As this data structure is not code, you can use it in one direction to *parse* data into Pythonic objects, and in the other direction, to *build* objects into binary data.\n\nThe library provides both simple, atomic constructs (such as integers of various sizes), as well as composite ones which allow you form hierarchical and sequential structures of increasing complexity. Construct features **bit and byte granularity**, easy debugging and testing, an **easy-to-extend subclass system**, and lots of primitive constructs to make your work easier:\n\n* Fields: raw bytes or numerical types\n* Structs and Sequences: combine simpler constructs into more complex ones\n* Bitwise: splitting bytes into bit-grained fields\n* Adapters: change how data is represented\n* Arrays/Ranges: duplicate constructs\n* Meta-constructs: use the context (history) to compute the size of data\n* If/Switch: branch the computational path based on the context\n* On-demand (lazy) parsing: read and parse only what you require\n* Pointers: jump from here to there in the data stream\n* Tunneling: prefix data with a byte count or compress it\n\n\nExample\n---------\n\nA ``Struct`` is a collection of ordered, named fields::\n\n    >>> format = Struct(\n    ...     \"signature\" / Const(b\"BMP\"),\n    ...     \"width\" / Int8ub,\n    ...     \"height\" / Int8ub,\n    ...     \"pixels\" / Array(this.width * this.height, Byte),\n    ... )\n    >>> format.build(dict(width=3,height=2,pixels=[7,8,9,11,12,13]))\n    b'BMP\\x03\\x02\\x07\\x08\\t\\x0b\\x0c\\r'\n    >>> format.parse(b'BMP\\x03\\x02\\x07\\x08\\t\\x0b\\x0c\\r')\n    Container(signature=b'BMP')(width=3)(height=2)(pixels=[7, 8, 9, 11, 12, 13])\n\nA ``Sequence`` is a collection of ordered fields, and differs from ``Array`` and ``GreedyRange`` in that those two are homogenous::\n\n    >>> format = Sequence(PascalString(Byte, \"utf8\"), GreedyRange(Byte))\n    >>> format.build([u\"lalaland\", [255,1,2]])\n    b'\\nlalaland\\xff\\x01\\x02'\n    >>> format.parse(b\"\\x004361789432197\")\n    ['', [52, 51, 54, 49, 55, 56, 57, 52, 51, 50, 49, 57, 55]]\n\nMost constructs can be build into XML and parsed back from XML:\n\n    >>> s = Struct(\n    ...    \"a\" / Int32ul,\n    ...    \"b\" / Int32ul,\n    ...    \"s\" / Struct(\n    ...        \"c\" / Int32ul,\n    ...        \"d\" / Int32ul,\n    ...    ),\n    ...    )\n    >>> data = {\"a\": 1, \"b\": 2, \"s\": {\"c\": 3, \"d\": 4}}\n    >>> xml = s.toET(obj=data, name=\"test\")\n    >>> assert(ET.tostring(xml) == b'<test a=\"1\" b=\"2\"><s c=\"3\" d=\"4\" /></test>')\n\n    >>> s = \"test\" / Struct(\n    ...     \"a\" / Int32ul,\n    ...     \"b\" / Int32ul,\n    ... )\n    >>> xml = ET.fromstring(b'<test a=\"1\" b=\"2\" />')\n    >>> obj = s.fromET(xml=xml)\n    >>> assert(obj == {\"a\": 1, \"b\": 2})\n\nHowever some constructs, like Switch or FocusedSeq have some caveats,\nbecause they use the XML tag name for identifying the corresponding construct.\n\nThis is mainly build for easy and quick describing of datastructures with an\neasy, human readable and changeable XML representation, rather than completeness of\nall possible constructs.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A powerful declarative symmetric parser/builder for binary data with XML de- and encoding",
    "version": "0.2.0",
    "project_urls": {
        "Documentation": "https://dingsda.readthedocs.io/en/latest/",
        "Homepage": "http://dingsda.readthedocs.org",
        "Issues": "https://github.com/ev1313/dingsda/issues",
        "Source": "https://github.com/ev1313/dingsda"
    },
    "split_keywords": [
        "dingsda",
        "construct",
        "declarative",
        "data structure",
        "struct",
        "binary",
        "symmetric",
        "parser",
        "builder",
        "parsing",
        "building",
        "pack",
        "unpack",
        "packer",
        "unpacker",
        "xml"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "44b9b09f85dd05399094f31a41e3aab8d85f08bd144ac79d61670e5a52666bf3",
                "md5": "e094392f163c39b10487e58662cd8c77",
                "sha256": "f365c4a72b9a2d3d73bd486aff8f2d815a80ca510a2e4319a5d29ec137a13885"
            },
            "downloads": -1,
            "filename": "dingsda-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e094392f163c39b10487e58662cd8c77",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 69441,
            "upload_time": "2023-09-19T02:12:13",
            "upload_time_iso_8601": "2023-09-19T02:12:13.644312Z",
            "url": "https://files.pythonhosted.org/packages/44/b9/b09f85dd05399094f31a41e3aab8d85f08bd144ac79d61670e5a52666bf3/dingsda-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a2f65f01178aea4210ea47f91603d468a7af0c302d9117d92ff3be1891c4e472",
                "md5": "8daab6071dd7a9cb6ce407f139b40603",
                "sha256": "08565ae7db9b9b82dfcdaaf1d1b44c06ad95f48772dbc6c8494b2c8b4bf32440"
            },
            "downloads": -1,
            "filename": "dingsda-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8daab6071dd7a9cb6ce407f139b40603",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 89420,
            "upload_time": "2023-09-19T02:12:15",
            "upload_time_iso_8601": "2023-09-19T02:12:15.827043Z",
            "url": "https://files.pythonhosted.org/packages/a2/f6/5f01178aea4210ea47f91603d468a7af0c302d9117d92ff3be1891c4e472/dingsda-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-19 02:12:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ev1313",
    "github_project": "dingsda",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "dingsda"
}
        
Elapsed time: 0.17685s