{ "info": { "author": "Alexander A. Strelets", "author_email": "StreletsAA@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication", "Natural Language :: English", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 2.7", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "This package provides a base class `enumr` for ranged enumerations\nwith reach annotation and formatting capabilities.\n\nIf you are new to this package, study also the `subrange` package as it\nis used here as the class for ranged item instances. Reach annotation\nand formatting capabilities are strongly based on the `subrange` class.\n\nDefine your custom ranged enum as a subclass of `enumr`. Provide item\ndescriptors as described below. Then use class items freely as separate\ninstances of `subrangef` class. Here is a basic example of ranged enum\n(this one does not use reach annotation and formatting)::\n\n from enumr import enumr\n\n class Devices(enumr):\n PRIMARY = 1 # value 1\n SECONDARY = 2\n USER_DEFINED = (3, 10) # subrange 3..10\n RESERVED = (11, 14)\n INVALID = 15\n\n print Devices.USER_DEFINED # 3..10\n print Devices.USER_DEFINED.min # 3\n print Devices.USER_DEFINED.max # 10\n print 7 in Devices.USER_DEFINED # True\n print 11 > Devices.USER_DEFINED # True\n print 2 in Devices.SECONDARY # True\n print 2 == Devices.SECONDARY # True\n print \"0x{:02X}\".format(Devices.RESERVED) # 0x0B..0E\n print \"{0.value} {0.name!r}\".format(Devices.INVALID) # 15 'INVALID'\n\nSee documentation to `subrange` package on which operations are\nsupported by ranged items (that are instances of `subrangef` class).\n\nTo use reach annotation and formatting capabilities add ``_ant_spec``\nand ``_str_spec`` to your subclass definition. This will change the\ndefault formatting of items::\n\n class Devices(enumr):\n _ant_spec = 'brief', 'ref'\n _str_spec = \"{value} {brief!r}\"\n PRIMARY = 1, \"Primary device\", \"sub.10.2.1\"\n USER_DEFINED = (3, 10), \"User defined device\", \"sub.10.2.3\"\n\n print Devices.PRIMARY # 1 'Primary device'\n print Devices.USER_DEFINED # 3..10 'User defined device'\n\n print Devices.PRIMARY.brief # Primary device\n print Devices.PRIMARY.ref # sub.10.2.1\n\n print \"{0.value}: {0.brief!r}\".format(Devices.USER_DEFINED)\n # 3..10: 'User defined device'\n\nHere are some more examples. Call to ``print Devices.USER_DEFINED`` will\nproduce different output depending on ``_str_spec``::\n\n _str_spec = \"0x{value:02X}\" # 0x03..0A\n _str_spec = \"0x{min:02X}-{max:02X}\" # 0x03-0A\n _str_spec = \"{name} = {value}\" # USER_DEFINED = 3..10\n _str_spec = \"{brief!r}\" # 'User defined device'\n\nSee documentation to `enumr` class for more details on how to use reach\nannotation and formatting capabilities.\n\nEnumeration class also provides a facility to resolve arbitrary integer\nvalues to enumeration items::\n\n print Devices(1) # 1 'Primary device'\n print Devices(7) # 3..10 'User defined device'\n print Devices(20, None) # None\n print Devices(20) # raises ValueError: 20 is not in Devices\n\nInteger values are resolved in O(lb(m)) in the worst case, where m is\nthe number of ranged items (i.e., items containing more than one\nvalue), lb(n) is the binary logarithm. If all items in the enum are\nsingle-value ranges, the given integer is resolved in O(1).\n\nThere are different implementations of enum data type in Python. Some of\nthem provide one-to-one relation between items and their values (and\nvalues must be integers), some allow multiple items to have the same\nvalue. Yet they support only one value per an item, but not a range (or\nset) of values.\n\nHowever, in some cases it might be very useful to consolidate a whole\nsubrange of integer values under the same identifier, define a number of\nsuch subranges if needed, and be able to resolve the correct subrange (a\nranged enum item) given an integer value. Such things may be met if we\ntalk about classifiers, decoding tasks, etc. Covering a wide range of\ninteger codes they may have very limited sets of fully defined items and\na number of huge continuous ranges of values under names like\n'user_defined' or 'reserved'. Obviously, if it's not a tiny set of 8-bit\ncodes, it would not be a good idea to put all the 'reserved' codes into\na dictionary to be able to resolve arbitrary code. On the other hand\nconstructing long if-else matchers is error-prone and not elegant (and\nalso they consume O(n) to find the match, where n is the number of\nitems). So, a ready-to-use data structure able to keep ranged enums and\nresolve codes to items might help. And now you have it.", "description_content_type": "", "docs_url": null, "download_url": "https://github.com/xoiss/python-enumr", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/xoiss/python-enumr", "keywords": "", "license": "Public Domain", "maintainer": "", "maintainer_email": "", "name": "enumr", "package_url": "https://pypi.org/project/enumr/", "platform": "Linux", "project_url": "https://pypi.org/project/enumr/", "project_urls": { "Download": "https://github.com/xoiss/python-enumr", "Homepage": "https://github.com/xoiss/python-enumr" }, "release_url": "https://pypi.org/project/enumr/1.0/", "requires_dist": null, "requires_python": "", "summary": "Ranged enumeration data type", "version": "1.0" }, "last_serial": 3911002, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "ec20b14645d977b2436292d3126a15a5", "sha256": "e76572583983069d92c2bece8c6f2ddc48fb2f9952922fbef2163ef574d5d492" }, "downloads": -1, "filename": "enumr-1.0.tar.gz", "has_sig": false, "md5_digest": "ec20b14645d977b2436292d3126a15a5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7179, "upload_time": "2018-05-30T00:35:30", "url": "https://files.pythonhosted.org/packages/ab/cb/c3d0f92e3550c2952c999cd63d1a282d2cb743d71bacc68248c2e97e2ac9/enumr-1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ec20b14645d977b2436292d3126a15a5", "sha256": "e76572583983069d92c2bece8c6f2ddc48fb2f9952922fbef2163ef574d5d492" }, "downloads": -1, "filename": "enumr-1.0.tar.gz", "has_sig": false, "md5_digest": "ec20b14645d977b2436292d3126a15a5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7179, "upload_time": "2018-05-30T00:35:30", "url": "https://files.pythonhosted.org/packages/ab/cb/c3d0f92e3550c2952c999cd63d1a282d2cb743d71bacc68248c2e97e2ac9/enumr-1.0.tar.gz" } ] }