{ "info": { "author": "Quora, Inc.", "author_email": "asynq@quora.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5" ], "description": "*****\nqcore\n*****\n.. image:: https://travis-ci.org/quora/qcore.svg?branch=master\n :target: https://travis-ci.org/quora/qcore\n\n``qcore`` is a library of common utility functions used at Quora. It is used to\nabstract out common functionality for other Quora libraries like `asynq `_.\n\nIts component modules are discussed below. See the docstrings in the code\nitself for more detail.\n\nqcore.asserts\n-------------\n\nWhen a normal Python assert fails, it only indicates that there was a failure,\nnot what the bad values were that caused the assert to fail. This module\nprovides rich assertion helpers that automatically produce better error\nmessages. For example:\n\n.. code-block:: python\n\n >>> from qcore.asserts import assert_eq\n >>> assert 5 == 2 * 2\n Traceback (most recent call last):\n File \"\", line 1, in \n AssertionError\n >>> assert_eq(5, 2 * 2)\n Traceback (most recent call last):\n File \"\", line 1, in \n File \"qcore/asserts.py\", line 82, in assert_eq\n assert expected == actual, _assert_fail_message(message, expected, actual, '!=', extra)\n AssertionError: 5 != 4\n\nSimilar methods are provided by the standard library's ``unittest`` package,\nbut those are tied to the ``TestCase`` class instead of being standalone\nfunctions.\n\nqcore.caching\n-------------\n\nThis provides helpers for caching data. Some examples include:\n\n.. code-block:: python\n\n from qcore.caching import cached_per_instance, lazy_constant\n\n @lazy_constant\n def some_function():\n # this will only be executed the first time some_function() is called;\n # afterwards it will be cached\n return expensive_computation()\n\n class SomeClass(object):\n @cached_per_instance()\n def some_method(self, a, b):\n # for any instance of SomeClass, this will only be executed once\n return expensive_computation(a, b)\n\nqcore.debug\n-----------\n\nThis module provides some helpers useful for debugging Python. Among others, it\nincludes the ``@qcore.debug.trace()`` decorator, which can be used to trace\nevery time a function is called.\n\nqcore.decorators\n----------------\n\nThis module provides an abstraction for class-based decorators that supports\ntransparently decorating functions, methods, classmethods, and staticmethods\nwhile also providing the option to add additional custom attributes. For\nexample, it could be used to provide a caching decorator that adds a ``.dirty``\nattribute to decorated functions to dirty their cache:\n\n.. code-block:: python\n\n from qcore.decorators import DecoratorBase, DecoratorBinder, decorate\n\n class CacheDecoratorBinder(DecoratorBinder):\n def dirty(self, *args):\n if self.instance is None:\n return self.decorator.dirty(*args)\n else:\n return self.decorator.dirty(self.instance, *args)\n\n class CacheDecorator(DecoratorBase):\n binder_cls = CacheDecoratorBinder\n\n def __init__(self, *args):\n super(CacheDecorator, self).__init__(*args)\n self._cache = {}\n\n def dirty(self, *args):\n try:\n del self._cache[args]\n except KeyError:\n pass\n\n def __call__(self, *args):\n try:\n return self._cache[args]\n except KeyError:\n value = self.fn(*args)\n self._cache[args] = value\n return value\n\n cached = decorate(CacheDecorator)\n\nqcore.enum\n----------\n\nThis module provides an abstraction for defining enums. You can define an enum\nas follows:\n\n.. code-block:: python\n\n from qcore.enum import Enum\n\n class Color(Enum):\n red = 1\n green = 2\n blue = 3\n\nqcore.errors\n------------\n\nThis module provides some commonly useful exception classes and helpers for\nreraising exceptions from a different place.\n\nqcore.events\n------------\n\nThis provides an abstraction for registering events and running callbacks.\nExample usage:\n\n.. code-block:: python\n\n >>> from qcore.events import EventHook\n >>> event = EventHook()\n >>> def callback():\n ... print('callback called')\n ...\n >>> event.subscribe(callback)\n >>> event.trigger()\n callback called\n\nqcore.helpers\n-------------\n\nThis provides a number of small helper functions.\n\nqcore.inspectable_class\n-----------------------\n\nThis provides a base class that automatically provides hashing, equality\nchecks, and a readable ``repr()`` result. Example usage:\n\n.. code-block:: python\n\n >>> from qcore.inspectable_class import InspectableClass\n >>> class Pair(InspectableClass):\n ... def __init__(self, a, b):\n ... self.a = a\n ... self.b = b\n ...\n >>> Pair(1, 2)\n Pair(a=1, b=2)\n >>> Pair(1, 2) == Pair(1, 2)\n True\n\nqcore.inspection\n----------------\n\nThis provides functionality similar to the standard ``inspect`` module. Among\nothers, it includes the ``get_original_fn`` function, which extracts the\nunderlying function from a ``qcore.decorators``-decorated object.\n\nqcore.microtime\n---------------\n\nThis includes helpers for dealing with time, represented as an integer number\nof microseconds since the Unix epoch.\n\nqcore.testing\n-------------\n\nThis provides helpers to use in unit tests. Among others, it provides an\n``Anything`` object that compares equal to any other Python object.", "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/quora/qcore", "keywords": "quora core common utility", "license": "Apache Software License", "maintainer": null, "maintainer_email": null, "name": "qcore-nocython", "package_url": "https://pypi.org/project/qcore-nocython/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/qcore-nocython/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/quora/qcore" }, "release_url": "https://pypi.org/project/qcore-nocython/0.3.0/", "requires_dist": null, "requires_python": null, "summary": "Quora's core utility library", "version": "0.3.0" }, "last_serial": 2619663, "releases": { "0.3.0": [ { "comment_text": "", "digests": { "md5": "1021a8200b5a72df6ead7f63708c9f3f", "sha256": "dd7a94b3a7eac4f6088e0ef53930e35c6b4b18a071f42d595a4363052131a5ba" }, "downloads": -1, "filename": "qcore-nocython-0.3.0.tar.gz", "has_sig": false, "md5_digest": "1021a8200b5a72df6ead7f63708c9f3f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 27042, "upload_time": "2017-02-04T22:58:54", "url": "https://files.pythonhosted.org/packages/11/f9/65caa31ac429694ace172042c0bdd3e69e6e6aa5bdbf1df5f018dbaadc23/qcore-nocython-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1021a8200b5a72df6ead7f63708c9f3f", "sha256": "dd7a94b3a7eac4f6088e0ef53930e35c6b4b18a071f42d595a4363052131a5ba" }, "downloads": -1, "filename": "qcore-nocython-0.3.0.tar.gz", "has_sig": false, "md5_digest": "1021a8200b5a72df6ead7f63708c9f3f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 27042, "upload_time": "2017-02-04T22:58:54", "url": "https://files.pythonhosted.org/packages/11/f9/65caa31ac429694ace172042c0bdd3e69e6e6aa5bdbf1df5f018dbaadc23/qcore-nocython-0.3.0.tar.gz" } ] }