{ "info": { "author": "Kay Schluehr", "author_email": "easyextend@fiber-space.de", "bugtrack_url": null, "classifiers": [], "description": "**P4D is not Python but it is also fun**\r\n\r\nP4D ( = Python for Data ) is an `EasyExtend langlet\r\n`_ used to write tree shaped\r\ntextual data a.k.a XML.\r\n\r\nP4D elements are written as statements in a notation being familiar for Python\r\nprogrammers. They closely resemble Python statements. Here is one used to define\r\nan element ::\r\n\r\n elm philosophers:\r\n philosopher:\r\n name: \"Hegel\"\r\n books:\r\n book( first_edition = 1807):\r\n title: \"Ph\u00e4nomenologie des Geistes\"\r\n language: \"german\"\r\n philosopher:\r\n name: \"Leibniz\"\r\n books:\r\n book( first_edition = 1714):\r\n title: \"Monadologie\"\r\n language: \"french\"\r\n\r\nThe ``elm`` keyword is new and it is one of the few occasions where P4D breaks\r\nactual\r\nPython code. However I did not found ``elm`` being used in Pythons stdlib so it\r\nmight\r\nbreak just none.\r\n\r\nThe subobjects of ``philosophers`` can be accessed in E4X style ::\r\n\r\n books = philosophers.philosopher.(name == \"Hegel\").books\r\n books.book.(@first_edition < 1810).title.text()\r\n # -> \"Ph\u00e4nomenologie des Geistes\"\r\n\r\nP4D can also be used as a *template language* in the sense that Python\r\nexpressions can be embedded in P4D elements ::\r\n\r\n L = [1,2,3]\r\n elm A:\r\n B: &L\r\n\r\n elm X:\r\n & A\r\n\r\nThe elements of the list object ``L`` will be distributed over elements of type B ::\r\n\r\n assert len(A.B) == 3\r\n assert X.A.B[0].text() == '1'\r\n\r\nIt is easy to convert a P4D element into an XML element using the ``xmlstr()``\r\nmethod.\r\nOtherwise one can convert XML to P4D using ``P4D.from_xml()``. This is so easy\r\nbecause\r\ninternally the same datastructure is used. Building a P4D element and parsing \r\nan XML document leads to the same internal representation. This internal\r\nrepresentation can be used to store even more distinct objects having quite\r\ndifferent properties and are not even textual but binary.\r\n\r\n**Bytelets**\r\n\r\nOther than XML and the P4D elements we've seen above Bytelets are used to deal\r\nwith binary data in a flexible manner.\r\n\r\nSuppose you want to serialize a string and don't want to use null-termination.\r\nThen you have to send the length of the string together with the string and \r\nthe type or ``tag`` for the receiver to identify the hexcode as a string ::\r\n\r\n elm bl:text:\r\n Tag: 0x50\r\n Len: &LEN\r\n Text: \"{obamania}\"\r\n\r\nThis P4D element produces a Bytelet. Bytelets are generally prefixed using the\r\n``bl`` namespace prefix. The ``LEN`` object is a so called ``Flow`` object. It\r\nis kind of a dataflow binding. If you bind ``LEN`` to a field it computes the\r\nsum of the lengths of all values of subsequent fields. If you update the Bytelet\r\nthe value of the `` Len`` field will be re-computed using ``LEN``.\r\n\r\nOne can check this out ::\r\n\r\n assert text.Len.hex() == 8\r\n\r\nHere ``8`` is just the length of the text. ::\r\n\r\n new_text = text.clone()\r\n new_text.Text = \"{the merkel}\"\r\n assert new_text.Len.hex() == 10\r\n\r\nOne can fully evaluate the ``text`` Bytelet ::\r\n\r\n assert text.hex() == 0x50 0x08 0x6F 0x62 0x61 0x6D 0x61 0x6E 0x69 0x61\r\n\r\nNotice that writing ``0x50 0x08 0x6F ... `` without quotes is valid in P4D and\r\nit yields a ``Hex`` object not a number. So P4D supports enhanced hexadecimal\r\nliterals which obtain a different semantics than Pythons.\r\n\r\nNow we want to turn the ``Hex`` object back into a Bytelet for which it has to\r\nbe parsed. This is done by a ``Schema`` ::\r\n\r\n elm bl-schema:TextSchema:\r\n \tTag: 1\r\n \tLen: &LEN\r\n \tText: &VAL\r\n\r\n parsed = TextSchema.parse(text.hex())\r\n assert parsed.hex() == text.hex()\r\n\r\nA ``Schema`` is characterized by the namespace prefix ``bl-schema``. Otherwise\r\nit is just another Bytelet with a ``parse()`` method. Here the Schema has the\r\nexact same structure than the original Bytelet but different field values. The\r\nnew value ``VAL`` is also a dataflow binding. It binds to the ``Len`` field.\r\nAfter the value ``0x08`` is assigned to ``Len`` while parsing the ``VAL``\r\nbinding uses this value to chop of ``8`` bytes from the input stream and \r\nassign it to Text.\r\n\r\nMore features of Bytelets:\r\n\r\n* Specifications of Bytelets can be refined by setting individual bits \r\n and specifying bit array widths.\r\n* Schemas can be used to parse arbitrary sequences of ``T(ag)L(ength)V(alue)``\r\n structures like the one in our example. However the order of the ``TLVs`` \r\n need not be fixed.\r\n* Simple arithmetics is defined for ``Flow`` objects like ``LEN`` and ``VAL``. \r\n So we can write ``Len : &LEN + 1`` but also ``Text: &VAL - VAL[\"IHL\"]*4`` \r\n where ``VAL[\"IHL\"]`` refers not to ``Len`` but another field ``IHL``.\r\n\r\n\r\nFor more information look at the P4D documents\r\n\r\nhttp://www.fiber-space.de/EasyExtend/doc/p4d/p4d.html\r\n\r\nhttp://www.fiber-space.de/EasyExtend/doc/p4d/bytelets.html", "description_content_type": null, "docs_url": null, "download_url": "http://www.fiber-space.de/EasyExtend/doc/main/Download_EE.html", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://www.fiber-space.de/", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "P4D-Langlet", "package_url": "https://pypi.org/project/P4D-Langlet/", "platform": "Python", "project_url": "https://pypi.org/project/P4D-Langlet/", "project_urls": { "Download": "http://www.fiber-space.de/EasyExtend/doc/main/Download_EE.html", "Homepage": "http://www.fiber-space.de/" }, "release_url": "https://pypi.org/project/P4D-Langlet/1.2.4/", "requires_dist": null, "requires_python": null, "summary": "E4X style embedded DSL for Python but without E and X", "version": "1.2.4" }, "last_serial": 784868, "releases": { "1.2.2": [ { "comment_text": "", "digests": { "md5": "a24ab259851f5d588c95def4f3462fc0", "sha256": "6aab0d0764cc09e4c31e1d53bf0e2f21548e9741f2786b8820d83fd6efba92c5" }, "downloads": -1, "filename": "P4D Langlet-1.2.2-py2.5.tgz", "has_sig": false, "md5_digest": "a24ab259851f5d588c95def4f3462fc0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 395788, "upload_time": "2008-08-13T20:52:39", "url": "https://files.pythonhosted.org/packages/69/f4/2203e708514184f5d5745ca039047443ff4e17a3ecd5fdaebe710cea4842/P4D%20Langlet-1.2.2-py2.5.tgz" }, { "comment_text": "", "digests": { "md5": "cfc5ca223d7d8e6bd9ecee1a04c14215", "sha256": "2131adc668e29788a7a42c8ac503b96caebf2b8f12a8c8acc2d6c117b5cc2ec9" }, "downloads": -1, "filename": "P4D Langlet-1.2.2-py2.5.zip", "has_sig": false, "md5_digest": "cfc5ca223d7d8e6bd9ecee1a04c14215", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 526966, "upload_time": "2008-08-13T20:52:21", "url": "https://files.pythonhosted.org/packages/92/ef/e338d4072440d905591934f9ccb26494eee1e8abd52a6d0c98a5d2b4b89b/P4D%20Langlet-1.2.2-py2.5.zip" }, { "comment_text": "", "digests": { "md5": "a76ebf2e76e45b79a4f1c4107cc4783d", "sha256": "b72ed95f5678b7d63ce9ca37c94f35ef740e3265e33701c9fbea1f7144b097c3" }, "downloads": -1, "filename": "P4D Langlet-1.2.2.win32-py2.5.exe", "has_sig": false, "md5_digest": "a76ebf2e76e45b79a4f1c4107cc4783d", "packagetype": "bdist_wininst", "python_version": "2.5", "requires_python": null, "size": 436029, "upload_time": "2008-08-13T20:52:57", "url": "https://files.pythonhosted.org/packages/40/1b/e47eb270ce608d02f066c9e6286021b82de2492d2de3c6a6a713ef54fc7e/P4D%20Langlet-1.2.2.win32-py2.5.exe" } ], "1.2.3": [ { "comment_text": "", "digests": { "md5": "a0a7fa769dac7f796beee22cac9bb16d", "sha256": "fd13d704e1ee158da89e474efe3790a008e69e6ebbf4b5483a07c587c9c6e7b3" }, "downloads": -1, "filename": "P4D Langlet-1.2.3-py2.5.tar.gz", "has_sig": false, "md5_digest": "a0a7fa769dac7f796beee22cac9bb16d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 462629, "upload_time": "2008-08-16T11:56:07", "url": "https://files.pythonhosted.org/packages/44/35/503b8f833c05c952c63b656b57fe59a6f0d80864451cdd7608e4e41e9081/P4D%20Langlet-1.2.3-py2.5.tar.gz" }, { "comment_text": "", "digests": { "md5": "82cc39098d8d7496047860ca45b3294d", "sha256": "97faa94630f36531c944e96751818b3de30772e7a50e82cd141435a7de7bd2ba" }, "downloads": -1, "filename": "P4D Langlet-1.2.3-py2.5.zip", "has_sig": false, "md5_digest": "82cc39098d8d7496047860ca45b3294d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 599673, "upload_time": "2008-08-16T11:55:45", "url": "https://files.pythonhosted.org/packages/c1/60/3a374e02003ae75a75a29f20cca08304e42dbe93ef2963a398022c1b53e9/P4D%20Langlet-1.2.3-py2.5.zip" }, { "comment_text": "", "digests": { "md5": "936d645b6c3789feeaaa7e44c30a720b", "sha256": "8358506de698a156332701760c702337b3e49546c8914236340f6c51746cb689" }, "downloads": -1, "filename": "P4D Langlet-1.2.3.win32-py2.5.exe", "has_sig": false, "md5_digest": "936d645b6c3789feeaaa7e44c30a720b", "packagetype": "bdist_wininst", "python_version": "2.5", "requires_python": null, "size": 617123, "upload_time": "2008-08-16T11:56:51", "url": "https://files.pythonhosted.org/packages/61/f2/0d5e63946bdbc021894e21f41f893bfbd9d68fb5e97c2e0716da38bc8dc4/P4D%20Langlet-1.2.3.win32-py2.5.exe" } ], "1.2.4": [ { "comment_text": "", "digests": { "md5": "6440f945e988d151d8e6bae852c40028", "sha256": "307d0bdf3fa06bffb04ca86fe51c41e4fb6ef15754312e255ed4c9a682f6fb02" }, "downloads": -1, "filename": "P4D Langlet-1.2.4-py2.5.tar.gz", "has_sig": false, "md5_digest": "6440f945e988d151d8e6bae852c40028", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 482563, "upload_time": "2008-09-15T05:11:11", "url": "https://files.pythonhosted.org/packages/9a/92/de461679d73caffccf8cf665e869823f6751fde5bcda80771e11db6b985a/P4D%20Langlet-1.2.4-py2.5.tar.gz" }, { "comment_text": "", "digests": { "md5": "9d2159177d12c1f4890e70606f99c6c3", "sha256": "4aef6fdd64b0a8269f9d98e27e8cf6cabd57f9aa1565b72c1dd86ace3c4d0d4a" }, "downloads": -1, "filename": "P4D Langlet-1.2.4-py2.5.zip", "has_sig": false, "md5_digest": "9d2159177d12c1f4890e70606f99c6c3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 620311, "upload_time": "2008-09-15T05:10:55", "url": "https://files.pythonhosted.org/packages/43/a5/8a7237553cd6d8bf03e9a3e653f003a94c13f20ac12030b98ccacc6be94b/P4D%20Langlet-1.2.4-py2.5.zip" }, { "comment_text": "", "digests": { "md5": "3b9db3299eaf31b50187deaae31b9c3b", "sha256": "d4e5d1682906869a28647eeea1279c0d8d5f00e5f880c96f154231c31a01ec50" }, "downloads": -1, "filename": "P4D Langlet-1.2.4.win32-py2.5.exe", "has_sig": false, "md5_digest": "3b9db3299eaf31b50187deaae31b9c3b", "packagetype": "bdist_wininst", "python_version": "2.5", "requires_python": null, "size": 637728, "upload_time": "2008-09-15T05:11:33", "url": "https://files.pythonhosted.org/packages/2c/bb/f74af2fe2a7ca01e4f425322c5ceb40e32225ff6451dcef7c1f9b93b399a/P4D%20Langlet-1.2.4.win32-py2.5.exe" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6440f945e988d151d8e6bae852c40028", "sha256": "307d0bdf3fa06bffb04ca86fe51c41e4fb6ef15754312e255ed4c9a682f6fb02" }, "downloads": -1, "filename": "P4D Langlet-1.2.4-py2.5.tar.gz", "has_sig": false, "md5_digest": "6440f945e988d151d8e6bae852c40028", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 482563, "upload_time": "2008-09-15T05:11:11", "url": "https://files.pythonhosted.org/packages/9a/92/de461679d73caffccf8cf665e869823f6751fde5bcda80771e11db6b985a/P4D%20Langlet-1.2.4-py2.5.tar.gz" }, { "comment_text": "", "digests": { "md5": "9d2159177d12c1f4890e70606f99c6c3", "sha256": "4aef6fdd64b0a8269f9d98e27e8cf6cabd57f9aa1565b72c1dd86ace3c4d0d4a" }, "downloads": -1, "filename": "P4D Langlet-1.2.4-py2.5.zip", "has_sig": false, "md5_digest": "9d2159177d12c1f4890e70606f99c6c3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 620311, "upload_time": "2008-09-15T05:10:55", "url": "https://files.pythonhosted.org/packages/43/a5/8a7237553cd6d8bf03e9a3e653f003a94c13f20ac12030b98ccacc6be94b/P4D%20Langlet-1.2.4-py2.5.zip" }, { "comment_text": "", "digests": { "md5": "3b9db3299eaf31b50187deaae31b9c3b", "sha256": "d4e5d1682906869a28647eeea1279c0d8d5f00e5f880c96f154231c31a01ec50" }, "downloads": -1, "filename": "P4D Langlet-1.2.4.win32-py2.5.exe", "has_sig": false, "md5_digest": "3b9db3299eaf31b50187deaae31b9c3b", "packagetype": "bdist_wininst", "python_version": "2.5", "requires_python": null, "size": 637728, "upload_time": "2008-09-15T05:11:33", "url": "https://files.pythonhosted.org/packages/2c/bb/f74af2fe2a7ca01e4f425322c5ceb40e32225ff6451dcef7c1f9b93b399a/P4D%20Langlet-1.2.4.win32-py2.5.exe" } ] }