{ "info": { "author": "Alberto Valverde Gonzalez", "author_email": "alberto@toscat.net", "bugtrack_url": null, "classifiers": [], "description": "This module provides four decorators:\n\n ``prioritized_when``\n\n ``prioritized_around``\n\n ``prioritized_before``\n\n ``prioritized_after``\n\nThese behave like their ``peak.rules`` counterparts except that they accept an\noptional ``prio`` argument which can be used to provide a comparable object\n(usually an integer) that will be used to disambiguate\nsituations in which more than rule applies to the given arguments and no rule\nis more specific than another. That is, situations in which an\n``peak.rules.AmbiguousMethods`` would have been raised.\n\nThis is useful for libraries which want to be extensible via generic functions\nbut want their users to easily override a method without figuring out how to\nwrite a more specific rule or when it is not feasible.\n\nFor example, TurboJson provides a ``jsonify`` function that looks like this::\n\n >>> def jsonify(obj):\n ... \"jsonify an object\"\n \n\nAnd extends it so it can handle SqlAlchemy mapped classes in a way\nsimilar to this one::\n\n\n >>> from peak.rules import when\n\n >>> def jsonify_sa(obj):\n ... print \"You're a SA object and I'm going to jsonify you!\"\n\n >>> when(jsonify, \"hasattr(obj, 'c')\")(jsonify_sa) # doctest: +ELLIPSIS\n \n\n >>> class Person(object):\n ... def __init__(self):\n ... self.c = \"im a stub\"\n\n >>> jsonify(Person())\n You're a SA object and I'm going to jsonify you!\n\nSo far so good, however, when a user of the library wants to override the built\nin implementation it can become quite hard since they have to write a more\nspecific rule which can be tedious, for example::\n\n hasattr(self, 'c') and isinstance(obj, Person)\n\nNotice the ``hasattr`` test, even though ``isinstance(obj, Person)`` implies it,\njust to make it more specific than the built in, this gets more cumbersome the\nmore complicated the expression becomes.\n\nElse this is what happens::\n\n >>> def jsonify_Person(obj):\n ... print \"No way, I'm going to jsonify you!\"\n\n >>> when(jsonify, (Person,))(jsonify_Person) # doctest: +ELLIPSIS\n \n\n >>> try:\n ... jsonify(Person())\n ... except AmbiguousMethods:\n ... print \"I told you, gfs can sometimes be a pain\"\n I told you, gfs can sometimes be a pain\n\n\nTo remedy this situation ``prioritized_when`` can be used to provide an\nimplementation that will override the one declared with ``when``::\n\n >>> def jsonify_Person2(obj):\n ... print \"No way, I'm going to jsonify you!\"\n\n >>> prioritized_when(jsonify, (Person,))(jsonify_Person2) # doctest: +ELLIPSIS\n \n\n >>> jsonify(Person())\n No way, I'm going to jsonify you!\n\nNotice that we didn't need a ``prio`` argument. This is because methods\ndecorated with ``prioritized_when`` always override those that have been\ndecorated with ``peak.rules.when``.\n\nMethods decorated with ``prioritized_when`` can also override other methods\nthat have been decorated by the same decorator using the ``prio`` parameter,\nthe one which compares greater wins, if both are equal\n``AmbiguousMethods`` will be raised as usual.\n\n >>> def jsonify_Person3(obj):\n ... print \"Don't be so smart, I am, my prio is higher!\"\n\n >>> prioritized_when(jsonify, (Person,), prio=1)(jsonify_Person3) # doctest: +ELLIPSIS\n \n\n >>> jsonify(Person())\n Don't be so smart, I am, my prio is higher!\n\nFor convenience, a ``generic`` decorator is provided too which behaves\nlike ``peak.rules.dispatch.generic`` except that the ``when``,...,``after``\ndecorators that will be bound as attributes of the decorated function will be\nprioritized::\n\n >>> @generic\n ... def f(n): pass\n\n >>> f(5)\n Traceback (most recent call last):\n ...\n NoApplicableMethods: ((5,), {})\n \nAdd a default rule::\n\n >>> @f.when()\n ... def default_f(n):\n ... return n\n >>> f(5)\n 5\n\nAdd a default rule that overrides the former::\n\n >>> @f.when(prio=1)\n ... def new_default_f(n):\n ... return n+1\n >>> f(5)\n 6", "description_content_type": null, "docs_url": null, "download_url": "http://toscawidgets.org/download", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": "PEAK rules generic functions dispatch", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "prioritized_methods", "package_url": "https://pypi.org/project/prioritized_methods/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/prioritized_methods/", "project_urls": { "Download": "http://toscawidgets.org/download", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/prioritized_methods/0.2.1/", "requires_dist": null, "requires_python": null, "summary": "An extension to PEAK-Rules to prioritize methods in order to to avoid AmbiguousMethods situations", "version": "0.2.1" }, "last_serial": 796701, "releases": { "0.1.2": [ { "comment_text": "", "digests": { "md5": "28166e365450194b95407aac81791fbd", "sha256": "11a0c47796d05e3636510f97fe9d28efe627a7ef05c64ea431049b415332ba8c" }, "downloads": -1, "filename": "prioritized_methods-0.1.2-py2.5.egg", "has_sig": false, "md5_digest": "28166e365450194b95407aac81791fbd", "packagetype": "bdist_egg", "python_version": "2.5", "requires_python": null, "size": 7388, "upload_time": "2008-07-09T10:34:47", "url": "https://files.pythonhosted.org/packages/bc/b2/c48d92b93665d15359a8c6c968a23dd5e4b7e804ddf25d25c728f1bd0d79/prioritized_methods-0.1.2-py2.5.egg" }, { "comment_text": "", "digests": { "md5": "1ed6f94e588a1e4f7a52e02dfaea05fb", "sha256": "40ce0661214a6bfce49178c908cc4c30a93cb29adf7dd32bd822ae152780c2fb" }, "downloads": -1, "filename": "prioritized_methods-0.1.2.tar.gz", "has_sig": false, "md5_digest": "1ed6f94e588a1e4f7a52e02dfaea05fb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3571, "upload_time": "2008-07-09T10:34:47", "url": "https://files.pythonhosted.org/packages/9a/8f/fa1a60b2adf9fc0bd63cfbd2f6114486e36c8ab22a39c19e7fad7bdad0b6/prioritized_methods-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "58d693975dd1115b3f48e43a1d26b86c", "sha256": "e05f660e9168a6165f14e11678666af585cfccd6fb00b1784b09b44706ef51a8" }, "downloads": -1, "filename": "prioritized_methods-0.1.3-py2.5.egg", "has_sig": false, "md5_digest": "58d693975dd1115b3f48e43a1d26b86c", "packagetype": "bdist_egg", "python_version": "2.5", "requires_python": null, "size": 8347, "upload_time": "2008-07-10T09:44:26", "url": "https://files.pythonhosted.org/packages/7d/7a/ca4bc6db0560e49495a32738498e6be0ae91506508c7ff58a491a93505f3/prioritized_methods-0.1.3-py2.5.egg" }, { "comment_text": "", "digests": { "md5": "3217d86b952bc2245a0bc750d8ea9952", "sha256": "3e28929f1729bc26fd40de35d0464721ab217718db4586c8c1147243c82dcd1f" }, "downloads": -1, "filename": "prioritized_methods-0.1.3.tar.gz", "has_sig": false, "md5_digest": "3217d86b952bc2245a0bc750d8ea9952", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4007, "upload_time": "2008-07-10T09:44:26", "url": "https://files.pythonhosted.org/packages/24/6a/c061d306623d641b07669aa916e17666906259475f90f835457e8633a56d/prioritized_methods-0.1.3.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "a4a0d832837e5f4aba0e6bfd050b5bac", "sha256": "ef0091839a8e23ae03f4e618d5cb5c4251b7c88a1713e41513d0569e5d775af7" }, "downloads": -1, "filename": "prioritized_methods-0.2-py2.5.egg", "has_sig": false, "md5_digest": "a4a0d832837e5f4aba0e6bfd050b5bac", "packagetype": "bdist_egg", "python_version": "2.5", "requires_python": null, "size": 9658, "upload_time": "2008-07-11T07:09:56", "url": "https://files.pythonhosted.org/packages/52/68/4cfd1201d585d653f87c503c1a03f2e243bdfb6998ee7d34dcecce3e4497/prioritized_methods-0.2-py2.5.egg" }, { "comment_text": "", "digests": { "md5": "82dad188b123a713bb111af62d5e5e19", "sha256": "2026aa2c3ccb52e7e3aec08b0439ac549d42076ca50664c47fd850c707fab6bf" }, "downloads": -1, "filename": "prioritized_methods-0.2.tar.gz", "has_sig": false, "md5_digest": "82dad188b123a713bb111af62d5e5e19", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4620, "upload_time": "2008-07-11T07:09:55", "url": "https://files.pythonhosted.org/packages/f4/99/2811df8e69198ab1eb1a5db845a83a1092b77495a79bcad1f48824b29fdc/prioritized_methods-0.2.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "1a88e79d320796108c42dd01a0037b18", "sha256": "d94f1545c4896f01ccf2b5004deb1beed721fa4afa64e52b8ae548b79bc6f1d5" }, "downloads": -1, "filename": "prioritized_methods-0.2.1-py2.5.egg", "has_sig": false, "md5_digest": "1a88e79d320796108c42dd01a0037b18", "packagetype": "bdist_egg", "python_version": "2.5", "requires_python": null, "size": 9801, "upload_time": "2008-08-17T18:53:50", "url": "https://files.pythonhosted.org/packages/79/e5/a7322c099953a7d0d35ec761f1d71d6c79b5c29f41c39dee8cc2cf51ac6f/prioritized_methods-0.2.1-py2.5.egg" }, { "comment_text": "", "digests": { "md5": "1e9d9de02291b0fc27942b48c170ddc3", "sha256": "931da40e1ba53c6d35312371b3c84573f1a5297a0ee6a78584a2337d0180b63c" }, "downloads": -1, "filename": "prioritized_methods-0.2.1.tar.gz", "has_sig": false, "md5_digest": "1e9d9de02291b0fc27942b48c170ddc3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4684, "upload_time": "2008-08-17T18:53:51", "url": "https://files.pythonhosted.org/packages/e4/97/ffc61ba866fc7b3d2da41793bb98dc4e59665e060948d4d67dc944983a0c/prioritized_methods-0.2.1.tar.gz" } ], "0.2.2dev-20110830": [ { "comment_text": "", "digests": { "md5": "b445af0be1ab634acb965e804a927b0f", "sha256": "704874b906514fe07680b7151620338bd03af0a901f027eb343d7ce535bfca54" }, "downloads": -1, "filename": "prioritized_methods-0.2.2dev-20110830.tar.gz", "has_sig": false, "md5_digest": "b445af0be1ab634acb965e804a927b0f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4755, "upload_time": "2011-08-30T12:25:23", "url": "https://files.pythonhosted.org/packages/cf/8e/0857d615deaa4e29002568c48af34058d3f3324517ae7edf1f7014c97434/prioritized_methods-0.2.2dev-20110830.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1a88e79d320796108c42dd01a0037b18", "sha256": "d94f1545c4896f01ccf2b5004deb1beed721fa4afa64e52b8ae548b79bc6f1d5" }, "downloads": -1, "filename": "prioritized_methods-0.2.1-py2.5.egg", "has_sig": false, "md5_digest": "1a88e79d320796108c42dd01a0037b18", "packagetype": "bdist_egg", "python_version": "2.5", "requires_python": null, "size": 9801, "upload_time": "2008-08-17T18:53:50", "url": "https://files.pythonhosted.org/packages/79/e5/a7322c099953a7d0d35ec761f1d71d6c79b5c29f41c39dee8cc2cf51ac6f/prioritized_methods-0.2.1-py2.5.egg" }, { "comment_text": "", "digests": { "md5": "1e9d9de02291b0fc27942b48c170ddc3", "sha256": "931da40e1ba53c6d35312371b3c84573f1a5297a0ee6a78584a2337d0180b63c" }, "downloads": -1, "filename": "prioritized_methods-0.2.1.tar.gz", "has_sig": false, "md5_digest": "1e9d9de02291b0fc27942b48c170ddc3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4684, "upload_time": "2008-08-17T18:53:51", "url": "https://files.pythonhosted.org/packages/e4/97/ffc61ba866fc7b3d2da41793bb98dc4e59665e060948d4d67dc944983a0c/prioritized_methods-0.2.1.tar.gz" } ] }