{ "info": { "author": "Alexander Borzunov", "author_email": "borzunov.alexander@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "=======\ndontasq\n=======\n\nExtend built-in Python collections with LINQ-for-objects style methods\n\nDescription\n-----------\n\nThe library extends built-in Python collections with methods from `Robert Smallshire`_'s asq_. Adding methods to built-ins isn't officially allowed, but it's possible to do this in CPython (both 2.x and 3.x) using a hack described in the corresponding section below.\n\n.. _Robert Smallshire: https://github.com/rob-smallshire\n.. _asq: https://github.com/rob-smallshire/asq\n\nFor example:\n\n.. code:: python\n\n >>> import dontasq\n >>>\n >>> [1, 2, 3].select_many(lambda x: (x, x ** 2)).to_tuple()\n (1, 1, 2, 4, 3, 9)\n >>> 'oh brave new world'.split() \\\n ... .where(lambda word: len(word) >= 5) \\\n ... .select(str.capitalize) \\\n ... .to_list()\n ['Brave', 'World']\n\nIn some cases, this style helps to write functional-esque code that is more clear than code with ``map``, ``filter`` and generator expressions: there's no confusion with brackets, and methods are applied in the natural order.\n\n**Warning!** ``dontasq`` uses undocumented CPython features. It's not guaranteed that this features will be maintained in the future Python versions.\n\nDetails\n-------\n\nDuring import, ``dontasq`` looks for classes in the built-ins namespace, ``collections`` and ``itertools`` modules. If a class is an iterable and isn't a metaclass, the library will append all public methods of ``asq.queryables.Queryable`` to it in such a way that a method call:\n\n.. code:: python\n\n >>> instance.select(lambda x: x * 2)\n\nWill be equal to:\n\n.. code:: python\n\n >>> Queryable(instance).select(lambda x: x * 2)\n\nSo the methods will be added to classes such as ``list``, ``str``, ``collections.OrderedDict``, or ``itertools.count``. You can find a list of all ``Queryable`` methods and their description in `asq documentation`_.\n\n.. _asq documentation: http://docs.asq.googlecode.com/hg/1.0/html/reference/queryables.html#asq-queryables-queryable\n\nIf a class already contains an attribute with a coinciding name (e.g. ``str.join`` and ``list.count``), this attribute won't be replaced.\n\nOf course, you're able to import other ``asq`` modules when using ``dontasq``:\n\n.. code:: python\n\n >>> import dontasq\n >>> from asq.predicates import *\n >>>\n >>> words = ['banana', 'receive', 'believe', 'ticket', 'deceive']\n >>> words.where(contains_('ei')).to_list()\n ['receive', 'deceive']\n\nIf you want to patch classes from another library, you can use methods ``dontasq.patch_type`` and ``dontasq.patch_module``:\n\n.. code:: python\n\n >>> import bintrees\n >>> import dontasq\n >>>\n >>> dontasq.patch_type(bintrees.AVLTree)\n >>>\n >>> dictionary = {1: 'Anton', 2: 'James', 3: 'Olivia'}\n >>> bintrees.AVLTree(dictionary).select(lambda x: x * 2).to_list()\n [2, 4, 6]\n\nYou can find other examples in `\"tests\" directory`_.\n\n.. _\"tests\" directory: https://github.com/borzunov/dontasq/tree/master/tests\n\nAdding methods to built-ins\n---------------------------\n\nThe following approach is found in `this question`_ on StackOverflow.\n\n.. _this question: https://stackoverflow.com/questions/25440694/whats-the-purpose-of-dictproxy\n\nOfficially, you can get only a protected (read-only) instance of built-ins' ``__dict__``. The trick is that in CPython this instance contains a reference to an original (modifiable) dictionary that can be tracked with `gc.get_referents`_ function.\n\n.. _gc.get_referents: https://docs.python.org/3/library/gc.html#gc.get_referents\n\nFor example, we can add ``select`` method to built-in ``list`` (unlike ``dontasq``, it's non-lazy in this example):\n\n.. code:: python\n\n >>> import gc\n >>> gc.get_referents(vars(list))[0]['select'] = lambda self, func: list(map(func, self))\n >>>\n >>> [1, 2, 3].select(lambda x: x * 2)\n [2, 4, 6]\n\nAnother possible way is to use forbiddenfruit_ library that interacts with ``ctypes.pythonapi`` module. The both approaches stably work on both Python 2 and 3, but restricted to CPython only.\n\n.. _forbiddenfruit: https://github.com/clarete/forbiddenfruit\n\nInstallation\n------------\n\nYou can install the library using pip::\n\n sudo pip install dontasq\n\nOr install a previously downloaded and extracted package::\n\n sudo python setup.py install\n\nAuthors\n-------\n\nCopyright (c) 2015 Alexander Borzunov\n\nThe library name suggested by `Robert Smallshire`_ (an author of `asq`_).", "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/borzunov/dontasq", "keywords": "LINQ", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "dontasq", "package_url": "https://pypi.org/project/dontasq/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/dontasq/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/borzunov/dontasq" }, "release_url": "https://pypi.org/project/dontasq/0.1/", "requires_dist": null, "requires_python": null, "summary": "Extend built-in Python collections with LINQ-for-objects style methods", "version": "0.1" }, "last_serial": 1747531, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "9c2bc264140c774980a3036c3cdef844", "sha256": "584145809416bf30b07edcbb197d51605bfdb6c360bb48dee04f924636f9ad3e" }, "downloads": -1, "filename": "dontasq-0.1.tar.gz", "has_sig": false, "md5_digest": "9c2bc264140c774980a3036c3cdef844", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5489, "upload_time": "2015-10-01T16:58:03", "url": "https://files.pythonhosted.org/packages/c0/af/d1a093fd0846696c0284beee105b2f9d0ea97e2758a24f44e7b7317aff2a/dontasq-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9c2bc264140c774980a3036c3cdef844", "sha256": "584145809416bf30b07edcbb197d51605bfdb6c360bb48dee04f924636f9ad3e" }, "downloads": -1, "filename": "dontasq-0.1.tar.gz", "has_sig": false, "md5_digest": "9c2bc264140c774980a3036c3cdef844", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5489, "upload_time": "2015-10-01T16:58:03", "url": "https://files.pythonhosted.org/packages/c0/af/d1a093fd0846696c0284beee105b2f9d0ea97e2758a24f44e7b7317aff2a/dontasq-0.1.tar.gz" } ] }