{ "info": { "author": "Johan L\u00fcbcke", "author_email": "johan.lubcke@trioptima.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6" ], "description": ".. image:: https://travis-ci.org/TriOptima/tri.token.svg?branch=master\n :target: https://travis-ci.org/TriOptima/tri.token\n\n\n.. image:: https://codecov.io/github/TriOptima/tri.token/coverage.svg?branch=master\n :target: https://codecov.io/github/TriOptima/tri.token?branch=master\n\n\ntri.token\n=========\n\ntri.token provides enriched enum functionality. tri.token enum structures are declared using:\n\n- TokenAttribute: overridable attribute definitions with support for dynamic values.\n- Token: holds TokenAttributes objects.\n- TokenContainer: holds Token objects.\n\nIn other words: a Token is an enum which has TokenInstance members. Token instances are declared within TokenContainer(s).\n\n\nBasic usage\n-----------\n\n.. code:: python\n\n from tri_token import Token, TokenAttribute, TokenContainer, PRESENT\n\n\n class Taste(Token):\n name = TokenAttribute()\n display_name = TokenAttribute(value=lambda **kwargs: kwargs['name'].upper() + '!!')\n opinion = TokenAttribute()\n\n\n class Tastes(TokenContainer):\n vanilla = Taste()\n pecan_nut = Taste(display_name=\"pecan nutz\", opinion=\"Tasty\")\n\n\n # A TokenContainer is a collection of Token objects.\n assert Tastes.vanilla in Tastes\n\n # The order of Token objects in a TokenContainer is by order of declaration.\n assert list(Tastes) == [Tastes.vanilla, Tastes.pecan_nut]\n assert list(Tastes) != [Tastes.pecan_nut, Tastes.vanilla]\n\n # Magic for 'name' TokenAttribute. It is set automatically from the token declaration within it's container.\n assert Tastes.vanilla.name == \"vanilla\"\n\n # A TokenAttribute will have a None value if not set during Token instantiation.\n assert Tastes.vanilla.opinion is None\n\n # A TokenAttribute can have a dynamic value, derived from the invocation to the callable\n # set as 'value' in the TokenAttribute definition\n # (see declaration of 'display_name' TokenAttribute further up in the code).\n\n # The real value of the token attribute will be the return value of an invocation to said callable.\n # The invocation will receive the values of all other token attributes passed as keyword arguments.\n assert Tastes.vanilla.display_name == \"VANILLA!!\"\n\n # TokenAttribute dynamic value behavior is overridden/not used if value is set explicitly during Token instantiation.\n assert Tastes.pecan_nut.display_name == \"pecan nutz\"\n\n # A TokenContainer can be rendered as csv, excel, rst etc\n assert \"\"\"\\\n +--------------+---------+\n | display_name | opinion |\n +==============+=========+\n | VANILLA!! | |\n +--------------+---------+\n | pecan nutz | Tasty |\n +--------------+---------+\\\n \"\"\" == Tastes.to_rst(['display_name', 'opinion'])\n\n\nOptional token attributes\n-------------------------\n\n.. code:: python\n\n # A TokenAttribute may be declared as having optional dynamic values.\n # That is, we want these dynamic attributes to be evaluated sometimes, but not always.\n # In the example below, we want some superheroes to have homes, but not others.\n\n SUPERHERO_HOMES = {'superman': 'Fortress of Solitude',\n 'batman': 'Batcave'}\n\n\n class Superhero(Token):\n name = TokenAttribute()\n home = TokenAttribute(optional_value=lambda name, **_: SUPERHERO_HOMES[name])\n\n\n # The PRESENT special value is used during Token instantiation to decide what\n # optional token attributes should be evaluated.\n class Superheroes(TokenContainer):\n batman = Superhero(home=PRESENT)\n hawkman = Superhero()\n wonder_woman = Superhero(home='Themyscira')\n\n # Batman has a home, but poor Hawkman does not.\n assert Superheroes.batman.home == 'Batcave'\n assert Superheroes.hawkman.home is None\n\n # Just as with dynamic attributes, the logic for TokenAttribute optional dynamic values is overridden\n if value is set explicitly during Token instantiation.\n assert Superheroes.wonder_woman.home = 'Themyscira'\n\n # As a shortcut, PRESENT for specific optional token attributes may be assigned to\n # variables, and used in declarations, for enhanced readability.\n # This is useful when one has tokens with many attributes declared using dynamic values,\n # but we don't want all of them to be evaluated in all tokens.\n home = PRESENT('home')\n\n class Superheroes(TokenContainer):\n batman = Superhero(home)\n hawkman = Superhero()\n\n # Again, Batman has a home, but poor Hawkman does not.\n assert Superheroes.batman.home == 'Batcave'\n assert Superheroes.hawkman.home is None\n\n\nTokenAttribute inheritance\n--------------------------\n\n.. code:: python\n\n class FooToken(Token):\n foo = TokenAttribute(value=lambda **kwargs: 'foo_value')\n\n class BarToken(Token):\n bar = TokenAttribute()\n\n class FieToken(FooToken, BarToken):\n fie = TokenAttribute()\n\n class FooBarFieTokenContainer(TokenContainer):\n t = FieToken(fie=3)\n\n assert dict(FooBarFieTokenContainer.t) == {'foo': 'foo_value', 'bar': None, 'name': 't', 'fie': 3}\n\n\nTokenAttribute container inheritance\n------------------------------------\n\n.. code:: python\n\n class MyToken(Token):\n\n name = TokenAttribute()\n stuff = TokenAttribute()\n\n\n class MyTokens(TokenContainer):\n\n foo = MyToken(stuff='Hello')\n bar = MyToken(stuff='World')\n\n assert MyTokens.foo in MyTokens\n\n class MoreTokens(MyTokens):\n boink = MyToken(stuff='Other Stuff')\n\n assert MyTokens.foo in MoreTokens\n\n assert list(MoreTokens) == [MyTokens.foo, MyTokens.bar, MoreTokens.boink]\n assert MoreTokens.foo is MyTokens.foo\n\n\nFor more tri.token examples, please have a look at the contents of tests/test_tokens.py in the installation directory.\n\n.. _test_tokens: tests/test_tokens.py\n\n\nRunning tests\n-------------\n\nYou need tox installed then just `make test`.\n\n\nLicense\n-------\n\nBSD\n\n\nDocumentation\n-------------\n\nhttp://tritoken.readthedocs.org.", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/TriOptima/tri.token", "keywords": "tri.token", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "tri.token", "package_url": "https://pypi.org/project/tri.token/", "platform": "", "project_url": "https://pypi.org/project/tri.token/", "project_urls": { "Homepage": "https://github.com/TriOptima/tri.token" }, "release_url": "https://pypi.org/project/tri.token/3.3.0/", "requires_dist": null, "requires_python": "", "summary": "tri.token provides enriched enum functionality", "version": "3.3.0", "yanked": false, "yanked_reason": null }, "last_serial": 9306103, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "a81c97d52febe40797a2ca1dcd570e98", "sha256": "2c00012bb5c281b4b57a2ac075c19cd30a14a81e17baa545fc1d58b95034c0b2" }, "downloads": -1, "filename": "tri.token-1.0.0.tar.gz", "has_sig": false, "md5_digest": "a81c97d52febe40797a2ca1dcd570e98", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8348, "upload_time": "2016-09-27T12:28:47", "upload_time_iso_8601": "2016-09-27T12:28:47.893062Z", "url": "https://files.pythonhosted.org/packages/7b/3c/704d09911532e7ab8db16bd929105dc96c8df313ab4e13989d156f312c51/tri.token-1.0.0.tar.gz", "yanked": false, "yanked_reason": null } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "104e020ff3a3267844a4f743c8276b63", "sha256": "a6c79686745cb80a4eba035a0ed88b908bab4562a12c45af4a700e553a811ee8" }, "downloads": -1, "filename": "tri.token-1.0.1.tar.gz", "has_sig": false, "md5_digest": "104e020ff3a3267844a4f743c8276b63", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9133, "upload_time": "2017-04-12T07:46:28", "upload_time_iso_8601": "2017-04-12T07:46:28.357324Z", "url": "https://files.pythonhosted.org/packages/b8/dc/218192c7213241b9c2165e0c556750b56023e736fc6799e3f24be90ef52f/tri.token-1.0.1.tar.gz", "yanked": false, "yanked_reason": null } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "32b3dc84edb2094134e275d7a6ba7f5b", "sha256": "5e4a170d7fce8a25012558a5b16344ad6ff07358cb9e089fa5cbcd2116a4bfe7" }, "downloads": -1, "filename": "tri.token-1.1.0.tar.gz", "has_sig": false, "md5_digest": "32b3dc84edb2094134e275d7a6ba7f5b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9556, "upload_time": "2018-09-26T08:36:49", "upload_time_iso_8601": "2018-09-26T08:36:49.362785Z", "url": "https://files.pythonhosted.org/packages/9b/71/c8174abe8b38f4f89380214e5cbbf2fd517bec09d214637aaae658aff9f8/tri.token-1.1.0.tar.gz", "yanked": false, "yanked_reason": null } ], "3.0.0": [ { "comment_text": "", "digests": { "md5": "bcca7ea499bfd64d479c02b04dac62af", "sha256": "454eef0072bb722c80be96b40bfef4cd0450dd52224579bd0f3fb8ee1bda3bb0" }, "downloads": -1, "filename": "tri.token-3.0.0.tar.gz", "has_sig": false, "md5_digest": "bcca7ea499bfd64d479c02b04dac62af", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8623, "upload_time": "2019-06-12T13:32:50", "upload_time_iso_8601": "2019-06-12T13:32:50.176980Z", "url": "https://files.pythonhosted.org/packages/d6/8e/32bd9c27e139035af70e4088bec02dfbb072db78d2571aa6f7d02e49f6cf/tri.token-3.0.0.tar.gz", "yanked": false, "yanked_reason": null } ], "3.0.1": [ { "comment_text": "", "digests": { "md5": "66455205d85fb81a8f026b655f8c5e64", "sha256": "d578a706824177a0bff728166f8392b4a9514de1d769383145c8976dab012d49" }, "downloads": -1, "filename": "tri.token-3.0.1.tar.gz", "has_sig": false, "md5_digest": "66455205d85fb81a8f026b655f8c5e64", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8673, "upload_time": "2019-10-10T11:03:51", "upload_time_iso_8601": "2019-10-10T11:03:51.284804Z", "url": "https://files.pythonhosted.org/packages/f3/60/e357325a2c9f4f6287b1700196d89c556e119cf92329a3232c744c39092d/tri.token-3.0.1.tar.gz", "yanked": false, "yanked_reason": null } ], "3.1.0": [ { "comment_text": "", "digests": { "md5": "e279acf9bf5cdbdca6de7b983d3521a8", "sha256": "ad819badbc284581e3f12b7e010d70595bcc6037c7aa8fb0b3a234802cc550fd" }, "downloads": -1, "filename": "tri.token-3.1.0.tar.gz", "has_sig": false, "md5_digest": "e279acf9bf5cdbdca6de7b983d3521a8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8949, "upload_time": "2019-10-15T11:28:25", "upload_time_iso_8601": "2019-10-15T11:28:25.858534Z", "url": "https://files.pythonhosted.org/packages/bf/67/5ecf10c6884791cdfb70d01d9df8bd1a71e48130db12f42ba753dee52311/tri.token-3.1.0.tar.gz", "yanked": false, "yanked_reason": null } ], "3.1.1": [ { "comment_text": "", "digests": { "md5": "31d2c00dcd7555b2dfffa05a7cb31c5c", "sha256": "a42ded215fcf7671485104b3550a95e3e03ef89f2a29d23fc07ac9229dd32d92" }, "downloads": -1, "filename": "tri.token-3.1.1.tar.gz", "has_sig": false, "md5_digest": "31d2c00dcd7555b2dfffa05a7cb31c5c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9067, "upload_time": "2019-10-23T13:39:48", "upload_time_iso_8601": "2019-10-23T13:39:48.017321Z", "url": "https://files.pythonhosted.org/packages/77/3b/2bb60e1cd18661c5023217994fc45fe842dd1d85f710e2eeef7d33a94481/tri.token-3.1.1.tar.gz", "yanked": false, "yanked_reason": null } ], "3.2.0": [ { "comment_text": "", "digests": { "md5": "af4bbe7b8b185647336f6ebc6f56f193", "sha256": "8bdcfa62b80653265cd7a8dc2f7faf3dde4db00fdebfb33f29d9aff70c9727a0" }, "downloads": -1, "filename": "tri.token-3.2.0.tar.gz", "has_sig": false, "md5_digest": "af4bbe7b8b185647336f6ebc6f56f193", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9082, "upload_time": "2020-04-24T09:19:30", "upload_time_iso_8601": "2020-04-24T09:19:30.765998Z", "url": "https://files.pythonhosted.org/packages/83/ab/24b429e559d081c8f2c669151198e10336813ddfca98104a7db5e194d346/tri.token-3.2.0.tar.gz", "yanked": false, "yanked_reason": null } ], "3.3.0": [ { "comment_text": "", "digests": { "md5": "9beceea7d39b8694980d32deea2fbf36", "sha256": "b8f5ec2d918838e081947ce5964e7b6b73aeeeab1355d39dae43707c299205af" }, "downloads": -1, "filename": "tri.token-3.3.0.tar.gz", "has_sig": false, "md5_digest": "9beceea7d39b8694980d32deea2fbf36", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9112, "upload_time": "2021-02-03T13:15:54", "upload_time_iso_8601": "2021-02-03T13:15:54.834491Z", "url": "https://files.pythonhosted.org/packages/10/d6/20054d610b167d5f55a49178730b65b721e8b799c51633714a140c1eff71/tri.token-3.3.0.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9beceea7d39b8694980d32deea2fbf36", "sha256": "b8f5ec2d918838e081947ce5964e7b6b73aeeeab1355d39dae43707c299205af" }, "downloads": -1, "filename": "tri.token-3.3.0.tar.gz", "has_sig": false, "md5_digest": "9beceea7d39b8694980d32deea2fbf36", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9112, "upload_time": "2021-02-03T13:15:54", "upload_time_iso_8601": "2021-02-03T13:15:54.834491Z", "url": "https://files.pythonhosted.org/packages/10/d6/20054d610b167d5f55a49178730b65b721e8b799c51633714a140c1eff71/tri.token-3.3.0.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }