{ "info": { "author": "Malthe Borch and Stefan Eletzhofer", "author_email": "repoze-dev@lists.repoze.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Zope3", "Intended Audience :: Developers", "License :: OSI Approved :: Zope Public License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP" ], "description": "Overview\n========\n\nThe motivation for this package is to encourage the use of request\ntype adaptation instead of depending on packages with request type\ndefinitions.\n\nInstead of subclassing the request interface, we encourage an\nadaptation pattern:\n\n >>> from repoze.bfg.interfaces import IRequest\n >>> IGZipRequest = IRequest({'http_accept_encoding': 'gzip'})\n\nAn event handler listens for the ``INewRequest`` event and\nautomatically marks the request with interfaces as needed to adapt the\nrequest to the request types that it may apply for.\n\nTo complete the example above, a request would come in with an HTTP\nenvironment like the following:\n\n {'http_accept_encoding': 'compress, gzip'}\n\nSince we've previouly adapted the request to an accept-encoding of\n'gzip', the adaptation machinery will mark the interface such that\nthis environment will match the ``IGZipRequest`` interface.\n\nThis would be an alternative to subclassing, where we would manually\nhave to set up an event listener that interprets the request\nenvironment and marks the request with the interface.\n\n >>> class IGZipRequest(IRequest):\n ... \"\"\"Marker interface for requests for gzipped response.\"\"\"\n\nCredits\n-------\n\nStefan Eletzhofer and Malthe Borch\n.\n\n\nAdaptable HTTP request interfaces\n=================================\n\nSuppose we want to adapt on requests that have an \"http_accept_encoding\"\nthat calls for a gzipped response, we'd set up an interface as\nfollows:\n\n >>> from repoze.bfg.interfaces import IRequest\n >>> IGZipRequest = IRequest({'http_accept_encoding': 'gzip'})\n\nLet's now craft a request that will match this interface.\n\n >>> class TestRequest(object):\n ... interface.implements(IRequest)\n ...\n ... def __init__(self, environ):\n ... self.environ = environ\n\n >>> request = TestRequest({'http_accept_encoding': 'compress, gzip'})\n\nAt this point, the request has not been prepared for adaptation.\n\n >>> from repoze.bfg.events import NewRequest\n >>> from zope.event import notify\n >>> notify(NewRequest(request))\n\nWe expect the request to implement the ``IGZipRequest`` interface.\n\n >>> IGZipRequest.providedBy(request)\n True\n\nTo get more flexibility, we can supply a match function:\n \n >>> IAlternativeGZipRequest = IRequest(\n ... {'http_accept_encoding': lambda value: 'gzip' in value})\n\n >>> notify(NewRequest(request))\n >>> IAlternativeGZipRequest.providedBy(request)\n True\n \nSuppose now we'd also like to support requests for documents in\nGerman.\n\n >>> IGermanLanguageRequest = IRequest({'http_accept_language': 'de'})\n\nWe'll create a new request, which, besides asking a gzipped response,\nalso asks for the content in German.\n\n >>> request = TestRequest(\n ... {'http_accept_encoding': 'compress, gzip', 'http_accept_language': 'de'})\n\n >>> notify(NewRequest(request))\n\nVerify that the request provides the adapted interfaces.\n \n >>> IGermanLanguageRequest.providedBy(request)\n True\n\n >>> IGZipRequest.providedBy(request)\n True\n\nNow, as you would expect, we can adapt a request interface that\ncombines these two environments.\n\n >>> IZippedGerman = IRequest(\n ... {'http_accept_encoding': 'gzip', 'http_accept_language': 'de'})\n >>> notify(NewRequest(request))\n \n >>> IZippedGerman.providedBy(request)\n True\n\nNote that this interface extends the two interfaces that were created\nfor each of the environment pairs of it.\n\n >>> IZippedGerman.isOrExtends(IGermanLanguageRequest)\n True\n\n >>> IZippedGerman.isOrExtends(IGZipRequest)\n True\n\nLet's try a request that doesn't match.\n \n >>> IZippedFrench = IRequest(\n ... {'http_accept_encoding': 'gzip', 'http_accept_language': 'fr'})\n >>> notify(NewRequest(request))\n \n >>> IZippedFrench.providedBy(request)\n False\n\nAdapted requests are global with respect to the environment:\n \n >>> IRequest({'http_accept_encoding': 'gzip'}) is IRequest({'http_accept_encoding': 'gzip'})\n True\n \nPickle-support\n--------------\n\nThe adapted interface are created dynamically and would therefore not\nbe locatable by the ``pickle`` module. To remedy this, an import hook\nis added on package initialization.\n\n(The ``repoze.bfg`` packages pickles configuration actions in order to\nimprove startup time, and therefore it's important that the adapted\ninterfaces are pickable.)\n\n >>> from pickle import dumps, loads\n >>> p = dumps(IGZipRequest)\n\nNow, we'll pretend that we the ``repoze.bfg.httprequest.interfaces`` has\nnot yet been imported. This will make pickle import it when we load\nback the pickle.\n\n >>> import sys\n >>> del sys.modules['repozehttprequestinterfaces']\n\nWe'll reinitialize the interfaces module.\n\n >>> loads(p)\n ", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/repoze.bfg.httprequest", "keywords": "zope3 repoze bfg", "license": "ZPL 2.1", "maintainer": null, "maintainer_email": null, "name": "repoze.bfg.httprequest", "package_url": "https://pypi.org/project/repoze.bfg.httprequest/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/repoze.bfg.httprequest/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/repoze.bfg.httprequest" }, "release_url": "https://pypi.org/project/repoze.bfg.httprequest/0.4.2/", "requires_dist": null, "requires_python": null, "summary": "Adaptable request interfaces.", "version": "0.4.2" }, "last_serial": 798793, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "4dabfde0c921a0d3fb2055f54c3de4ba", "sha256": "3ebd60a459853f5813f86a8c09319bf1f854066cdefbe98fcc60fe93c63ffd82" }, "downloads": -1, "filename": "repoze.bfg.httprequest-0.1.tar.gz", "has_sig": false, "md5_digest": "4dabfde0c921a0d3fb2055f54c3de4ba", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4857, "upload_time": "2008-10-01T02:37:58", "url": "https://files.pythonhosted.org/packages/cf/f2/07cffbc3291038f6043f9fa428921b19327933b871deca0bb8e56f694cb5/repoze.bfg.httprequest-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "d70b0c88a7cb22d336284ffe1c8c3207", "sha256": "f62c0c818ad64f9f979394cd8e5c219029879e22eaa17cc6b188287c0b98314f" }, "downloads": -1, "filename": "repoze.bfg.httprequest-0.2.tar.gz", "has_sig": false, "md5_digest": "d70b0c88a7cb22d336284ffe1c8c3207", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5057, "upload_time": "2008-10-03T15:22:26", "url": "https://files.pythonhosted.org/packages/48/11/9d7a8ead88390c80ec96a9d642b08f3650cac9ab2c63d2236abe32a243d0/repoze.bfg.httprequest-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "2c956fa69c0c081a5e25a042e09aa559", "sha256": "c01d7f37258a066bd7819c18023f37cbf8acee57f29714306b770e74ddeee32b" }, "downloads": -1, "filename": "repoze.bfg.httprequest-0.3.tar.gz", "has_sig": false, "md5_digest": "2c956fa69c0c081a5e25a042e09aa559", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6352, "upload_time": "2009-01-28T20:22:14", "url": "https://files.pythonhosted.org/packages/af/3a/597b322408dc76998bec63b9093035b0a67f1eee33d5c982c673bcef4af2/repoze.bfg.httprequest-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "d5d0e2948ee94c3008d3718ae130bf77", "sha256": "0d7b0aded3e8216f6553734dde108d260c556e2d795755504bdccdd7815381c2" }, "downloads": -1, "filename": "repoze.bfg.httprequest-0.4.tar.gz", "has_sig": false, "md5_digest": "d5d0e2948ee94c3008d3718ae130bf77", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6625, "upload_time": "2009-02-10T08:37:36", "url": "https://files.pythonhosted.org/packages/f6/38/0fd907971ad15289d2c9bedfa3ee431294b4a5bbc97541c84f62ee07caee/repoze.bfg.httprequest-0.4.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "fc555655348eafe6530765132e849ba8", "sha256": "68ff0716e84a17b8213927e94eba123b7a8b4e18e84540e0503506ec18aec05b" }, "downloads": -1, "filename": "repoze.bfg.httprequest-0.4.1.tar.gz", "has_sig": false, "md5_digest": "fc555655348eafe6530765132e849ba8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6685, "upload_time": "2009-05-28T19:00:25", "url": "https://files.pythonhosted.org/packages/92/dc/5a437c26f80ae1480967417d105a3ed3c4db78026f52d8c35750f3ada659/repoze.bfg.httprequest-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "1675963f6b9fb03e41bb0374fc059c6e", "sha256": "39cec0977228897ee771092dc81fd094bf2f1f437240b59e6d5cf87e5e280488" }, "downloads": -1, "filename": "repoze.bfg.httprequest-0.4.2.tar.gz", "has_sig": false, "md5_digest": "1675963f6b9fb03e41bb0374fc059c6e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6886, "upload_time": "2009-06-15T09:48:36", "url": "https://files.pythonhosted.org/packages/a4/a5/dd06b2c3596deaf68d1cca1478bae976088281ef031459c50c7c8c3552c5/repoze.bfg.httprequest-0.4.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1675963f6b9fb03e41bb0374fc059c6e", "sha256": "39cec0977228897ee771092dc81fd094bf2f1f437240b59e6d5cf87e5e280488" }, "downloads": -1, "filename": "repoze.bfg.httprequest-0.4.2.tar.gz", "has_sig": false, "md5_digest": "1675963f6b9fb03e41bb0374fc059c6e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6886, "upload_time": "2009-06-15T09:48:36", "url": "https://files.pythonhosted.org/packages/a4/a5/dd06b2c3596deaf68d1cca1478bae976088281ef031459c50c7c8c3552c5/repoze.bfg.httprequest-0.4.2.tar.gz" } ] }