{ "info": { "author": "Ryan Northey", "author_email": "ryan@3ca.org.uk", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Programming Language :: Python :: 3.4", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Detailed documentation\n**********************\n\naio.web.page\n============\n\nWeb page templates for the aio_ asyncio framework\n\n.. _aio: https://github.com/phlax/aio\n\n\n\nBuild status\n------------\n\n.. image:: https://travis-ci.org/phlax/aio.web.page.svg?branch=master\n\t :target: https://travis-ci.org/phlax/aio.web.page\n\n\nInstallation\n------------\n\nRequires python >= 3.4\n\nInstall with:\n\n.. code:: bash\n\n\t pip install aio.web.page\n\n\nQuick start - hello world web page\n----------------------------------\n\nSave the following into a file \"hello.conf\"\n\n.. code:: ini\n\n\t [aio]\n\t modules = aio.web.server\n\n\t [server/my_server]\n\t factory = aio.web.server.factory\n\t port = 8080\n\n\t [web/my_server]\n\t template_dirs = templates\n\t \n\t [web/my_server/my_route]\n\t match = /\n\t route = my_example.route_handler\n\n\nAnd save the following into a file named \"my_example.py\"\n\n.. code:: python\n\n\t import aio.web.page\t \n\t import aio.web.server\n\n\t @aio.web.page.template('example_page.html')\n\t def template_handler(request):\n\t return {\"message\": \"Hello template world\"}\t \n\t \n\t @aio.web.server.route\n\t def route_handler(request, config):\n\t return (yield from template_handler(request))\n\n\nAnd the following into a file named \"templates/example_page.html\"\n\n.. code:: html\n\t \n\t \n\t \n\t {{ message }}\n\t \n\t \n\t \nRun with the aio run command\n\n.. code:: bash\n\n\t aio run -c hello.conf\n\n\n\naio.web.page usage\n------------------\n\naio.web.page provides templates and fragments for building web pages\n\nLets set up a test to run a server and request a web page\n\n>>> from aio.app.runner import runner \n>>> import aio.testing\n>>> import aiohttp \n\n>>> @aio.testing.run_forever(sleep=1)\n... def run_web_server(config, request_page=\"http://localhost:7070\"):\n... yield from runner(['run'], config_string=config)\n... \n... def call_web_server():\n... result = yield from (\n... yield from aiohttp.request(\n... \"GET\", request_page)).read()\n... aio.web.server.clear()\n... \n... print(result.decode())\n... \n... return call_web_server\n\n\nTemplates\n---------\n \nAn @aio.web.server.route handler can defer to other templates, for example according to the matched path.\n\n>>> example_config = \"\"\"\n... [aio]\n... log_level = CRITICAL\n... modules = aio.web.server\n... aio.web.server.tests \n... \n... [server/server_name]\n... factory: aio.web.server.factory\n... port: 7070\n... \n... [web/server_name/route_name]\n... match = /{path:.*}\n... route = aio.web.page.tests._example_route_handler\n... \"\"\"\n\nLets create a couple of template handlers\n\n>>> import aio.web.page\n\n>>> @aio.web.page.template(\"test_template.html\") \n... def template_handler_1(request): \n... return {\n... 'message': \"Hello, world from template handler 1\"}\n\nTemplate handlers can return a response object, in which case the template is not rendered\n \n>>> @aio.web.page.template(\"test_template.html\")\n... def template_handler_2(request):\n... return aiohttp.web.Response(\n... body=b\"Hello, world from template handler 2\")\n\n\nAnd lets set up a route handler which will defer to a template accordingly\n\n>>> import aio.web.server\n\n>>> @aio.web.server.route\n... def route_handler(request, config):\n... path = request.match_info['path']\n... \n... if path == \"path1\":\n... return (yield from template_handler_1(request))\n... \n... elif path == \"path2\":\n... return (yield from template_handler_2(request))\n... \n... raise aiohttp.web.HTTPNotFound\n\nAnd make it importable\n \n>>> import aio.web.page.tests\n>>> aio.web.page.tests._example_route_handler = route_handler\n\nCalling the server at /path1 we get the templated handler\n \n>>> run_web_server(\n... example_config,\n... request_page=\"http://localhost:7070/path1\") \n\n \n Hello, world from template handler 1\n \n\n\nAnd calling on /path2 we get the response without the template\n \n>>> run_web_server(\n... example_config,\n... request_page=\"http://localhost:7070/path2\") \nHello, world from template handler 2\n\n\nTemplates must always specify a template, even if they dont use it\n\n>>> try:\n... @aio.web.page.template\n... def template_handler(request, test_list): \n... return {'test_list': test_list}\n... except Exception as e:\n... print(repr(e))\nTypeError('Template decorator must specify template: ',)\n\nTemplates can take arbitrary arguments\n\n>>> @aio.web.page.template(\"test_template.html\") \n... def template_handler(request, foo, bar): \n... return {\n... 'message': \"Hello, world with %s and %s\" % (foo, bar)}\n\n>>> @aio.web.server.route\n... def route_handler(request, config):\n... return (yield from(template_handler(request, \"spam\", \"tuesday\")))\n>>> aio.web.page.tests._example_route_handler = route_handler\n\n>>> run_web_server(example_config)\n\n \n Hello, world with spam and tuesday\n \n\n\nThe first argument to a template should always be a request object\n\n>>> @aio.web.page.template(\"test_template.html\") \n... def template_handler(foo, bar): \n... return {\n... 'message': \"Hello, world with %s and %s\" % (foo, bar)}\n\n>>> @aio.web.server.route\n... def route_handler(request, config):\n... try:\n... return (yield from(template_handler(\"spam\", \"tuesday\")))\n... except TypeError as e:\n... return aiohttp.web.Response(body=repr(e).encode())\n>>> aio.web.page.tests._example_route_handler = route_handler\n\n>>> run_web_server(example_config)\nTypeError(\"Template handler () should be called with a request object, got: spam\",)\n\n\nFragments\n---------\n\nFragments render a snippet of html for embedding in other templates.\n\nFragments can specify a template and return a context object to render it with\n\nA fragment can take an arbitrary number of arguments\n\n>>> @aio.web.page.fragment(\"fragments/test_fragment.html\")\n... def fragment_handler(request, foo, bar):\n... return {\"test_list\": [foo, bar]}\n\n>>> @aio.web.page.template(\"test_template.html\") \n... def template_handler(request):\n... return {'message': (yield from fragment_handler(request, \"eggs\", \"thursday\"))}\n\n>>> @aio.web.server.route\n... def route_handler(request, config):\n... return (yield from(template_handler(request)))\n>>> aio.web.page.tests._example_route_handler = route_handler\n\n>>> run_web_server(example_config)\n\n \n
    \n
  • eggs
  • thursday
  • \n
\n \n\n\nThe first argument to a fragment should always be an aiohttp.web.Request object\n\n>>> @aio.web.page.fragment(\"fragments/test_fragment.html\")\n... def fragment_handler(foo, bar):\n... return {\"test_list\": [foo, bar]}\n\n>>> @aio.web.page.template(\"test_template.html\") \n... def template_handler(request):\n... try:\n... message = (yield from(fragment_handler(\"eggs\", \"thursday\")))\n... except Exception as e:\n... message = repr(e)\n... return {'message': message}\n\n>>> @aio.web.server.route\n... def route_handler(request, config):\n... return (yield from(template_handler(request)))\n>>> aio.web.page.tests._example_route_handler = route_handler\n\n>>> run_web_server(example_config)\n\n \n TypeError(\"Fragment handler () should be called with a request object, got: eggs\",)\n \n\n\n\nFragments do not need to specify a template\n\n>>> @aio.web.page.fragment\n... def fragment_handler(request):\n... return \"Hello from fragment\"\n\n>>> @aio.web.page.template(\"test_template.html\") \n... def template_handler(request):\n... return {'message': (yield from fragment_handler(request))} \n\n>>> @aio.web.server.route\n... def route_handler(request, config):\n... return (yield from(template_handler(request)))\n>>> aio.web.page.tests._example_route_handler = route_handler\n\n>>> run_web_server(example_config)\n\n \n Hello from fragment\n \n\n\nIf a fragment doesnt specify a template, it must return a string\n\n>>> @aio.web.page.fragment\n... def fragment_handler(request):\n... return {\"foo\": \"bar\"}\n\n>>> @aio.web.page.template(\"test_template.html\") \n... def template_handler(request):\n... try:\n... fragment = yield from fragment_handler(request)\n... except Exception as e:\n... fragment = repr(e)\n... return {'message': fragment}\n\n>>> @aio.web.server.route\n... def route_handler(request, config):\n... return (yield from(template_handler(request)))\n>>> aio.web.page.tests._example_route_handler = route_handler\n\n>>> run_web_server(example_config)\n\n \n TypeError('Fragment handler () should specify a template or return a string',)\n \n\n\nFragments should only return strings or context dictionaries, and should not return an aiohttp.web.Response object.\n\n>>> @aio.web.page.fragment(\"fragments/test_fragment.html\")\n... def fragment_handler(request):\n... return aiohttp.web.Response(body=b\"Fragments should not return Response objects\")\n\n>>> @aio.web.page.template(\"test_template.html\") \n... def template_handler(request):\n... try:\n... fragment = yield from fragment_handler(request)\n... except Exception as e:\n... fragment = repr(e)\n... return {'message': fragment}\n\n>>> @aio.web.server.route\n... def route_handler(request, config):\n... return (yield from(template_handler(request)))\n>>> aio.web.page.tests._example_route_handler = route_handler\n\n>>> run_web_server(example_config)\n\n \n TypeError(\"Fragment handler () should return a string or context dictionary, got: \",)\n \n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/phlax/aio.web.page", "keywords": "", "license": "GPL", "maintainer": null, "maintainer_email": null, "name": "aio.web.page", "package_url": "https://pypi.org/project/aio.web.page/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/aio.web.page/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/phlax/aio.web.page" }, "release_url": "https://pypi.org/project/aio.web.page/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "Web page templates for the aio asyncio framework", "version": "0.1.0" }, "last_serial": 1560703, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "6a39237648d0dc2451a7ca5f9d37fe89", "sha256": "9ebab8a1d9013ec29b41fcccc5b0c64844c14b1d96f168624d0c15eb5d71cb11" }, "downloads": -1, "filename": "aio.web.page-0.0.1.tar.gz", "has_sig": false, "md5_digest": "6a39237648d0dc2451a7ca5f9d37fe89", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4480, "upload_time": "2015-05-23T19:27:40", "url": "https://files.pythonhosted.org/packages/39/47/7bf02a569e0946cb8c441931fbb0a4b8ce6361d0f1217ff103449c59649c/aio.web.page-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "e3d34e05b0778aa4d2e72cf5a27b9bad", "sha256": "9d6642b0bf27fd5500be73729b61cb9e9df2169e21030a6c23421d170ff526d9" }, "downloads": -1, "filename": "aio.web.page-0.0.2.tar.gz", "has_sig": false, "md5_digest": "e3d34e05b0778aa4d2e72cf5a27b9bad", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4480, "upload_time": "2015-05-23T21:11:49", "url": "https://files.pythonhosted.org/packages/94/4a/ba34ac6381d2f6c6f38efdb247b5eb81b626f23a1ea21b404fe23c3f9c71/aio.web.page-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "7aecba8f252ea5b7227645990e8ca78a", "sha256": "83bf5f1f188818555aebe6515e149e6b727202cf29f3da3ac36c627dd73d0199" }, "downloads": -1, "filename": "aio.web.page-0.0.3.tar.gz", "has_sig": false, "md5_digest": "7aecba8f252ea5b7227645990e8ca78a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5991, "upload_time": "2015-05-23T21:31:33", "url": "https://files.pythonhosted.org/packages/16/83/60b65138f0d8ac842d2d03faaa910157d20310caa220a2498046063f29cc/aio.web.page-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "d72d8b35c6d1372d657a483083c2b690", "sha256": "16f7e628865d3f0e3e8b785e9e024775e219cfde342a8abadc30d8bd6dde5d06" }, "downloads": -1, "filename": "aio.web.page-0.0.4.tar.gz", "has_sig": false, "md5_digest": "d72d8b35c6d1372d657a483083c2b690", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5964, "upload_time": "2015-05-23T22:42:00", "url": "https://files.pythonhosted.org/packages/a3/a9/1bf6442e69a04cc62bcbc922633e319c9e5202e9d2be49d70ebaf5eb408c/aio.web.page-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "82afcfede165bf27205bb77299cf4da0", "sha256": "ed5f682fc92830f22e21be968f5d7e42bf82950f2da3f56a6fd7ff2985c2a7c8" }, "downloads": -1, "filename": "aio.web.page-0.0.5.tar.gz", "has_sig": false, "md5_digest": "82afcfede165bf27205bb77299cf4da0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6407, "upload_time": "2015-05-24T00:01:50", "url": "https://files.pythonhosted.org/packages/b6/c8/8257f5e1408cc7547eeaf3b826875d8cff358310a7523f25b07c0cf9a33b/aio.web.page-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "d36fb9f5b1571652637b35f3d3d76cd2", "sha256": "1190c3973bfc1a5e38066aa305e4f3f9c7edfecbbc5a9414ce6a7c649bac33ac" }, "downloads": -1, "filename": "aio.web.page-0.0.6.tar.gz", "has_sig": false, "md5_digest": "d36fb9f5b1571652637b35f3d3d76cd2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6445, "upload_time": "2015-05-24T03:24:19", "url": "https://files.pythonhosted.org/packages/35/97/334f507aeb202160d1ea2a70aa86a5257e4a316bd8706452af55e2b3a5d9/aio.web.page-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "398e226b81d50abda242679b909a5938", "sha256": "2da7b39299c2b5e7a3b4da4de293e1f291eb3aa14fde0192ed370d5a4f5bb332" }, "downloads": -1, "filename": "aio.web.page-0.0.7.tar.gz", "has_sig": false, "md5_digest": "398e226b81d50abda242679b909a5938", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7413, "upload_time": "2015-05-24T13:20:31", "url": "https://files.pythonhosted.org/packages/6a/94/fa2623f516a7ec6d0355d6ee7f9a98577a27e0a4c12c68980cd8f359338b/aio.web.page-0.0.7.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "2b498a3e3bae317198e0895bf9edc039", "sha256": "b44ea633143d6eccf30c446a0cb390cdc2af6b5d60ddf72ab061a63e2739899d" }, "downloads": -1, "filename": "aio.web.page-0.1.0.tar.gz", "has_sig": false, "md5_digest": "2b498a3e3bae317198e0895bf9edc039", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7404, "upload_time": "2015-05-24T21:42:48", "url": "https://files.pythonhosted.org/packages/4d/e5/c7caee4398b8d4dbb668a20ccf8476da5b607399138fb7fe36cfec5d4b42/aio.web.page-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2b498a3e3bae317198e0895bf9edc039", "sha256": "b44ea633143d6eccf30c446a0cb390cdc2af6b5d60ddf72ab061a63e2739899d" }, "downloads": -1, "filename": "aio.web.page-0.1.0.tar.gz", "has_sig": false, "md5_digest": "2b498a3e3bae317198e0895bf9edc039", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7404, "upload_time": "2015-05-24T21:42:48", "url": "https://files.pythonhosted.org/packages/4d/e5/c7caee4398b8d4dbb668a20ccf8476da5b607399138fb7fe36cfec5d4b42/aio.web.page-0.1.0.tar.gz" } ] }