{ "info": { "author": "\u211codrigo \u212dacilh\u03b1\u03c2", "author_email": "batalema@cacilhas.info", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# Concerns\n\n[Python](https://www.python.org/) implementation of the\n[Ruby](https://www.ruby-lang.org/)\u2019s\n[ActiveSupport::Concern](https://api.rubyonrails.org/v5.1/classes/ActiveSupport/Concern.html)\nbehavior.\n\n## Use examples\n\nNote: the class context is the fourth argument of the\n[metaclass](https://www.python.org/doc/essays/metaclasses/) `__init__` method,\nformally \u201cnamespace\u201d:\n\n```python\ndef __init__(cls, name: str, bases: tuple, namespace: dict) -> None:\n ...\n```\n\nIt is a dictionary representation of the class body.\n\n### Using a class as mix-in\n\nIf the aspect is a class, its context will be merged to the target context on\nits factoring.\n\n```python\nfrom typing import NamedTuple\nfrom concerns import concern\n\n\nclass SerialMixin:\n\n def serialize(self) -> str:\n return json.dumps(self._asdict(), sort_keys=True)\n\n @classmethod\n def deserialize(cls, data: str):\n return cls(**json.loads(data))\n\n\nclass PersonBase(NamedTuple):\n name: str\n surname: str\n\n\nclass Person(PersonBase):\n concern(SerialMixin)\n```\n\n### Using a mapping as default values map\n\nIf the aspect is a mapping (a dictionary, by example), it itself will be merged\nto the target context on its factoring.\n\n```python\nfrom concerns import concern\n\nclass Animal:\n # Too simple use, avoid doing it\n concern({voice='grrr'})\n\n def __init__(self, *, voice: str = None):\n if voice:\n self.voice = voice\n\n def say(self) -> None:\n print(self.voice)\n```\n\n### Function to change behavior\n\nIf the aspect is a callable, the target class context will be passed as\nparameter to the aspect for processing before its factoring.\n\n```python\nfrom concerns import concern\nfrom collections.abc import MutableMapping\nfrom datetime import datetime\n\ndef make_timed(context: MutableMapping) -> None:\n \"\"\"\n Reusable aspect function to add creating time to objects\n \"\"\"\n\n def set_created_attr(attr: str) -> None:\n context[attr] = None\n def new(cls, name: str, bases: tuple, _dict: dict):\n self = super().__new__(cls, name, bases, _dict)\n setattr(self, attr) = datetime.now()\n return self\n context['__new__'] = new\n context['set_created_attr'] = set_created_attr\n\n\nclass Register:\n concern(make_timed)\n\n ... # more class attributes\n\n set_created_attr('created_at')\n```\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/cacilhas/concerns", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "concerns", "package_url": "https://pypi.org/project/concerns/", "platform": "", "project_url": "https://pypi.org/project/concerns/", "project_urls": { "Homepage": "https://bitbucket.org/cacilhas/concerns" }, "release_url": "https://pypi.org/project/concerns/1.0/", "requires_dist": null, "requires_python": "", "summary": "aspect oriented programming helper", "version": "1.0" }, "last_serial": 4176597, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "3817540cc0596fa4b2d8508c592de043", "sha256": "11c8621e42adb2f263a7bfb8c6151c4478df7c78246406936e618d486a350df0" }, "downloads": -1, "filename": "concerns-1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "3817540cc0596fa4b2d8508c592de043", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 2128, "upload_time": "2018-08-16T13:37:50", "url": "https://files.pythonhosted.org/packages/91/b5/968af51879e395fb61703ceaaed932f45c881c88355fcddacf69849b55de/concerns-1.0-py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3817540cc0596fa4b2d8508c592de043", "sha256": "11c8621e42adb2f263a7bfb8c6151c4478df7c78246406936e618d486a350df0" }, "downloads": -1, "filename": "concerns-1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "3817540cc0596fa4b2d8508c592de043", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 2128, "upload_time": "2018-08-16T13:37:50", "url": "https://files.pythonhosted.org/packages/91/b5/968af51879e395fb61703ceaaed932f45c881c88355fcddacf69849b55de/concerns-1.0-py3-none-any.whl" } ] }