{ "info": { "author": "Hiroki Kiyohara", "author_email": "hirokiky@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "=========\nwraptools\n=========\n\nUtilities for wrapping and dispatching functions.\n\nSupported Python versions:\n\n* 2.7\n* 3.4\n* 3.5\n\npluggable\n=========\n\n``pluggable`` will take some decorators and simply apply it.\nBut applied decorators can be purged by ``purge_pluggable_decorators``.\n\n.. code-block:: python\n\n from functools import lru_cache\n from wraptools.pluggable import pluggable\n\n @pluggable(\n lru_cache,\n )\n def get_data():\n \"\"\" Some function return data from RDB or so. \"\"\"\n\n``purge_pluggable_decorators`` is useful on tests.\n\n.. code-block:: python\n\n from wraptools.pluggable import purge_pluggable_decorators\n\n @purge_pluggable_decorators\n def test__get_data(self):\n always_flesh_data = get_data()\n\nOr it can be also used as a context manager.\n\n.. code-block:: python\n\n with purge_pluggable_decorators():\n always_flesh_data = get_data()\n\n``pluggable`` decorator can be useful for view functions of Web Frameworks,\nlike Django.\n\n.. code-block:: python\n\n @pluggable(\n login_required,\n )\n def profile_view(request):\n return TemplateResponse(request, \"profile.html\")\n\ndispatch\n========\n\n``dispatch`` will create function by some condition and functions.\nFollowing example means\n\n* When request is authenticated, ``dashboard`` function will be called.\n* Other cases, ``landing_page`` function will be called.\n\n.. code-block:: python\n\n from wraptools.dispatch import dispatch\n from wraptools.contrib.django.dispatchers import is_authenticated\n\n\n def landing_page(request):\n return TemplateResponse(request, \"landing.html\")\n\n\n def dashboard(request):\n return TemplateResponse(request, \"dashboard.html\")\n\n\n top_view = dispatch(\n (is_authenticated, dashboard),\n default=landing_page,\n )\n\nCombine conditions\n------------------\n\nIn this case ``dispatch`` is used for Django's view, but it can be used\ngeneric Python functions.\n\n``dispatcher`` functions can be combined and inverted.\n\n* To create ``and`` condition, just combine dispatchers by ``&``\n* ``or`` condition, by ``|``\n* ``not`` condition, by ``~``\n\n.. code-block:: python\n\n from wraptools.contrib.django.dispatchers import is_authenticated, method_get\n\n top = dispatch(\n (is_authenticated & method_get, dashboard_get),\n (is_authenticated & (method_post | method_put), dashboard_post),\n (~is_authenticated, landing),\n )\n\nCreate own dispatcher\n---------------------\n\nBasically dispatcher is just a function to get same arguments with dispatched functions\nand return bool values.\n\n.. code-block:: python\n\n def is_even(num):\n return num % 2 == 0\n\n def echo(num):\n return num\n\n dispatch(\n (is_even, echo),\n ...\n )\n\nBut by using ``dispatcher`` decorator, your dispatcher functions\nwill be able to be combined and inverted by ``&``, ``|``, or ``~``\n\n.. code-block:: python\n\n from wraptools.dispatch import dispatcher\n\n dispatcher\n def is_even(num):\n return num % 2 == 0\n\n dispatch(\n (~is_even, ...), # It will be called when the value is odd (not even).\n ...\n )\n\n\ncontext\n=======\n\n``context`` is a decorator which injects additional arguments to wrapped functions.\nFollowing example is to separate logic to get user object into ``get_user`` context function,\nand applying it for ``profile_page`` view by ``context`` decorator.\n\n.. code-block:: python\n\n from wraptools.context import context\n\n\n def get_user(user_id):\n return get_object_or_404(User, id=user_id)\n\n\n @context(\n get_user,\n )\n def profile_page(request, user_id, user):\n return TemplateResponse(request, \"profile.html\")", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/hirokiky/wraptools/", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "wraptools", "package_url": "https://pypi.org/project/wraptools/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/wraptools/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/hirokiky/wraptools/" }, "release_url": "https://pypi.org/project/wraptools/1.1/", "requires_dist": null, "requires_python": null, "summary": "Utilities for wrapping and dispatching functions", "version": "1.1" }, "last_serial": 2448603, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "7c01962060112c99607ceda662886497", "sha256": "646f7c339a4cd97c14e5f7f9c6ac87adb17911b6652b716525949649c59f7342" }, "downloads": -1, "filename": "wraptools-1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "7c01962060112c99607ceda662886497", "packagetype": "bdist_wheel", "python_version": "3.5", "requires_python": null, "size": 10197, "upload_time": "2016-11-06T09:40:02", "url": "https://files.pythonhosted.org/packages/1b/66/1608257162fe965b33c0d8eebbefc402d23c0b42fa048c63ab94b00f64e7/wraptools-1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4002e744aeb4ced623ff6e94e742336d", "sha256": "d6e0a0a8d96ba6814b242b4aee792526bb98c683ee31ae623caea1476c7550e5" }, "downloads": -1, "filename": "wraptools-1.0.tar.gz", "has_sig": false, "md5_digest": "4002e744aeb4ced623ff6e94e742336d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5309, "upload_time": "2016-11-06T09:39:52", "url": "https://files.pythonhosted.org/packages/f6/5e/db04e19d8ebd9863087a460495f4a201bd0f56a20569b0d8e3619f487d0d/wraptools-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "5a3b542f0b8b05fcc97a8bba9cff29e9", "sha256": "b9d8f8c01383863949557c756df513810b786771d51486bf64c0392e29436d26" }, "downloads": -1, "filename": "wraptools-1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5a3b542f0b8b05fcc97a8bba9cff29e9", "packagetype": "bdist_wheel", "python_version": "3.5", "requires_python": null, "size": 10023, "upload_time": "2016-11-08T09:20:16", "url": "https://files.pythonhosted.org/packages/0b/b4/f9193b98722bbea885863179d42a598fadcf97abc7568d41a40a9fda835c/wraptools-1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8ffcf036c8720ea6a20614a0e25e5365", "sha256": "d938334821fa1d3804a5393362db4fcdcb76b4de21790ebc7afc2734f3b9366e" }, "downloads": -1, "filename": "wraptools-1.1.tar.gz", "has_sig": false, "md5_digest": "8ffcf036c8720ea6a20614a0e25e5365", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5772, "upload_time": "2016-11-08T09:20:13", "url": "https://files.pythonhosted.org/packages/c5/41/a1945de825433b13615a37e3d16deabd891acd06534a8c904a7e7cd5e89f/wraptools-1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5a3b542f0b8b05fcc97a8bba9cff29e9", "sha256": "b9d8f8c01383863949557c756df513810b786771d51486bf64c0392e29436d26" }, "downloads": -1, "filename": "wraptools-1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5a3b542f0b8b05fcc97a8bba9cff29e9", "packagetype": "bdist_wheel", "python_version": "3.5", "requires_python": null, "size": 10023, "upload_time": "2016-11-08T09:20:16", "url": "https://files.pythonhosted.org/packages/0b/b4/f9193b98722bbea885863179d42a598fadcf97abc7568d41a40a9fda835c/wraptools-1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8ffcf036c8720ea6a20614a0e25e5365", "sha256": "d938334821fa1d3804a5393362db4fcdcb76b4de21790ebc7afc2734f3b9366e" }, "downloads": -1, "filename": "wraptools-1.1.tar.gz", "has_sig": false, "md5_digest": "8ffcf036c8720ea6a20614a0e25e5365", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5772, "upload_time": "2016-11-08T09:20:13", "url": "https://files.pythonhosted.org/packages/c5/41/a1945de825433b13615a37e3d16deabd891acd06534a8c904a7e7cd5e89f/wraptools-1.1.tar.gz" } ] }