{ "info": { "author": "Bystroushaak", "author_email": "bystrousak@kitakitsune.org", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7" ], "description": "kwargs_obj\n===============================\n\n.. image:: https://badge.fury.io/py/kwargs_obj.png\n :target: http://badge.fury.io/py/kwargs_obj\n\n.. image:: https://pypip.in/d/kwargs_obj/badge.png\n :target: https://pypi.python.org/pypi/kwargs_obj\n\n\nClass that maps ``.__init__(self, **kwargs)`` to attributes.\n\nDocumentation\n-------------\n\nThis module can be used to automatically set values from ``**kwargs`` to attributes, and also to dissable setting of unset attributes.\n\nExamples\n++++++++\n\nMap \\*\\*kwargs to attributes\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nHere you can see, how to map ``**kwargs`` to your attributes:\n\n.. code-block:: python\n\n class Xex(KwargsObj):\n def __init__(self, **kwargs):\n self.something = None\n self.something_else = None\n\n self._kwargs_to_attributes(kwargs)\n\nThis will allow to pass parameters which sets ``something_else`` and ``something_different``:\n\n.. code-block:: python\n\n >>> x = Xex(something=True)\n >>> x.something\n True\n\nSetting of unset attributes is dissabled:\n\n.. code-block:: python\n\n >>> x = Xex(asd=True)\n Traceback (most recent call last):\n File \"\", line 1, in \n File \"\", line 5, in __init__\n File \"kwargs_obj/kwargs_obj.py\", line 61, in _kwargs_to_attributes\n \"Can't set %s parameter - it is not defined here!\" % key\n ValueError: Can't set asd parameter - it is not defined here!\n\nDisable setting of unset attributes\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nThere is also modified `.__setattr__()`` method, which disables to set new attributes. This may be good idea for data containers.\n\nModified `.__setattr__()` functionality can be triggered by setting the ``._all_set`` attribute:\n\n.. code-block:: python\n\n class Xex(KwargsObj):\n def __init__(self):\n self.something = None\n self.something_else = None\n\n self._all_set = True\n\nIt will be now impossible to set new attributes, which may be good for preventing typos:\n\n.. code-block:: python\n\n >>> x = Xex()\n >>> x.asd = True\n Traceback (most recent call last):\n File \"\", line 1, in \n File \"kwargs_obj/kwargs_obj.py\", line 50, in __setattr__\n raise ValueError(\"%s is not defined in this class!\" % name)\n ValueError: asd is not defined in this class!\n\nBut you can still redefine already defined attributes:\n\n.. code-block:: python\n\n >>> x.something = True\n >>> \n\n\nChangelog\n=========\n\n1.0.0\n-----\n - Added tests.\n - Added documentation.\n - Package uploaded to pypi.\n\n0.1.0\n-----\n - Project created.", "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/Bystroushaak/kwargs_obj", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "kwargs_obj", "package_url": "https://pypi.org/project/kwargs_obj/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/kwargs_obj/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/Bystroushaak/kwargs_obj" }, "release_url": "https://pypi.org/project/kwargs_obj/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "Class that maps .__init__(self, **kwargs) to attributes.", "version": "1.0.0" }, "last_serial": 1558806, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "8cbb310a16d1fd072369c4dd67f49bbd", "sha256": "acf094120268beb105eae4b28126697abdf3db39387fd2e85c75de2b615097ba" }, "downloads": -1, "filename": "kwargs_obj-1.0.0.tar.gz", "has_sig": false, "md5_digest": "8cbb310a16d1fd072369c4dd67f49bbd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4198, "upload_time": "2015-05-23T00:04:43", "url": "https://files.pythonhosted.org/packages/39/73/c16fa20b1c36c7eb3ac9eb4e6a48bff25311987482726e95c5220a5f2ad4/kwargs_obj-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8cbb310a16d1fd072369c4dd67f49bbd", "sha256": "acf094120268beb105eae4b28126697abdf3db39387fd2e85c75de2b615097ba" }, "downloads": -1, "filename": "kwargs_obj-1.0.0.tar.gz", "has_sig": false, "md5_digest": "8cbb310a16d1fd072369c4dd67f49bbd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4198, "upload_time": "2015-05-23T00:04:43", "url": "https://files.pythonhosted.org/packages/39/73/c16fa20b1c36c7eb3ac9eb4e6a48bff25311987482726e95c5220a5f2ad4/kwargs_obj-1.0.0.tar.gz" } ] }