{ "info": { "author": "Anshu Choubey", "author_email": "anshu.choubey@imaginea.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Simple Interceptor\r\n==================\r\n\r\nIt is a simple tool that can be used to intercept methods of classes to\r\napply advices on them.\r\n\r\nInstallation\r\n------------\r\n::\r\n\r\n pip install SimpleInterceptor\r\n\r\nPlease note, ``pip search SimpleInterceptor`` doesn't return anything.\r\nAlternatively, the package can be cloned or downloaded, extracted and\r\nfollowing can be run\r\n\r\n\r\n- *Install* using ``python setup.py install``\r\n- *Run Tests* using ``python setup.py test``\r\n\r\nExample\r\n-------\r\n\r\nIf we were to implement a bank transaction logic, it could be as simple\r\nas this.\r\n\r\n::\r\n\r\n class BankTransaction(object):\r\n def transfer(self, amt):\r\n print \"Transferring Rs. %d\" % amt\r\n\r\nAnd transaction would be done this simply as well.\r\n\r\n::\r\n\r\n obj = BankTransaction()\r\n obj.transfer(1000)\r\n\r\n.. figure:: example/non-intercept.jpg?raw=true\r\n :alt: Non-intercept Example\r\n\r\n Non-intercept Example\r\n\r\nNow, there could be various other concerns related to this requirement -\r\n*logging, checking if balance is available, notifying user about the\r\ntransaction status* etc. We could had written all of this logic there.\r\nBut in order to modularise it better or separate the cross-cutting\r\nconcerns, we follow principles of AOP and apply the other\r\nconcerns(advices) by intercepting the core method. This simple library\r\nis intended to do this.\r\n\r\nSay the above concerns are implemented this trivially.\r\n\r\n::\r\n\r\n def start_transaction_log(*args, **kwargs):\r\n print \"Starting transaction\"\r\n\r\n def check_balance_available(*args, **kwargs):\r\n print \"Balance check logic says Transaction allowed\"\r\n\r\n def send_notification(*args, **kwargs):\r\n print \"Transaction successful\"\r\n\r\nNow, in order to apply these logics to the ``transfer`` method, we would\r\nneed to create an aspect and decorate the ``BankTransaction`` class with\r\nthe ``intercept`` decorator, featured by the tool, as shown under.\r\nInstead of using transfer we could had used any regex pattern to match\r\nthe method name. This allows to intercept multiple methods using the\r\nsame pattern.\r\n\r\n::\r\n\r\n aspects = dict()\r\n aspects[r'transfer'] = dict(\r\n before=start_transaction_log,\r\n around_before=check_balance_available,\r\n after_success=send_notification)\r\n\r\n from interceptor import intercept\r\n\r\n BankTransaction = intercept(aspects)(BankTransaction)\r\n\r\n obj = BankTransaction()\r\n obj.transfer(1000)\r\n\r\n.. figure:: example/intercept.jpg?raw=true\r\n :alt: Intercept Example\r\n\r\n Intercept Example\r\n\r\nAdvices honoured\r\n----------------\r\n\r\nThe tool accepts following self-explanatory advices. *before* logic is\r\nrun before *around\\_before* and *around\\_after* is run before\r\n*after\\_success*. *after\\_exc* can be used to write exception logic.\r\n*around\\_after* doesn't run in case of exception.\r\n\r\n- before\r\n- around\\_before\r\n- after\\_exc\r\n- around\\_after\r\n- after\\_success\r\n- after\\_finally", "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/host-anshu/simpleInterceptor", "keywords": "interceptor aop", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "SimpleInterceptor", "package_url": "https://pypi.org/project/SimpleInterceptor/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/SimpleInterceptor/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/host-anshu/simpleInterceptor" }, "release_url": "https://pypi.org/project/SimpleInterceptor/0.1/", "requires_dist": null, "requires_python": null, "summary": "Simple interceptor related to concepts of AOP", "version": "0.1" }, "last_serial": 2099007, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "d4bde9d48b7c3903e8468c313d607f3a", "sha256": "e9a4736c53ad7b593c2811b7dfd17a87e38e9455f49b54cdb363569dd3dfcb59" }, "downloads": -1, "filename": "SimpleInterceptor-0.1.tar.gz", "has_sig": false, "md5_digest": "d4bde9d48b7c3903e8468c313d607f3a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7929934, "upload_time": "2016-05-04T14:54:34", "url": "https://files.pythonhosted.org/packages/92/e1/4835bd4296636614fbbd0f2a5b111f19aed1aed78cc238373e6efe715fd9/SimpleInterceptor-0.1.tar.gz" } ], "0.1.dev1": [ { "comment_text": "", "digests": { "md5": "a66dc535aa517d749e381598ff4c5b56", "sha256": "0233913664b7aedeea89bcdc4c90d63a8f23396355698a9b7dd90f13734365b5" }, "downloads": -1, "filename": "SimpleInterceptor-0.1.dev1.tar.gz", "has_sig": false, "md5_digest": "a66dc535aa517d749e381598ff4c5b56", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 77816, "upload_time": "2016-04-17T21:00:28", "url": "https://files.pythonhosted.org/packages/2f/a2/5f87249b2da959bf16aa46a44d242e99543f341f7ee08539a7902fdd605e/SimpleInterceptor-0.1.dev1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d4bde9d48b7c3903e8468c313d607f3a", "sha256": "e9a4736c53ad7b593c2811b7dfd17a87e38e9455f49b54cdb363569dd3dfcb59" }, "downloads": -1, "filename": "SimpleInterceptor-0.1.tar.gz", "has_sig": false, "md5_digest": "d4bde9d48b7c3903e8468c313d607f3a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7929934, "upload_time": "2016-05-04T14:54:34", "url": "https://files.pythonhosted.org/packages/92/e1/4835bd4296636614fbbd0f2a5b111f19aed1aed78cc238373e6efe715fd9/SimpleInterceptor-0.1.tar.gz" } ] }