{ "info": { "author": "Bar Harel", "author_email": "bzvi7919@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# bdict\nA library allowing you to create an auto method-binding dict.\n\nEver dreamed of writing clean dicts pointing keys to methods? Fear no more!\n\nMainly used for event handlers, a binding dict consists of a mapping between\nany events or keys, to their appropriate handler functions within a class.\nUpon key lookup, the dict will bind the appropriate function to the instance\nof the class.\n\nFor an example:\n\n```Python\nclass Server:\n \"\"\"Typical server with a small mapping between event handlers and functions\"\"\"\n def __init__(self, name):\n self.name = name\n\n def on_connect(self, remote_host):\n print(self.name, remote_host)\n\n def on_connect(self, remote_host):\n print(self.name, remote_host)\n\n handlers = BDict({NewConnectionEvent: on_connect,\n DisconnectonEvent: on_disconnect})\n\n>>> s = Server(\"myserver\")\n>>> s.handlers[NewConnectionEvent](\"1.2.3.4\")\nmyserver 1.2.3.4\n```\nAs you can see, after accessing the handlers dict, and upon key lookup,\nthe dict bound the handler functions to the instance.\n\nBDict also works with classmethods in a clean and fashioned way:\n\n```Python\nclass MyClass:\n \"\"\"Typical server with a small mapping between event handlers and functions\"\"\" \n @classmethod\n def class_handle(cls):\n print(cls.__name__)\n\n handlers = BDict({\"class_handle\": class_handle})\n\n>>> MyClass.handlers[\"class_handle\"]\n>\n>>> MyClass.handlers[\"class_handle\"]()\nMyClass\n\n>>> inst = MyClass()\n>>> inst.handlers[\"class_handle\"]\n>\n>>> inst.handlers[\"class_handle\"]()\nMyClass\n```\nUpon accessing the BDict through an instance, the BDict will create an internal instance data container on the BDict, \nallowing you to modify it's dictionary and not affect other instances!\n```Python\n>>> inst.handlers[123] = 456\n>>> inst.handlers[123]\n456\n>>> inst2 = MyClass()\n>>> inst2.handlers[123]\nTraceback (most recent call last):\n ...\nKeyError: 123\n```\n\n## Usage:\n\n`BDict(dict_)`\n\n`dict_` can be a dict or an iterable of (key, value) pairs and will be used to initialize `BDict`.\n\nThe class BDict is used on must support weak referencing (the vast majority of custom objects do). If you use `__slots__`, you are able to do this by adding `__weakref__` to the slots.\n\n`BDict.autobind(key, value)`\n\nAllows adding an autobinding entry in the dict (regular additions will not autobind). `key` is the key for access while `value` is the function that will be autobound.\n\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/bharel/bdict", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "bdict", "package_url": "https://pypi.org/project/bdict/", "platform": "", "project_url": "https://pypi.org/project/bdict/", "project_urls": { "Homepage": "https://github.com/bharel/bdict" }, "release_url": "https://pypi.org/project/bdict/0.1.0/", "requires_dist": null, "requires_python": ">=3.6", "summary": "Python auto-binding dict", "version": "0.1.0" }, "last_serial": 4001800, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "f9b74120e9d725d69b513186c3733a14", "sha256": "7997d1b9779b46750e64ce32e5bd597aa1ec5e0fc817be909a3b98da1f3659ed" }, "downloads": -1, "filename": "bdict-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "f9b74120e9d725d69b513186c3733a14", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 4380, "upload_time": "2018-06-25T22:01:00", "url": "https://files.pythonhosted.org/packages/68/e6/125bfae2e93b128265070e7363b02b55b9c053554125429d11649197baaf/bdict-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "05f7ab18af4cd50661a8de0abb6bd0af", "sha256": "720fd713d34d057813eddf1834255459248d90f15dd5b64bd97db449206c2821" }, "downloads": -1, "filename": "bdict-0.1.0.tar.gz", "has_sig": false, "md5_digest": "05f7ab18af4cd50661a8de0abb6bd0af", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 3938, "upload_time": "2018-06-25T22:01:01", "url": "https://files.pythonhosted.org/packages/9c/3b/ae00dcaad306488276bae8240ce84432a34acbe9ee14bda451d0fb19f88d/bdict-0.1.0.tar.gz" } ], "0.1.0b2": [ { "comment_text": "", "digests": { "md5": "62abc0a0c5b9b2c284967a0eebd80ca9", "sha256": "fbc3e38d8a136da6ae80f16c185c4a88db0922e3297126db27f04a9dbe5cb37d" }, "downloads": -1, "filename": "bdict-0.1.0b2-py3-none-any.whl", "has_sig": false, "md5_digest": "62abc0a0c5b9b2c284967a0eebd80ca9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 4011, "upload_time": "2018-06-12T22:31:45", "url": "https://files.pythonhosted.org/packages/d9/96/0c170dfeb7205717d46f814e8243ca4c0338d540e73c689fc8e1d2a6075c/bdict-0.1.0b2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "dbdc6be15d12227f0880b144d08ee69a", "sha256": "32cb0e1d9a5bbbb5a0d8104619da1aafbd5066d1f26411ac11aebd9e304591aa" }, "downloads": -1, "filename": "bdict-0.1.0b2.tar.gz", "has_sig": false, "md5_digest": "dbdc6be15d12227f0880b144d08ee69a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 3695, "upload_time": "2018-06-12T22:31:46", "url": "https://files.pythonhosted.org/packages/0d/73/3912fe9c9d8e58ed7eca9e6ad59213a235bf6d2a919c44799c3d60aef86c/bdict-0.1.0b2.tar.gz" } ], "0.1.0b3": [ { "comment_text": "", "digests": { "md5": "df76f72fadddca90cba6a60e88c703bd", "sha256": "542c31022f3abd4509a3fe0b47973d8245505666a4e1302e2abc92336d269da4" }, "downloads": -1, "filename": "bdict-0.1.0b3-py3-none-any.whl", "has_sig": false, "md5_digest": "df76f72fadddca90cba6a60e88c703bd", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 5156, "upload_time": "2018-06-12T22:37:34", "url": "https://files.pythonhosted.org/packages/f5/e7/d4c98cc1d1d232a07fb3505e94d922ab0d48b4b02676139de5a4eab74440/bdict-0.1.0b3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "20e22373d7e3f255cc1fe006ea2969f3", "sha256": "796a08666943153503ba9968f0e2d4613265bb68cc55f4fa5e7dc4b95896d3d6" }, "downloads": -1, "filename": "bdict-0.1.0b3.tar.gz", "has_sig": false, "md5_digest": "20e22373d7e3f255cc1fe006ea2969f3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 4761, "upload_time": "2018-06-12T22:37:35", "url": "https://files.pythonhosted.org/packages/13/b2/944edb5fadd191b500e67cda1b4f584a8a82491de5a2c938c135d92ff64e/bdict-0.1.0b3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f9b74120e9d725d69b513186c3733a14", "sha256": "7997d1b9779b46750e64ce32e5bd597aa1ec5e0fc817be909a3b98da1f3659ed" }, "downloads": -1, "filename": "bdict-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "f9b74120e9d725d69b513186c3733a14", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 4380, "upload_time": "2018-06-25T22:01:00", "url": "https://files.pythonhosted.org/packages/68/e6/125bfae2e93b128265070e7363b02b55b9c053554125429d11649197baaf/bdict-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "05f7ab18af4cd50661a8de0abb6bd0af", "sha256": "720fd713d34d057813eddf1834255459248d90f15dd5b64bd97db449206c2821" }, "downloads": -1, "filename": "bdict-0.1.0.tar.gz", "has_sig": false, "md5_digest": "05f7ab18af4cd50661a8de0abb6bd0af", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 3938, "upload_time": "2018-06-25T22:01:01", "url": "https://files.pythonhosted.org/packages/9c/3b/ae00dcaad306488276bae8240ce84432a34acbe9ee14bda451d0fb19f88d/bdict-0.1.0.tar.gz" } ] }