{ "info": { "author": "Alice Bevan-McGregor", "author_email": "alice@gothcandy.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Console", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "===================\nweb.dispatch.object\n===================\n\n \u00a9 2009-2019 Alice Bevan-McGregor and contributors.\n\n..\n\n https://github.com/marrow/web.dispatch.object\n\n..\n\n |latestversion| |ghtag| |downloads| |masterstatus| |mastercover| |masterreq| |ghwatch| |ghstar|\n\n\n\nIntroduction\n============\n\nDispatch is the process of taking some starting point and a path, then resolving the object that path refers to. This\nprocess is common to almost every web application framework (transforming URLs into controllers), RPC system, and even\nfilesystem shell. Other terms for this process include: \"traversal\", \"routing\", or \"lookup\".\n\nObject dispatch is a particular flavour of dispatch that attempts to resolve path elements as a chain of object\nattributes. This is similar to how Python's ``import`` machinery would work, with modules being just another object.\nA simplified analogy for object dispatch would be that of a filesystem, with \"objects\" as directories, and\n\"attributes\" as files.\n\nThis package speaks a standardized `dispatch protocol `_ and\nis not entirely intended for direct use by most developers. The target audience is instead the authors of frameworks\nthat may require such modular dispatch for use by their own users.\n\n\nInstallation\n============\n\nInstalling ``web.dispatch.object`` is easy, just execute the following in a terminal::\n\n pip install web.dispatch.object\n\n**Note:** We *strongly* recommend always using a container, virtualization, or sandboxing environment of some kind when\ndeveloping using Python; installing things system-wide is yucky (for a variety of reasons) nine times out of ten. We\nprefer light-weight `virtualenv `_, others prefer solutions as\nrobust as `Vagrant `_.\n\nIf you add ``web.dispatch.object`` to the ``install_requires`` argument of the call to ``setup()`` in your\napplication's ``setup.py`` file, this dispatcher will be automatically installed and made available when your own\napplication or library is installed. We recommend using \"less than\" version numbers to ensure there are no\nunintentional side-effects when updating. Use ``web.dispatch.object<3.1`` to get all bugfixes for the current release,\nand ``web.dispatch.object<4.0`` to get bugfixes and feature updates while ensuring that large breaking changes are not\ninstalled.\n\n\nDevelopment Version\n-------------------\n\n |developstatus| |developcover| |ghsince| |issuecount| |ghfork|\n\nDevelopment takes place on `GitHub `_ in the \n`web.dispatch.object `_ project. Issue tracking, documentation, and\ndownloads are provided there.\n\nInstalling the current development version requires `Git `_, a distributed source code management\nsystem. If you have Git you can run the following to download and *link* the development version into your Python\nruntime::\n\n git clone https://github.com/marrow/web.dispatch.object.git\n pip install -e 'web.dispatch.object[development]'\n\nYou can then upgrade to the latest version at any time::\n\n (cd web.dispatch.object; git pull; pip install -e .)\n\nIf you would like to make changes and contribute them back to the project, fork the GitHub project, make your changes,\nand submit a pull request. This process is beyond the scope of this documentation; for more information see\n`GitHub's documentation `_.\n\n\nUsage\n=====\n\nThis section is split to cover framework authors who will need to integrate the overall protocol into their systems,\nand the object interactions this form of dispatch provides for end users.\n\n\nFramework Use\n-------------\n\nAt the most basic level, in order to resolve paths against a tree of objects one must first insantiate the dispatcher::\n\n from web.dispatch.object import ObjectDispatch\n\n dispatch = ObjectDispatch() # Opportunity to pass configuration options here.\n\nThe object dispatcher currently only has one configurable option: ``protect``. This defaults to ``True``, and will\nprematurely end dispatch in the event it encounters a path element beginning with an underscore. This protects Python\nmagic attributes (such as ``__name__``), mangled \"private\" methods (such as ``__foo``), and protected-by-convention\nsingle underscore prefixed attributes (such as ``_foo``). Python ordinarily does not enforce such protections,\nexcepting the \"mangling\" feature which is only `security through obscurity `_.\n\nNow that you have a prepared dispatcher, and presuming you have some \"base object\" to start dispatch from, you'll need\nto prepare the path according to the protocol::\n\n path = \"/foo/bar/baz\" # Initial path, i.e. an HTTP request's PATH_INFO.\n path = path.split('/') # Find the path components.\n path = path[1:] # Skip the singular leading slash; see the API specification.\n path = deque(path) # Provide the path as a deque instance, allowing popleft.\n\nOf course, the above is rarely split apart like that. We split apart the invidiual steps of path processing here to\nmore clearly illustrate. In a web framework the above would happen once per request that uses dispatch. This, of\ncourse, frees your framework to use whatever internal or public representation of path you want: choices of\nseparators, and the ability for deque to consume arbitrary iterables. An RPC system might ``split`` on a period and\nsimply not have the possibility of leading separators. Etc.\n\nYou can now call the dispatcher and iterate the dispatch events::\n\n for segment, handler, endpoint, *meta in dispatch(None, some_object, path):\n print(segment, handler, endpoint) # Do something with this information.\n\nThe initial ``None`` value there represents the \"context\" to pass along to initializers of classes encountered during\ndispatch. If the value ``None`` is provided, classes won't be instantiated with any arguments. If a context is\nprovided it will be passed as the first positional argument to instantiation.\n\nAfter completing iteration, check the final ``endpoint``. If it is ``True`` then the path was successfully mapped to\nthe object referenced by the ``handler`` variable, otherwise it represents the deepest object that was able to be\nfound. While some dispatchers might not support partial path resolution and may instead raise ``LookupError`` or a\nsubclass, such as ``AttriuteError`` or ``KeyError``, object dispatch does not do this. This is to allow the framework\nmaking use of object dispatch to decide for itself how to proceed in the event of failed or partial lookup, in a\nsomewhat cleaner way than extensive exception handling within a loop.\n\nIn the context of a web framework, dispatch being an iterable process makes a lot of sense. In the simplest use of\niteration, path elements would be moved from ``PATH_INFO`` to ``SCRIPT_NAME`` as dispatch progresses, or to build up a\n\"bread crumb list\" of accessible controllers.\n\nYou can always just skip straight to the answer if you so choose::\n\n segment, handler, endpoint, *meta = list(dispatch(None, some_object, path))[-1]\n\nHowever, providing some mechanism for callbacks or notifications of dispatch is often far more generally useful.\n\n**Note:** It is entirely permissable for dispatchers to return ``None`` as a processed path segment. Object dispatch\nwill do this to announce the starting point of dispatch. This is especially useful if you need to know if the initial\nobject was a class that was instantiated. (In that event ``handler`` will be an instance of ``some_object`` during\nthe first iteration instead of being literally ``some_object``.) Other dispatchers may return ``None`` at other\ntimes, such as to indicate multiple steps of intermediate processing.\n\nPython 2 & 3 Compatibility\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe dispatch protocol is designed to be extendable in the future by using ``namedtuple`` subclasses, however this has\nan impact on usage as you may have noticed the ``*meta`` in there. This syntax, introduced in Python 3, will gather\nany extraneous tuple elements into a separate list. If you actually care about the metadata do not unpack the tuple\nthis way. Instead::\n\n for meta in dispatch(None, some_object, path):\n segment, handler, endpoint = step[:3] # Unpack, but preserve.\n print(segment, handler, endpoint, meta) # Do something with this information.\n\nThis document is written from the perspective of modern Python 3, and throwing away the metadata within the ``for``\nstatement itself provides more compact examples. The above method of unpacking the first three values is the truly\nportable way to do this across versions.\n\n\nDispatchable Objects\n--------------------\n\nEvery object, of every built-in or third-party class in Python, supports object dispatch. This is because this form\nof dispatch is implemented as a series of basic ``getattr()`` calls happening in a loop. In theory, you can dispatch\nagainst anything. In practice, there are certain expectations and protocols you will have to work within. The first of\nthese notes is extremely important to keep in mind:\n\n* Bare classes are instantiated with zero or one positional argument, depending on the presence of a context.\n* You can override ``getattr()`` by providing a ``__getattr__(self, name)`` method in your object's class.\n* Python has no particular distinction between a \"real\" attribute and one generated by ``__getattr__``, so if\n protection is enabled dispatch would stop and your ``__getattr__`` method would never be called when\n encountering protected path elements.\n* If a callable routine is encountered, it is considered the endpoint regardless of the presence of additional path\n elements. This does not extend to classes with ``__call__`` methods, allowing mixed use in that situation.\n\nWith those elements out of the way, we'll work up from the simplest possible example, a single function::\n\n def hola():\n pass\n\nAny path resolved against a plain function will resolve to that plain function. You can't \"descend\" past any routine;\nthey are, by definition, endpoints. In this instance there will be only a single dispatch event.\n\nA slightly more complex example involves a class with callable instances::\n\n class Thing:\n def __call__(self):\n pass\n\nSimilar to an isolated function, an instance of the ``Thing`` class will be the endpoint for all paths. As a note,\nmore specific attributes are preferred over the instance-level ``__call__``, however an empty path (in this example)\nwill always use the instance as the endpoint, and missing attributes will also use the instance as the endpoint. It is\nup to the framework you are using to determine if this is a problem or not, i.e. to allow unprocessed path elements.\n\nIn the following example::\n\n class Thing:\n class foo:\n def bar(self):\n pass\n\nOnly dispatch to the paths ``/``, ``/foo``, and ``/foo/bar`` will resolve, and only ``/foo/bar`` finds a recognizable\nendpoint. For a somewhat real-world example, the following would successfully represent a database-backed collection\nof things, each with their own set of endpoints::\n\n class Thing:\n def __init__(self, identifier):\n self._thing = identifier # This might look it up from the DB.\n\n def __call__(self):\n pass # Handle direct access to an identified thing.\n\n def action(self):\n pass # This will match any path in the form //action\n\n class Things:\n def __call__(self):\n pass # This will only handle the path /\n\n def __getattr__(self, identifier):\n return Thing(identifier)\n\nBecause there is a ``__getattr__`` method and it does not raise an ``AttributeError`` all first path segments are\nvalid on the ``Things`` class, giving you such paths as::\n\n / - Things.__call__\n /foo - Thing.__call__\n /foo/action - Thing.action\n /bar - Thing.__call__\n /bar/action - Thing.action\n\nEt cetera.\n\n\nVersion History\n===============\n\nVersion 3.0\n-----------\n\n* Python 2 support removed and Python 2 specific code eliminated.\n* Updated to utilize Python 3 namespace packaging. **Critical Note**: This is not compatible with any Marrow package\n that is backwards compatible with Python 2.\n\nVersion 2.1\n-----------\n\n* Massive simplification and conformance to common dispatch protocol.\n\nVersion 2.0\n-----------\n\n* Extract of the object dispatch mechanism from WebCore.\n\nVersion 1.x\n-----------\n\n* Process fully integrated in the WebCore web framework.\n\n\nLicense\n=======\n\nweb.dispatch.object has been released under the MIT Open Source license.\n\nThe MIT License\n---------------\n\nCopyright \u00a9 2009-2019 Alice Bevan-McGregor and contributors.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\ndocumentation files (the \u201cSoftware\u201d), to deal in the Software without restriction, including without limitation the\nrights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit\npersons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the\nSoftware.\n\nTHE SOFTWARE IS PROVIDED \u201cAS IS\u201d, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\nWARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\nOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\n.. |ghwatch| image:: https://img.shields.io/github/watchers/marrow/web.dispatch.object.svg?style=social&label=Watch\n :target: https://github.com/marrow/web.dispatch.object/subscription\n :alt: Subscribe to project activity on Github.\n\n.. |ghstar| image:: https://img.shields.io/github/stars/marrow/web.dispatch.object.svg?style=social&label=Star\n :target: https://github.com/marrow/web.dispatch.object/subscription\n :alt: Star this project on Github.\n\n.. |ghfork| image:: https://img.shields.io/github/forks/marrow/web.dispatch.object.svg?style=social&label=Fork\n :target: https://github.com/marrow/web.dispatch.object/fork\n :alt: Fork this project on Github.\n\n.. |masterstatus| image:: http://img.shields.io/travis/marrow/web.dispatch.object/master.svg?style=flat\n :target: https://travis-ci.org/marrow/web.dispatch.object/branches\n :alt: Release build status.\n\n.. |mastercover| image:: http://img.shields.io/codecov/c/github/marrow/web.dispatch.object/master.svg?style=flat\n :target: https://codecov.io/github/marrow/web.dispatch.object?branch=master\n :alt: Release test coverage.\n\n.. |masterreq| image:: https://img.shields.io/requires/github/marrow/web.dispatch.object.svg\n :target: https://requires.io/github/marrow/web.dispatch.object/requirements/?branch=master\n :alt: Status of release dependencies.\n\n.. |developstatus| image:: http://img.shields.io/travis/marrow/web.dispatch.object/develop.svg?style=flat\n :target: https://travis-ci.org/marrow/web.dispatch.object/branches\n :alt: Development build status.\n\n.. |developcover| image:: http://img.shields.io/codecov/c/github/marrow/web.dispatch.object/develop.svg?style=flat\n :target: https://codecov.io/github/marrow/web.dispatch.object?branch=develop\n :alt: Development test coverage.\n\n.. |developreq| image:: https://img.shields.io/requires/github/marrow/web.dispatch.object.svg\n :target: https://requires.io/github/marrow/web.dispatch.object/requirements/?branch=develop\n :alt: Status of development dependencies.\n\n.. |issuecount| image:: http://img.shields.io/github/issues-raw/marrow/web.dispatch.object.svg?style=flat\n :target: https://github.com/marrow/web.dispatch.object/issues\n :alt: Github Issues\n\n.. |ghsince| image:: https://img.shields.io/github/commits-since/marrow/web.dispatch.object/2.1.0.svg\n :target: https://github.com/marrow/web.dispatch.object/commits/develop\n :alt: Changes since last release.\n\n.. |ghtag| image:: https://img.shields.io/github/tag/marrow/web.dispatch.object.svg\n :target: https://github.com/marrow/web.dispatch.object/tree/2.1.0\n :alt: Latest Github tagged release.\n\n.. |latestversion| image:: http://img.shields.io/pypi/v/web.dispatch.object.svg?style=flat\n :target: https://pypi.python.org/pypi/web.dispatch.object\n :alt: Latest released version.\n\n.. |downloads| image:: http://img.shields.io/pypi/dw/web.dispatch.object.svg?style=flat\n :target: https://pypi.python.org/pypi/web.dispatch.object\n :alt: Downloads per week.\n\n.. |cake| image:: http://img.shields.io/badge/cake-lie-1b87fb.svg?style=flat\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "https://pypi.org/project/web.dispatch.object/releases", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/marrow/web.dispatch.object", "keywords": "marrow,dispatch,web.dispatch,object dispatch,endpoint discovery,WebCore", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "web.dispatch.object", "package_url": "https://pypi.org/project/web.dispatch.object/", "platform": "", "project_url": "https://pypi.org/project/web.dispatch.object/", "project_urls": { "Documentation": "https://github.com/marrow/web.dispatch.object/#readme", "Download": "https://pypi.org/project/web.dispatch.object/releases", "Funding": "https://www.patreon.com/GothAlice", "Homepage": "https://github.com/marrow/web.dispatch.object", "Issue Tracker": "https://github.com/marrow/web.dispatch.object/issues", "Repository": "https://github.com/marrow/web.dispatch.object/" }, "release_url": "https://pypi.org/project/web.dispatch.object/3.0.0/", "requires_dist": [ "web.dispatch (~=3.0.1)", "pytest ; extra == 'development'", "pytest-cov ; extra == 'development'", "pytest-flakes ; extra == 'development'", "pytest-isort ; extra == 'development'", "pre-commit ; extra == 'development'" ], "requires_python": "~=3.6", "summary": "Object dispatch; a method to resolve path components to Python objects using directed attribute access.", "version": "3.0.0" }, "last_serial": 5382743, "releases": { "2.1.0": [ { "comment_text": "", "digests": { "md5": "8c3cd1b6eb3a9f7237056b44ab24a7f0", "sha256": "72e2ad673372585ec242d4dc36ca1b6f30c8b3a4ca71278f7f559f70d9e55407" }, "downloads": -1, "filename": "web.dispatch.object-2.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8c3cd1b6eb3a9f7237056b44ab24a7f0", "packagetype": "bdist_wheel", "python_version": "3.5", "requires_python": null, "size": 19113, "upload_time": "2016-02-15T01:45:53", "url": "https://files.pythonhosted.org/packages/37/48/e87ceaef966ea8a1b11c411cf878ab58a943ee16177e99536f4b1ce635a3/web.dispatch.object-2.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "087d24adb365994d67ff80b9d0f9ac34", "sha256": "91fe3868864ab26bc2eef091b47cb8dd601dab61cfc29a012b0a1baac6b42254" }, "downloads": -1, "filename": "web.dispatch.object-2.1.0-py3.5.egg", "has_sig": false, "md5_digest": "087d24adb365994d67ff80b9d0f9ac34", "packagetype": "bdist_egg", "python_version": "3.5", "requires_python": null, "size": 15744, "upload_time": "2016-02-15T01:45:46", "url": "https://files.pythonhosted.org/packages/c8/a0/707e20d567150aff41495902461e6dad979c390851c9aa9f057ed72b8756/web.dispatch.object-2.1.0-py3.5.egg" }, { "comment_text": "", "digests": { "md5": "2b9a6b1288659751322b36bff1a74e48", "sha256": "e4556ef68f57f3da2cc0dedc48309c1c9280119abbc1626efef4fa2113c6448e" }, "downloads": -1, "filename": "web.dispatch.object-2.1.0.tar.gz", "has_sig": false, "md5_digest": "2b9a6b1288659751322b36bff1a74e48", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18869, "upload_time": "2016-02-15T01:45:41", "url": "https://files.pythonhosted.org/packages/57/05/56a2a48ca8c09192fe724875d4a0610250898ca86e35fa7d24d9afe570d0/web.dispatch.object-2.1.0.tar.gz" } ], "3.0.0": [ { "comment_text": "", "digests": { "md5": "d355d4c3fb2ad19439989827df01cb31", "sha256": "a352e4de0a9cf1e73c1f497344bca773ddacee85bbe974ed1ef21cd19132fdd6" }, "downloads": -1, "filename": "web.dispatch.object-3.0.0-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "d355d4c3fb2ad19439989827df01cb31", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": "~=3.6", "size": 15040, "upload_time": "2019-06-10T17:44:10", "url": "https://files.pythonhosted.org/packages/87/2c/33b9b8fbac472481b4516f905607e63d5c48fc02d945405850846bdd83c2/web.dispatch.object-3.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f73ddc5f738f187237f12b16aa0c424f", "sha256": "a458b09b72cddff2aaf200ba312decb32c83d6618ec5a2c7ff7cfafccf637784" }, "downloads": -1, "filename": "web.dispatch.object-3.0.0.tar.gz", "has_sig": true, "md5_digest": "f73ddc5f738f187237f12b16aa0c424f", "packagetype": "sdist", "python_version": "source", "requires_python": "~=3.6", "size": 20212, "upload_time": "2019-06-10T17:44:11", "url": "https://files.pythonhosted.org/packages/b2/4f/3eed5795a19267d3d3f8c3e60ab46632c527b7a7d00f422d69e6a957a293/web.dispatch.object-3.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d355d4c3fb2ad19439989827df01cb31", "sha256": "a352e4de0a9cf1e73c1f497344bca773ddacee85bbe974ed1ef21cd19132fdd6" }, "downloads": -1, "filename": "web.dispatch.object-3.0.0-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "d355d4c3fb2ad19439989827df01cb31", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": "~=3.6", "size": 15040, "upload_time": "2019-06-10T17:44:10", "url": "https://files.pythonhosted.org/packages/87/2c/33b9b8fbac472481b4516f905607e63d5c48fc02d945405850846bdd83c2/web.dispatch.object-3.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f73ddc5f738f187237f12b16aa0c424f", "sha256": "a458b09b72cddff2aaf200ba312decb32c83d6618ec5a2c7ff7cfafccf637784" }, "downloads": -1, "filename": "web.dispatch.object-3.0.0.tar.gz", "has_sig": true, "md5_digest": "f73ddc5f738f187237f12b16aa0c424f", "packagetype": "sdist", "python_version": "source", "requires_python": "~=3.6", "size": 20212, "upload_time": "2019-06-10T17:44:11", "url": "https://files.pythonhosted.org/packages/b2/4f/3eed5795a19267d3d3f8c3e60ab46632c527b7a7d00f422d69e6a957a293/web.dispatch.object-3.0.0.tar.gz" } ] }