{ "info": { "author": "David Wolever", "author_email": "david@wolever.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Software Development", "Topic :: Utilities" ], "description": "``autorepr``: makes civilized string representations\n====================================================\n\n.. image:: https://travis-ci.org/wolever/autorepr.svg?branch=master\n :target: https://travis-ci.org/wolever/autorepr\n\nNow with Python 3 support!\n\nOverview\n--------\n\nPython makes classes easy, but ``__repr__`` methods hard. Did you forget to\nreference ``self`` again? Probably. Did have you thought to yourself \"eh, this\nclass is real simple, it doesn't need a repr\"? Without a doubt. Was production\ntaken down three times last week because your ``__str__`` returned unicode? ...\nno? Maybe that's just me.\n\n``autorepr`` makes it simple to build expressive, safe, and correct,\n``__repr__``, ``__str__``, ``__unicode__``, and ``__bytes__`` methods in a\nsingle line each.\n\nWith ``autorepr``, you get the repers you want, without worrying about the\nfiddly bits (like encoding and decoding), leaving you to focus on your project:\n\n.. code:: python\n\n >>> from autorepr import autorepr, autotext\n >>> class Person(object):\n ... name = u\"Alex \u2603\"\n ... height = 123.456\n ...\n ... __repr__ = autorepr([\"name\", \"height:0.1f\"])\n ... __str__, __unicode__ = autotext(\"{self.name} ({self.height:0.0f} cm)\")\n ...\n >>> p = Person()\n >>> repr(p)\n \"<__main__.Person name=u'Alex \\\\u2603' height=123.5 at 0x...>\"\n >>> unicode(p)\n u'Alex \\u2603 (123 cm)'\n >>> str(p)\n 'Alex \\xe2\\x98\\x83 (123 cm)'\n\n\nInstallation\n------------\n\n::\n\n $ pip install autorepr\n\n\nUsage\n-----\n\n``autorepr`` exposes two main functions:\n\n- ``autorepr``, which builds a Python-esque ``__repr__`` string by passing\n either a ``str.format``-style string, or a list of attributes which should be\n included in a ``name=value`` list::\n\n autorepr([\"name\", \"height:0.1f\"]) -->\n \"\"\n autorepr(\"{self.id} name={self.name!r}\") -->\n \"\"\n\n- ``autotext``, which uses ``autostr`` and ``autounicode`` to create\n ``__str__`` and ``__unicode__`` methods in a Python 2 + 3 friendly way::\n\n __str__, __unicode__ = autotext(\"{self.name} ({self.height!d} cm)\") -->\n str: 'Alex \\xe2\\x98\\x83 (123cm)'\n unicode: u'Alex \\u2603 (123cm)'\n\nAnd three secondary functions - ``autostr``, ``autounicode``, and\n``autobytes`` - which build ``__str__``, ``__unicode__``, and ``__bytes__``\nfunctions, respectively. The functions will do their best to avoid Unicode\nencoding / decoding errors, and will generally Do The Right Thing, even if the\ninputs aren't necessarily sensible.\n\nNote: the examples shown here are Python 2, but everything works equally well\nunder Python 3.\n\n.. code:: python\n\n >>> from autorepr import autorepr, autotext, autostr, autounicode\n >>> class Person(object):\n ... name = u\"Alex \u2603\"\n ... height = 123.456\n ...\n ... __repr__ = autorepr([\"name\", \"height:0.1f\"])\n ... __str__, __unicode__ = autotext(\"{self.name} ({self.height:0.0f} cm)\")\n ...\n >>> p = Person()\n >>> repr(p)\n \"<__main__.Person name=u'Alex \\\\u2603' height=123.5 at 0x...>\"\n >>> unicode(p)\n u'Alex \\u2603 (123 cm)'\n >>> str(p)\n 'Alex \\xe2\\x98\\x83 (123 cm)'\n\n\nNotice that ``autostr`` and ``autorepr`` (as called here through ``autotext``)\nare intelligent about converting to/from unicode (decoding/encoding as UTF-8)\nas necessary:\n\n.. code:: python\n\n >>> p.name = u\"unicode: \u2603\"\n >>> unicode(p)\n u'unicode: \\u2603 (123 cm)'\n >>> str(p)\n 'unicode: \\xe2\\x98\\x83 (123 cm)'\n >>> p.name = 'utf-8 bytes: \\xe2\\x98\\x83'\n >>> unicode(p)\n u'utf-8 bytes: \\u2603 (123 cm)'\n >>> str(p)\n 'utf-8 bytes: \\xe2\\x98\\x83 (123 cm)'\n\n*Note*: ``autostr`` and ``autorepr`` won't crash on invalid UTF-8 (for example,\nif ``autounicode`` is asked to turn binary data into unicode), but the result\nis *undefined* and may not be desirable.\n\nAdditional properties can be passed in as ``kwargs``, which will be called with\nthe instance as a parameter:\n\n.. code:: python\n\n >>> name_with_len = autostr(\"{self.name} length={len}\",\n ... len=lambda self: len(self.name))\n ...\n >>> p.name = 'Alex'\n >>> name_with_len(p)\n 'Alex length=4'\n\nThis works with ``autorepr``'s list mode too:\n\n.. code:: python\n\n >>> repr_with_len = autorepr([\"name\", \"len\"],\n ... len=lambda self: len(self.name))\n ...\n >>> repr_with_len(p)\n \"<__main__.Person name='Alex' len=4 at 0x...>\"\n\nIf a regular format string is passed to ``autorepr``, it will use that instead\nof the generated string:\n\n.. code:: python\n\n >>> repr_with_str = autorepr(\"{self.name!r}\")\n >>> repr_with_str(p)\n \"<__main__.Person 'Alex' at 0x...>\"\n\nAnd of course, if you don't want your ``__repr__`` to be wrapped in\n````, you can use ``autostr``:\n\n.. code:: python\n\n >>> repr_with_autostr = autostr(\"Person({self.name!r})\")\n >>> repr_with_autostr(p)\n \"Person('Alex')\"\n\n\nFormat specifications can also be passed to ``autorepr`` if the default of\n``!r`` is undesirable (for example, truncating floats):\n\n.. code:: python\n\n >>> with_fmt_spec = autorepr([\"duration:0.1f\", \"addr:x\", \"type!s\"],\n ... duration=lambda x: 123.456,\n ... addr=lambda x: 0xabc123,\n ... type=lambda x: \"foo\")\n >>> with_fmt_spec(None)\n '<....NoneType duration=123.5 addr=abc123 type=foo at 0x...>'\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/wolever/autorepr", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "autorepr", "package_url": "https://pypi.org/project/autorepr/", "platform": "", "project_url": "https://pypi.org/project/autorepr/", "project_urls": { "Homepage": "https://github.com/wolever/autorepr" }, "release_url": "https://pypi.org/project/autorepr/0.3.0/", "requires_dist": null, "requires_python": "", "summary": "Makes civilized __repr__, __str__, and __unicode__ methods", "version": "0.3.0" }, "last_serial": 2705148, "releases": { "0.1.0": [], "0.1.1": [ { "comment_text": "", "digests": { "md5": "68acf76cbc3b386882cfbab573575161", "sha256": "1ef7a6bc30cbd49b53579002ee38846e5a03d04697ed3b9a62854d02ee93dd71" }, "downloads": -1, "filename": "autorepr-0.1.1-py2-none-any.whl", "has_sig": false, "md5_digest": "68acf76cbc3b386882cfbab573575161", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 5795, "upload_time": "2016-01-27T22:07:36", "url": "https://files.pythonhosted.org/packages/0a/a7/dc3be08b1e4ca8b987c943906dac7f642b29a35ad6731b72223550536744/autorepr-0.1.1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b443749fce97995d678c3c54d05c6432", "sha256": "95661d4a36b2115f901362ee8c518ccac7daa505e31721f77dc26e49436434c7" }, "downloads": -1, "filename": "autorepr-0.1.1.tar.gz", "has_sig": false, "md5_digest": "b443749fce97995d678c3c54d05c6432", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4005, "upload_time": "2016-01-27T22:07:30", "url": "https://files.pythonhosted.org/packages/f8/91/a1039358032d7a89f7550aedf6085e2f3b569c4baff1f175923f188ac8fd/autorepr-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "2bf8337c60df8ce014a6808b204029c7", "sha256": "83a9c26d9c09bfb65b2d26ea0fbc1775ce0d8ac6a9750e3222f7c45cf71dbd1c" }, "downloads": -1, "filename": "autorepr-0.2.0-py2-none-any.whl", "has_sig": false, "md5_digest": "2bf8337c60df8ce014a6808b204029c7", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 7059, "upload_time": "2016-10-01T23:47:42", "url": "https://files.pythonhosted.org/packages/44/a1/6a26ce41988ac36ad4fcc8fb4203b51216571b153993a05ee82ee2cc8618/autorepr-0.2.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "662d6922b8cf10913bc2c15c7c6c257b", "sha256": "645f0e09c08736bfc877b439746ce48d21ee4a17f7be3f5ad87808593bc26ec3" }, "downloads": -1, "filename": "autorepr-0.2.0.tar.gz", "has_sig": false, "md5_digest": "662d6922b8cf10913bc2c15c7c6c257b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6520, "upload_time": "2016-10-01T23:47:39", "url": "https://files.pythonhosted.org/packages/61/33/e02d21ab85b1bb162bc3420e5c33c0dd7a8dfc8436f68219bbcfa2fa01f0/autorepr-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "9613c8b96286d91c55a8b75b49be11d4", "sha256": "c34567e4073630feb52d9c788fc198085e9e9de4817e3b93b7c4c534fc689f11" }, "downloads": -1, "filename": "autorepr-0.3.0-py2-none-any.whl", "has_sig": false, "md5_digest": "9613c8b96286d91c55a8b75b49be11d4", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 8583, "upload_time": "2017-03-14T15:23:48", "url": "https://files.pythonhosted.org/packages/0f/c6/ef25daa81f3f8eb1c714f1e3d538faf18004440ed624e2f91298e43d1bae/autorepr-0.3.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a16066d0490fbef50bff1e923add94a3", "sha256": "1d9010d14fb325d3961e3aa73692685563f97d6ba4a2f0f735329fb37422599c" }, "downloads": -1, "filename": "autorepr-0.3.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a16066d0490fbef50bff1e923add94a3", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 8589, "upload_time": "2017-03-14T15:24:37", "url": "https://files.pythonhosted.org/packages/f7/a5/339ac779f32f7ed627c84311bb93274906212e5285d5bb80aa5e087161f8/autorepr-0.3.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "886c0d63750c41f9fe490c04ec14483d", "sha256": "ef770b84793d5433e6bb893054973b8c7ce6b487274f9c3f734f678cae11e85e" }, "downloads": -1, "filename": "autorepr-0.3.0.tar.gz", "has_sig": false, "md5_digest": "886c0d63750c41f9fe490c04ec14483d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8685, "upload_time": "2017-03-14T15:23:46", "url": "https://files.pythonhosted.org/packages/15/d1/d33a2f69b85af4ac67298bf8d8b41db94363e91a48dbdc95aaf49eca5504/autorepr-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9613c8b96286d91c55a8b75b49be11d4", "sha256": "c34567e4073630feb52d9c788fc198085e9e9de4817e3b93b7c4c534fc689f11" }, "downloads": -1, "filename": "autorepr-0.3.0-py2-none-any.whl", "has_sig": false, "md5_digest": "9613c8b96286d91c55a8b75b49be11d4", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 8583, "upload_time": "2017-03-14T15:23:48", "url": "https://files.pythonhosted.org/packages/0f/c6/ef25daa81f3f8eb1c714f1e3d538faf18004440ed624e2f91298e43d1bae/autorepr-0.3.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a16066d0490fbef50bff1e923add94a3", "sha256": "1d9010d14fb325d3961e3aa73692685563f97d6ba4a2f0f735329fb37422599c" }, "downloads": -1, "filename": "autorepr-0.3.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a16066d0490fbef50bff1e923add94a3", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 8589, "upload_time": "2017-03-14T15:24:37", "url": "https://files.pythonhosted.org/packages/f7/a5/339ac779f32f7ed627c84311bb93274906212e5285d5bb80aa5e087161f8/autorepr-0.3.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "886c0d63750c41f9fe490c04ec14483d", "sha256": "ef770b84793d5433e6bb893054973b8c7ce6b487274f9c3f734f678cae11e85e" }, "downloads": -1, "filename": "autorepr-0.3.0.tar.gz", "has_sig": false, "md5_digest": "886c0d63750c41f9fe490c04ec14483d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8685, "upload_time": "2017-03-14T15:23:46", "url": "https://files.pythonhosted.org/packages/15/d1/d33a2f69b85af4ac67298bf8d8b41db94363e91a48dbdc95aaf49eca5504/autorepr-0.3.0.tar.gz" } ] }