{ "info": { "author": "BTaskaya", "author_email": "batuhanosmantaskaya@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "# Restrict\nRestrict python methods \n\n# Example 1\n```py\nfrom restrict import *\nimport builtins\nr = Restrictor()\nrestriction = Restriction(\n builtins, ['__import__', '__build_class__'], Access.BY_CASE\n)\nr.restrict(restriction)\n\nwith case(hash(id(restriction))) as ensured_call:\n collections = ensured_call(builtins.__import__, 'collections')\n Y = ensured_call(builtins.__build_class__, lambda: ..., 'Y')\n assert isinstance(Y, type)\n \nprint(collections.defaultdict(list))\ntry:\n import math\nexcept CaseError:\n print('Case error on import')\n \ntry:\n class X:\n pass\nexcept CaseError:\n print('Case error on build class')\n\n```\nOutput\n```\ndefaultdict(, {})\nCase error on import\nCase error on build class\n```\n# Example 2\n```py\nfrom restrict import *\n\n\nclass TaskManager:\n def __init__(self):\n self.tasks = {}\n\n def add_task(self, task: str, *items):\n self.tasks[task] = items\n\n def pop_task(self):\n return self.tasks.popitem()\n\n def get_tasks(self, task: str):\n return self.tasks[task]\n\n def add(self, x1, x2):\n return x1 + x2\n\n\nrestrictor = Restrictor()\n\n```\n### By Case\n```py\nrestriction = Restriction(\n TaskManager, [\"add_task\", \"pop_task\", TaskManager.get_tasks, \"add\"], Access.BY_CASE\n)\nrestrictor.restrict(restriction)\nt = TaskManager()\ntry:\n t.add(3, 2)\nexcept CaseError:\n print(\"A case error just occured\")\n\nwith case(hash(id(restriction))) as ensured_call:\n z = ensured_call(t.add, 3, 2)\n assert z == 5\n```\nOutput\n```\nA case error just occured\n```\n### By Owner\n```\nrestrictor = Restrictor()\nrestriction = Restriction(\n TaskManager, [\"add_task\", \"pop_task\", TaskManager.get_tasks, \"add\"], Access.BY_OWNER\n)\nrestrictor.restrict(restriction)\nt = TaskManager()\nt.add_task(\"a\", \"b\")\ny = t.add(3, 2)\nassert y == 5\ntry:\n z = TaskManager.add(object(), 3, 2)\n assert z == 5\nexcept OwnerError as exc:\n print(\"An owner error just occured\")\n```\nOutput\n```\nAn owner error just occured\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/btaskaya/restrict", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "restrict", "package_url": "https://pypi.org/project/restrict/", "platform": "", "project_url": "https://pypi.org/project/restrict/", "project_urls": { "Homepage": "https://github.com/btaskaya/restrict" }, "release_url": "https://pypi.org/project/restrict/0.1.3/", "requires_dist": null, "requires_python": "", "summary": "Restrict python methods", "version": "0.1.3" }, "last_serial": 4936146, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "ece292572828b30c8f830ea5484cf77f", "sha256": "ebae59d486f1abd286e6eeaad03b4c0e6424ecebd6c40ec22fc99315676d46e6" }, "downloads": -1, "filename": "restrict-0.1.tar.gz", "has_sig": false, "md5_digest": "ece292572828b30c8f830ea5484cf77f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 651, "upload_time": "2019-03-12T14:32:05", "url": "https://files.pythonhosted.org/packages/91/3e/d43c136b9f2caca9de2b503b2822791ef2e48d44dbe0e1704bc964807370/restrict-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "ea30cb032c00cc8a6a80f0eef4b719f3", "sha256": "6dfb3ea963635ac12a7544438a9e8dead19628049d19a3b33abbd227b277bb5f" }, "downloads": -1, "filename": "restrict-0.1.1.tar.gz", "has_sig": false, "md5_digest": "ea30cb032c00cc8a6a80f0eef4b719f3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2827, "upload_time": "2019-03-13T19:30:08", "url": "https://files.pythonhosted.org/packages/3f/31/9917ea4d9086b450b04fa8e9916f4a87fc6cf18e0566a37b2c4b60f6cff1/restrict-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "a944d5e8222e88b5990d3b5a5005796e", "sha256": "2434b82b013490bdff9e2486da3135311c486717b28445daf1ad9cb7bf68a22b" }, "downloads": -1, "filename": "restrict-0.1.2.tar.gz", "has_sig": false, "md5_digest": "a944d5e8222e88b5990d3b5a5005796e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3865, "upload_time": "2019-03-13T19:30:39", "url": "https://files.pythonhosted.org/packages/7e/df/3ff37cbaa50246a62043eceabff718925f8b11888337e71ec3668f29b5d2/restrict-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "b5936182c3ce48bd13ee7b9e647976b1", "sha256": "ab826d306e9051dab4b229af0eda4ab6f2279d778cc1271450ce1a468e44feb0" }, "downloads": -1, "filename": "restrict-0.1.3.tar.gz", "has_sig": false, "md5_digest": "b5936182c3ce48bd13ee7b9e647976b1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3814, "upload_time": "2019-03-13T19:33:14", "url": "https://files.pythonhosted.org/packages/e5/98/66c625b5cb127e42969f7a0f5196dd2d56ed27644aaaa839a5b1638cb828/restrict-0.1.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b5936182c3ce48bd13ee7b9e647976b1", "sha256": "ab826d306e9051dab4b229af0eda4ab6f2279d778cc1271450ce1a468e44feb0" }, "downloads": -1, "filename": "restrict-0.1.3.tar.gz", "has_sig": false, "md5_digest": "b5936182c3ce48bd13ee7b9e647976b1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3814, "upload_time": "2019-03-13T19:33:14", "url": "https://files.pythonhosted.org/packages/e5/98/66c625b5cb127e42969f7a0f5196dd2d56ed27644aaaa839a5b1638cb828/restrict-0.1.3.tar.gz" } ] }