backports.functools_lru_cache-1.4/0000755000175000017500000000000013105455640020233 5ustar travistravis00000000000000backports.functools_lru_cache-1.4/backports/0000755000175000017500000000000013105455640022223 5ustar travistravis00000000000000backports.functools_lru_cache-1.4/backports/__init__.py0000644000175000017500000000010113105455567024334 0ustar travistravis00000000000000__path__ = __import__('pkgutil').extend_path(__path__, __name__) backports.functools_lru_cache-1.4/backports/functools_lru_cache.py0000644000175000017500000001622513105455567026634 0ustar travistravis00000000000000from __future__ import absolute_import import functools from collections import namedtuple from threading import RLock _CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"]) @functools.wraps(functools.update_wrapper) def update_wrapper(wrapper, wrapped, assigned = functools.WRAPPER_ASSIGNMENTS, updated = functools.WRAPPER_UPDATES): """ Patch two bugs in functools.update_wrapper. """ # workaround for http://bugs.python.org/issue3445 assigned = tuple(attr for attr in assigned if hasattr(wrapped, attr)) wrapper = functools.update_wrapper(wrapper, wrapped, assigned, updated) # workaround for https://bugs.python.org/issue17482 wrapper.__wrapped__ = wrapped return wrapper class _HashedSeq(list): __slots__ = 'hashvalue' def __init__(self, tup, hash=hash): self[:] = tup self.hashvalue = hash(tup) def __hash__(self): return self.hashvalue def _make_key(args, kwds, typed, kwd_mark=(object(),), fasttypes=set([int, str, frozenset, type(None)]), sorted=sorted, tuple=tuple, type=type, len=len): 'Make a cache key from optionally typed positional and keyword arguments' key = args if kwds: sorted_items = sorted(kwds.items()) key += kwd_mark for item in sorted_items: key += item if typed: key += tuple(type(v) for v in args) if kwds: key += tuple(type(v) for k, v in sorted_items) elif len(key) == 1 and type(key[0]) in fasttypes: return key[0] return _HashedSeq(key) def lru_cache(maxsize=100, typed=False): """Least-recently-used cache decorator. If *maxsize* is set to None, the LRU features are disabled and the cache can grow without bound. If *typed* is True, arguments of different types will be cached separately. For example, f(3.0) and f(3) will be treated as distinct calls with distinct results. Arguments to the cached function must be hashable. View the cache statistics named tuple (hits, misses, maxsize, currsize) with f.cache_info(). Clear the cache and statistics with f.cache_clear(). Access the underlying function with f.__wrapped__. See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used """ # Users should only access the lru_cache through its public API: # cache_info, cache_clear, and f.__wrapped__ # The internals of the lru_cache are encapsulated for thread safety and # to allow the implementation to change (including a possible C version). def decorating_function(user_function): cache = dict() stats = [0, 0] # make statistics updateable non-locally HITS, MISSES = 0, 1 # names for the stats fields make_key = _make_key cache_get = cache.get # bound method to lookup key or return None _len = len # localize the global len() function lock = RLock() # because linkedlist updates aren't threadsafe root = [] # root of the circular doubly linked list root[:] = [root, root, None, None] # initialize by pointing to self nonlocal_root = [root] # make updateable non-locally PREV, NEXT, KEY, RESULT = 0, 1, 2, 3 # names for the link fields if maxsize == 0: def wrapper(*args, **kwds): # no caching, just do a statistics update after a successful call result = user_function(*args, **kwds) stats[MISSES] += 1 return result elif maxsize is None: def wrapper(*args, **kwds): # simple caching without ordering or size limit key = make_key(args, kwds, typed) result = cache_get(key, root) # root used here as a unique not-found sentinel if result is not root: stats[HITS] += 1 return result result = user_function(*args, **kwds) cache[key] = result stats[MISSES] += 1 return result else: def wrapper(*args, **kwds): # size limited caching that tracks accesses by recency key = make_key(args, kwds, typed) if kwds or typed else args with lock: link = cache_get(key) if link is not None: # record recent use of the key by moving it to the front of the list root, = nonlocal_root link_prev, link_next, key, result = link link_prev[NEXT] = link_next link_next[PREV] = link_prev last = root[PREV] last[NEXT] = root[PREV] = link link[PREV] = last link[NEXT] = root stats[HITS] += 1 return result result = user_function(*args, **kwds) with lock: root, = nonlocal_root if key in cache: # getting here means that this same key was added to the # cache while the lock was released. since the link # update is already done, we need only return the # computed result and update the count of misses. pass elif _len(cache) >= maxsize: # use the old root to store the new key and result oldroot = root oldroot[KEY] = key oldroot[RESULT] = result # empty the oldest link and make it the new root root = nonlocal_root[0] = oldroot[NEXT] oldkey = root[KEY] root[KEY] = root[RESULT] = None # now update the cache dictionary for the new links del cache[oldkey] cache[key] = oldroot else: # put result in a new link at the front of the list last = root[PREV] link = [last, root, key, result] last[NEXT] = root[PREV] = cache[key] = link stats[MISSES] += 1 return result def cache_info(): """Report cache statistics""" with lock: return _CacheInfo(stats[HITS], stats[MISSES], maxsize, len(cache)) def cache_clear(): """Clear the cache and cache statistics""" with lock: cache.clear() root = nonlocal_root[0] root[:] = [root, root, None, None] stats[:] = [0, 0] wrapper.__wrapped__ = user_function wrapper.cache_info = cache_info wrapper.cache_clear = cache_clear return update_wrapper(wrapper, user_function) return decorating_function backports.functools_lru_cache-1.4/backports.functools_lru_cache.egg-info/0000755000175000017500000000000013105455640027735 5ustar travistravis00000000000000backports.functools_lru_cache-1.4/backports.functools_lru_cache.egg-info/PKG-INFO0000644000175000017500000000350113105455640031031 0ustar travistravis00000000000000Metadata-Version: 1.2 Name: backports.functools-lru-cache Version: 1.4 Summary: backports.functools_lru_cache Home-page: https://github.com/jaraco/backports.functools_lru_cache Author: Jason R. Coombs Author-email: jaraco@jaraco.com License: UNKNOWN Description: .. image:: https://img.shields.io/pypi/v/backports.functools_lru_cache.svg :target: https://pypi.org/project/backports.functools_lru_cache .. image:: https://img.shields.io/pypi/pyversions/backports.functools_lru_cache.svg .. image:: https://img.shields.io/pypi/dm/backports.functools_lru_cache.svg .. image:: https://img.shields.io/travis/jaraco/backports.functools_lru_cache/master.svg :target: http://travis-ci.org/jaraco/backports.functools_lru_cache License ======= License is indicated in the project metadata (typically one or more of the Trove classifiers). For more details, see `this explanation `_. Backport of functools.lru_cache from Python 3.3 as published at `ActiveState `_. Usage ----- Consider using this technique for importing the 'lru_cache' function:: try: from functools import lru_cache except ImportError: from backports.functools_lru_cache import lru_cache Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Requires-Python: >=2.6 backports.functools_lru_cache-1.4/backports.functools_lru_cache.egg-info/SOURCES.txt0000644000175000017500000000076513105455640031631 0ustar travistravis00000000000000.gitignore .readthedocs.yml .travis.yml CHANGES.rst README.rst appveyor.yml pytest.ini setup.cfg setup.py tox.ini backports/__init__.py backports/functools_lru_cache.py backports.functools_lru_cache.egg-info/PKG-INFO backports.functools_lru_cache.egg-info/SOURCES.txt backports.functools_lru_cache.egg-info/dependency_links.txt backports.functools_lru_cache.egg-info/requires.txt backports.functools_lru_cache.egg-info/top_level.txt docs/conf.py docs/history.rst docs/index.rst tests/test_lru_cache.pybackports.functools_lru_cache-1.4/backports.functools_lru_cache.egg-info/dependency_links.txt0000644000175000017500000000000113105455640034003 0ustar travistravis00000000000000 backports.functools_lru_cache-1.4/backports.functools_lru_cache.egg-info/requires.txt0000644000175000017500000000013113105455640032330 0ustar travistravis00000000000000 [docs] sphinx jaraco.packaging>=3.2 rst.linker>=1.9 [testing] pytest>=2.8 pytest-sugar backports.functools_lru_cache-1.4/backports.functools_lru_cache.egg-info/top_level.txt0000644000175000017500000000001213105455640032460 0ustar travistravis00000000000000backports backports.functools_lru_cache-1.4/docs/0000755000175000017500000000000013105455640021163 5ustar travistravis00000000000000backports.functools_lru_cache-1.4/docs/conf.py0000644000175000017500000000116213105455567022472 0ustar travistravis00000000000000#!/usr/bin/env python3 # -*- coding: utf-8 -*- extensions = [ 'sphinx.ext.autodoc', 'jaraco.packaging.sphinx', 'rst.linker', ] master_doc = 'index' link_files = { '../CHANGES.rst': dict( using=dict( GH='https://github.com', ), replace=[ dict( pattern=r'(Issue )?#(?P\d+)', url='{package_url}/issues/{issue}', ), dict( pattern=r'^(?m)((?Pv?\d+(\.\d+){1,2}))\n[-=]+\n', with_scm='{text}\n{rev[timestamp]:%d %b %Y}\n', ), dict( pattern=r'PEP[- ](?P\d+)', url='https://www.python.org/dev/peps/pep-{pep_number:0>4}/', ), ], ), } backports.functools_lru_cache-1.4/docs/history.rst0000644000175000017500000000012113105455567023420 0ustar travistravis00000000000000:tocdepth: 2 .. _changes: History ******* .. include:: ../CHANGES (links).rst backports.functools_lru_cache-1.4/docs/index.rst0000644000175000017500000000052613105455567023037 0ustar travistravis00000000000000Welcome to backports.functools_lru_cache documentation! ============================================ .. toctree:: :maxdepth: 1 history .. automodule:: backports.functools_lru_cache :members: :undoc-members: :show-inheritance: Indices and tables ================== * :ref:`genindex` * :ref:`modindex` * :ref:`search` backports.functools_lru_cache-1.4/tests/0000755000175000017500000000000013105455640021375 5ustar travistravis00000000000000backports.functools_lru_cache-1.4/tests/test_lru_cache.py0000644000175000017500000000025213105455567024742 0ustar travistravis00000000000000import random from backports.functools_lru_cache import lru_cache def test_invocation(): @lru_cache() def func(): return random.random() assert func() == func() backports.functools_lru_cache-1.4/.gitignore0000644000175000017500000000143113105455567022232 0ustar travistravis00000000000000 # Created by https://www.gitignore.io/api/python ### Python ### # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python env/ build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .installed.cfg *.egg # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *,cover .hypothesis/ # Translations *.mo *.pot # Django stuff: *.log # Sphinx documentation docs/_build/ # PyBuilder target/ backports.functools_lru_cache-1.4/.readthedocs.yml0000644000175000017500000000011213105455567023323 0ustar travistravis00000000000000python: version: 3 extra_requirements: - docs pip_install: true backports.functools_lru_cache-1.4/.travis.yml0000644000175000017500000000202713105455567022355 0ustar travistravis00000000000000sudo: false language: python python: - 2.6 - 2.7 - 3.6 install: - pip install tox "setuptools>=28.2" script: - tox branches: except: - skeleton deploy: provider: pypi server: https://upload.pypi.org/legacy/ on: tags: true all_branches: true python: 3.6 user: jaraco distributions: dists skip_upload_docs: true password: secure: mJUt/9xGGfOMjAug7PEJojli2VgQyoCKx88amgK595lfdK/cAmTGi/na3Hw3Kt/7bfNjGCWyYzoXZ1VAhCDiiG8mOnWszTSNoeQSS4NCTkR7f1oUEo7izLrsGpEs8aveXY3XlqW5VTnssaL526ju5vIXDPKvhqvLrYkd7mP62HcL3rbSJM72D54OUVVX0gEKf4swgwjQe6xNQyRQpq/QcIKXxqgKF3/qIbnJQWGv7tDuxaWLghh2gx3oBNZVmQKBWfokwjp+PWV7zqIrE2o5sZ5Jkh+kt5+UOVDyMh/3Fd4s2G6ZD6asDRA5QBQxo/QtF2fQsi8heE4VgChRrnKzYXAZN1CSEj9i7BgBq2nbRod5WqlCR44zC44A4qS+D5ZlZVdmamZY9ni2/vZ6xMxl4m8Yk30xBHIoo+huJjLimnOETp9YTArMlebfPetCE6C6Tu3rmVoftiW2npjaBBxDCglSdRmluf+fsuw/Sq77p0q6nBZ2TxlWGxT0QUAF8u41I0I/n+B5rart/H1Yf3HvBAiGf8omU7QrsbA496hgIHY0r2LUsVre7IwjYYyUM6xqd9m7T8yX5yQNijp/rpvHnwcgRvd6WdHJ1BtnoYaAHWmROwC5PFz9mWB3Cw5csPylaC7gOkvD8LkjUk9zOx3C8/TUlr/QmxAAdOooqFey3kY= backports.functools_lru_cache-1.4/CHANGES.rst0000644000175000017500000000047713105455567022055 0ustar travistravis000000000000001.4 === #9: Updated namespace package to use pkgutil for declaring the namespace. 1.3 === Tagged commits are automatically released following passing tests. 1.2 === Issue #5: Added a minimal test suite. 1.1 === Moved hosting to Github. Library uses setuptools_scm for version tagging. Added license declaration. backports.functools_lru_cache-1.4/README.rst0000644000175000017500000000176513105455567021743 0ustar travistravis00000000000000.. image:: https://img.shields.io/pypi/v/backports.functools_lru_cache.svg :target: https://pypi.org/project/backports.functools_lru_cache .. image:: https://img.shields.io/pypi/pyversions/backports.functools_lru_cache.svg .. image:: https://img.shields.io/pypi/dm/backports.functools_lru_cache.svg .. image:: https://img.shields.io/travis/jaraco/backports.functools_lru_cache/master.svg :target: http://travis-ci.org/jaraco/backports.functools_lru_cache License ======= License is indicated in the project metadata (typically one or more of the Trove classifiers). For more details, see `this explanation `_. Backport of functools.lru_cache from Python 3.3 as published at `ActiveState `_. Usage ----- Consider using this technique for importing the 'lru_cache' function:: try: from functools import lru_cache except ImportError: from backports.functools_lru_cache import lru_cache backports.functools_lru_cache-1.4/appveyor.yml0000644000175000017500000000060213105455567022631 0ustar travistravis00000000000000environment: APPVEYOR: true matrix: - PYTHON: "C:\\Python36-x64" - PYTHON: "C:\\Python27-x64" install: # symlink python from a directory with a space - "mklink /d \"C:\\Program Files\\Python\" %PYTHON%" - "SET PYTHON=\"C:\\Program Files\\Python\"" - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" build: off test_script: - "python -m pip install tox" - "tox" backports.functools_lru_cache-1.4/pytest.ini0000644000175000017500000000015413105455567022274 0ustar travistravis00000000000000[pytest] norecursedirs=dist build .tox addopts=--doctest-modules doctest_optionflags=ALLOW_UNICODE ELLIPSIS backports.functools_lru_cache-1.4/setup.cfg0000644000175000017500000000020513105455640022051 0ustar travistravis00000000000000[aliases] release = dists upload dists = clean --all sdist bdist_wheel [wheel] universal = 1 [egg_info] tag_build = tag_date = 0 backports.functools_lru_cache-1.4/setup.py0000644000175000017500000000234613105455567021762 0ustar travistravis00000000000000#!/usr/bin/env python # Project skeleton maintained at https://github.com/jaraco/skeleton import io import setuptools with io.open('README.rst', encoding='utf-8') as readme: long_description = readme.read() name = 'backports.functools_lru_cache' description = '' params = dict( name=name, use_scm_version=True, author="Raymond Hettinger", author_email="raymond.hettinger@gmail.com", maintainer="Jason R. Coombs", maintainer_email="jaraco@jaraco.com", description=description or name, long_description=long_description, url="https://github.com/jaraco/" + name, packages=setuptools.find_packages(), include_package_data=True, python_requires='>=2.6', install_requires=[ ], extras_require={ 'testing': [ 'pytest>=2.8', 'pytest-sugar', ], 'docs': [ 'sphinx', 'jaraco.packaging>=3.2', 'rst.linker>=1.9', ], }, setup_requires=[ 'setuptools_scm>=1.15.0', ], classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", ], entry_points={ }, ) if __name__ == '__main__': setuptools.setup(**params) backports.functools_lru_cache-1.4/tox.ini0000644000175000017500000000014213105455567021553 0ustar travistravis00000000000000[tox] minversion = 2.4 [testenv] commands = py.test {posargs} usedevelop = True extras = testing backports.functools_lru_cache-1.4/PKG-INFO0000644000175000017500000000350113105455640021327 0ustar travistravis00000000000000Metadata-Version: 1.2 Name: backports.functools_lru_cache Version: 1.4 Summary: backports.functools_lru_cache Home-page: https://github.com/jaraco/backports.functools_lru_cache Author: Jason R. Coombs Author-email: jaraco@jaraco.com License: UNKNOWN Description: .. image:: https://img.shields.io/pypi/v/backports.functools_lru_cache.svg :target: https://pypi.org/project/backports.functools_lru_cache .. image:: https://img.shields.io/pypi/pyversions/backports.functools_lru_cache.svg .. image:: https://img.shields.io/pypi/dm/backports.functools_lru_cache.svg .. image:: https://img.shields.io/travis/jaraco/backports.functools_lru_cache/master.svg :target: http://travis-ci.org/jaraco/backports.functools_lru_cache License ======= License is indicated in the project metadata (typically one or more of the Trove classifiers). For more details, see `this explanation `_. Backport of functools.lru_cache from Python 3.3 as published at `ActiveState `_. Usage ----- Consider using this technique for importing the 'lru_cache' function:: try: from functools import lru_cache except ImportError: from backports.functools_lru_cache import lru_cache Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Requires-Python: >=2.6