{ "info": { "author": "Patrick Dill", "author_email": "jamespatrickdill@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.0", "Programming Language :: Python :: 3.1", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": "struction\n---------\nPythonic, yet C-Style structs/unions.\n\nStructs are similar to namedtuples, but they allow type assertion and are defined the same way as any class. Creating\na struct is easy.\n\n``$ pip install struction``\n\n.. code-block:: python\n\n from struction import Struct, default, between, clamp\n\n class MyStruct(Struct):\n # any types specified *must* be a class/type\n field_0 = int\n field_1 = str\n\n # you can also allow multiple types\n multi_type = int, str\n\n # and default values!\n with_default = int, default(10)\n\n with_multi_and_default = int, str, default(10)\n\n # it's also possible to set a specific range for fields\n with_range = int, float, between(1, 10) # setting this to a value < 1 or > 10 will raise ValueError\n\n # or, values can be clamped to a range\n with_clamp = int, float, clamp(-5, 5) # setting this to any value outside of range will clamp it\n\n\nOnce a struct is created, it's fields can be changed, but they must match the given type or\na TypeError will be raised. Using ``del`` on a field resets it to its default value.\n\nIt's also possible to nest structs.\nAny structs that are nested will automatically be initialized.\n\n\n.. code-block:: python\n\n class NestMe(Struct):\n field_0 = int\n field_1 = int\n\n\n class Nester(Struct):\n abc = str\n nest = OnlyInt # nested struct\n\n\n.. code-block:: python\n\n >>> print(Nester())\n # Nester {\n # abc = None\n # nest = OnlyInt {\n # field_0 = None\n # field_1 = None\n # }\n # }\n\n >>> print(Nester(nest=None))\n # Nester {\n # abc = None\n # nest = None\n # }\n\nIf you don't want strict types, you can also use a ``TypecastingStruct``. This will attempt to typecast the given value\nto the field's type. If it can't be typecasted, it will then raise a TypeError.\n\n.. code-block:: python\n\n from struction import TypecastingStruct\n\n class Test(TypecastingStruct):\n i = int\n f = float\n s = str\n all = float, int, str\n\n.. code-block:: python\n\n >>> test = Test()\n >>> test.i = 5.3\n >>> test.f = 100\n >>> test.s = {\"a\": 1, \"b\":2}\n >>> print(test)\n # Struct Test {\n # all = None\n # f = 100.0\n # i = 5\n # s = \"{'a': 1, 'b': 2}\"\n # }\n >>> # If multiple types are allowed for a field, the value will be\n >>> # casted to the first type that doesn't throw an Exception\n >>> test.all = (\"a\", 1, \"b\", 2, \"c\", 3)\n >>> test.all\n # '(\"a\", 1, \"b\", 2, \"c\", 3)'\n\n**Note:** Typecasting only works at runtime. The values still need to match their types at class definition.\n\nReference\n---------\nThese can be applied to any Struct class.\n\n- ``Struct.dict()`` : dict with struct's fields. {name: value, ...}\n- ``Struct.fields()`` : list of fields struct has.\n- ``str(Struct)`` : Multi-line representation of struct.\n- ``repr(Struct)`` : Single line representation of struct.", "description_content_type": null, "docs_url": null, "download_url": "http://github.com/reshanie/struction/archive/master.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/reshanie/struction", "keywords": "structs struct datastructure data", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "Struction", "package_url": "https://pypi.org/project/Struction/", "platform": "", "project_url": "https://pypi.org/project/Struction/", "project_urls": { "Download": "http://github.com/reshanie/struction/archive/master.tar.gz", "Homepage": "http://github.com/reshanie/struction" }, "release_url": "https://pypi.org/project/Struction/0.3.0/", "requires_dist": null, "requires_python": "", "summary": "Pythonic, yet C-style structs.", "version": "0.3.0" }, "last_serial": 3126750, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "95bce4172ebc7388eb87c79e60c8a7da", "sha256": "6aa2854a2e1c2313c93e64e040a114a3d9fad17697ddbb92876eb3f1343e6ba4" }, "downloads": -1, "filename": "Struction-0.0.1.tar.gz", "has_sig": false, "md5_digest": "95bce4172ebc7388eb87c79e60c8a7da", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4016, "upload_time": "2017-08-27T00:00:31", "url": "https://files.pythonhosted.org/packages/2e/87/e01e0654178f76f5affefd944a2cde5a1631c9b1fa52a3b58a8d36b845ce/Struction-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "110ca91db2ad696f7f47b0e0e8590eeb", "sha256": "1293ac09dc38aa6ec84a85fe2004edd44b2d868eec53357bce179738eec51f03" }, "downloads": -1, "filename": "Struction-0.0.2.tar.gz", "has_sig": false, "md5_digest": "110ca91db2ad696f7f47b0e0e8590eeb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4035, "upload_time": "2017-08-27T00:05:38", "url": "https://files.pythonhosted.org/packages/39/ba/b8efb66d6dbe9c8f719a02df0cdb39f67a8f40e01c3d6293bceb9af77bed/Struction-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "776b67d2b3e9a00cc1a188d8449d7506", "sha256": "f8713d0b9b21f0c3ea88b07fae1838b10e11e81703e4eb71344715f4eebb19b1" }, "downloads": -1, "filename": "Struction-0.0.3.tar.gz", "has_sig": false, "md5_digest": "776b67d2b3e9a00cc1a188d8449d7506", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4010, "upload_time": "2017-08-27T00:10:18", "url": "https://files.pythonhosted.org/packages/8a/e4/af180ec737369ba70b13ad76aea804ed89a84520f67b9413d0d6bb03965c/Struction-0.0.3.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "b98b39528d876f2dc0c6c3e8a4532448", "sha256": "3f068cdea1cb508531640c71096888ced13415828e1dd121d0a84d23891d0dc1" }, "downloads": -1, "filename": "Struction-0.1.0.tar.gz", "has_sig": false, "md5_digest": "b98b39528d876f2dc0c6c3e8a4532448", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4845, "upload_time": "2017-08-27T02:59:03", "url": "https://files.pythonhosted.org/packages/93/12/1aa7be978ccdb06ddd1f29304447b38df08d2677609d47d0173bd13c9e96/Struction-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "f5c5b3326d6c542d31d1edf8203961cc", "sha256": "9cb5e8ea7654bf1d8c451a721efb367ae7ca7a847a717da064bf1665a63fa24e" }, "downloads": -1, "filename": "Struction-0.2.0.tar.gz", "has_sig": false, "md5_digest": "f5c5b3326d6c542d31d1edf8203961cc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4954, "upload_time": "2017-08-27T05:29:52", "url": "https://files.pythonhosted.org/packages/6c/5a/921cfffdb58d084be51bee9d6616d893bae73758528e0dd1d43f9b47caab/Struction-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "2d64140e9b687a805a91f150166766b4", "sha256": "b6390a0cc1dc09b3fb8cd08bc373bfc83fcb13e395301d56b37c8f0202df21b9" }, "downloads": -1, "filename": "Struction-0.3.0.tar.gz", "has_sig": false, "md5_digest": "2d64140e9b687a805a91f150166766b4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5386, "upload_time": "2017-08-27T17:41:45", "url": "https://files.pythonhosted.org/packages/80/75/044b440ca9454bb191a1cd1f800cf24fe01f0d586419b5390698d08acd6b/Struction-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2d64140e9b687a805a91f150166766b4", "sha256": "b6390a0cc1dc09b3fb8cd08bc373bfc83fcb13e395301d56b37c8f0202df21b9" }, "downloads": -1, "filename": "Struction-0.3.0.tar.gz", "has_sig": false, "md5_digest": "2d64140e9b687a805a91f150166766b4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5386, "upload_time": "2017-08-27T17:41:45", "url": "https://files.pythonhosted.org/packages/80/75/044b440ca9454bb191a1cd1f800cf24fe01f0d586419b5390698d08acd6b/Struction-0.3.0.tar.gz" } ] }