{ "info": { "author": "Shaun Duncan", "author_email": "shaun.duncan@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Utilities" ], "description": "# smokesignal - simple python signaling\n\n[![Build Status](https://travis-ci.org/shaunduncan/smokesignal.png)](https://travis-ci.org/shaunduncan/smokesignal)\n\n`smokesignal` is a simple python library for sending and receiving signals.\nIt draws some inspiration from the django signal framework but is meant as a\ngeneral purpose variant.\n\n\n## Requirements & Compatibility\n\n`smokesignal` requires no dependencies outside of the python standard library.\nIt has been tested on and is compatible with python versions 2.6, 2.7, 3.2, and 3.3.\n\n\n## How To Use\n\nMost uses of `smokesignal` involve registering a single callable to respond to a signal\nusing `on` and sending signals using `emit`.\n\n### Registering Callbacks\n\nMost callback registration happens using `on`, which can be used either as a decorator\nor a direct function call. This method also accepts an optional argument `max_calls` which\nindicates the maximum number of times a callback should respond to an emitted signal:\n\n```python\nimport smokesignal\n\n@smokesignal.on('foo')\ndef my_callback():\n pass\n\n@smokesignal.on('foo', max_calls=2)\ndef my_callback():\n pass\n\nsmokesignal.on('foo', my_callback, max_calls=5)\n```\n\nIf you intend a callback to respond to a signal at most one time, rather than indicating\n`max_calls=1`, you can use `once` as a convenience:\n\n```python\nimport smokesignal\n\n@smokesignal.once('foo')\ndef my_callback():\n pass\n```\n\n### Sending Signals\n\nSignals are sent to all registered callbacks using `emit`. This method optionally accepts\nargument and keyword argument lists that are passed directly to each callback:\n\n```python\nimport smokesignal\n\n# Each callback responding to 'foo' is called\nsmokesignal.emit('foo')\n\n# Each callback responding to 'foo' is called with arguments\nsmokesignal.emit('foo', 1, 2, 3, four=4)\n```\n\nYou can also send signals with the included context manager `emitting`. By default, this context\nmanager accepts one argument, which is a signal to send once the context manager exits. However,\nyou can supply keyword arguments for `enter` and `exit` that will be sent at those points of the\ncontext manager:\n\n```python\nimport smokesignal\n\n# 'foo' emitted on exit\nwith smokesignal.emitting('foo'):\n pass\n\n# 'foo' emitted on enter, 'bar' emitted on exit\nwith smokesignal.emitting(enter='foo', exit='bar'):\n pass\n```\n\n### Disconnecting Callbacks\n\nIf you no longer wish for a callback to respond to any signals, you can use either\n`disconnect_from`, if you intend on removing specific signals, or `disconnect` if you intend\nto remove all of them:\n\n```python\nimport smokesignal\n\n# my_callback will no longer respond to signals\nsmokesignal.disconnect(my_callback)\n\n# my_callback will no longer respond to 'foo', but may repond to others\nsmokesignal.disconnect_from(my_callback, 'foo')\n```\n\n### Other Batteries Included\n\n\nYou can clear large swaths of callbacks using either `clear` or `clear_all`.\nIf you call `clear` without any arguments, it effectively works like `clear_all`:\n\n```python\n# Remove all callbacks responding to a specific signal\nsmokesignal.clear('foo')\n\n# Remove all callbacks responding to all signals\nsmokesignal.clear_all()\nsmokesignal.clear()\n```\n\nSometimes you may want to get a list of signals a callback responds to or quickly\ncheck if a callback will respond to a certain signal. The `signals` and `responds_to`\nare available for this purpose. Note that registering a callback to respond to a\nsignal will also create callable attributes of the callback for easier interaction\nwith these methods:\n\n```python\n# Get a tuple of all signals a callback responds to\nsmokesignal.signals(my_callback)\n\n# Check if a callback responds to a signal\nsmokesignal.responds_to(my_callback, 'foo')\n\n# Or as attributes of the callback\nmy_callback.signals()\nmy_callback.responds_to('foo')\n```\n\n\n## Caveats\n\nWhat would be great is if you could decorate instance methods using `on` or `once`. However,\nthat doesn't work because there is no knowledge of the class instance at the time the callback\nis registered to respond to signals:\n\n```python\nimport smokesignal\n\nclass Foo(object):\n\n # THIS DOES NOT WORK\n @smokesignal.on('bar')\n def callback(self):\n pass\n```\n\nThere is a workaround if you would like instance methods to respond to callbacks:\n\n```python\nimport smokesignal\n\nclass Foo(object):\n def __init__(self, *args, **kwargs):\n smokesignal.on('bar', self.callback)\n super(Foo, self).__init__(*args, **kwargs)\n\n def callback(self):\n pass\n```\n\nThe above will register the callback without any argument requirements but will\nalso ensure that the _intended_ callback method is called correctly.\n\n\n## Changelog\n\n### 0.3\n- Callbacks now have callable attributes `responds_to` and `signals`\n- Calling `clear` with no arguments will clear all callbacks for all signals\n\n### 0.2\n- Added `emitting` context manager\n- Updated internals no longer require decorator magic for enforcing maximum call counts\n\n### 0.1\n- Initial Version\n\n\n## Contribution and License\n\nDeveloped by [Shaun Duncan](mailto:shaun.duncan@gmail.com) and is\nlicensed under the terms of a MIT license.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://www.github.com/shaunduncan/smokesignal/", "keywords": "python event signal signals signaling", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "smokesignal", "package_url": "https://pypi.org/project/smokesignal/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/smokesignal/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://www.github.com/shaunduncan/smokesignal/" }, "release_url": "https://pypi.org/project/smokesignal/0.7.0/", "requires_dist": null, "requires_python": null, "summary": "Simple python event signaling", "version": "0.7.0" }, "last_serial": 1357852, "releases": { "0.1": [], "0.2": [], "0.3": [], "0.4": [ { "comment_text": "", "digests": { "md5": "1f8c37fe8439eb5030cd8f8e9080d43e", "sha256": "fc2abd4fc5124fc3ef57dcd5adbb5a30b096a1814be740c47cfdd424fdff6561" }, "downloads": -1, "filename": "smokesignal-0.4.tar.gz", "has_sig": false, "md5_digest": "1f8c37fe8439eb5030cd8f8e9080d43e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5771, "upload_time": "2014-03-25T11:28:03", "url": "https://files.pythonhosted.org/packages/63/d8/5c668a27a745e31b881f7cc588f12c0e8b88212961dc9c4928ad20ac8c63/smokesignal-0.4.tar.gz" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "c36cc927ac4507b7db14053bd3935542", "sha256": "ae640646ca507bd71138bc3991885b384ee56a9acf3542cf8d351cb7e7766be3" }, "downloads": -1, "filename": "smokesignal-0.5.tar.gz", "has_sig": false, "md5_digest": "c36cc927ac4507b7db14053bd3935542", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5846, "upload_time": "2014-08-12T23:29:13", "url": "https://files.pythonhosted.org/packages/b1/b4/b75ff60462fc83233b4f3d7a8d287494ab150caa34b1bba353f7872cb634/smokesignal-0.5.tar.gz" } ], "0.6": [ { "comment_text": "", "digests": { "md5": "6ee1d42301495c4d7535dc46ee0a4d42", "sha256": "15fa200010f143f8227991cf9f913a82b5574206f568a16fd8e59161e1a47861" }, "downloads": -1, "filename": "smokesignal-0.6.tar.gz", "has_sig": false, "md5_digest": "6ee1d42301495c4d7535dc46ee0a4d42", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5839, "upload_time": "2014-11-25T18:42:51", "url": "https://files.pythonhosted.org/packages/90/ee/5206ded1fcd9619dea4630c7a90fabc8b81c1baea82dc50382d21fd83fd5/smokesignal-0.6.tar.gz" } ], "0.7.0": [ { "comment_text": "", "digests": { "md5": "6643746cea36e8f4d74c32c0cd4ca891", "sha256": "8e0e651a73c258106e59bf8574090fc1cf8a903ee2d074616b76c3a170d53396" }, "downloads": -1, "filename": "smokesignal-0.7.0.tar.gz", "has_sig": false, "md5_digest": "6643746cea36e8f4d74c32c0cd4ca891", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5900, "upload_time": "2014-12-22T21:05:26", "url": "https://files.pythonhosted.org/packages/c2/7d/eef1ce06f78b92b9dfb5f21152ca7bf9eccc856c957de90939f2c3ca1db7/smokesignal-0.7.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6643746cea36e8f4d74c32c0cd4ca891", "sha256": "8e0e651a73c258106e59bf8574090fc1cf8a903ee2d074616b76c3a170d53396" }, "downloads": -1, "filename": "smokesignal-0.7.0.tar.gz", "has_sig": false, "md5_digest": "6643746cea36e8f4d74c32c0cd4ca891", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5900, "upload_time": "2014-12-22T21:05:26", "url": "https://files.pythonhosted.org/packages/c2/7d/eef1ce06f78b92b9dfb5f21152ca7bf9eccc856c957de90939f2c3ca1db7/smokesignal-0.7.0.tar.gz" } ] }