backports.functools_lru_cache-1.5/0000755000372000037200000000000013235714717020241 5ustar travistravis00000000000000backports.functools_lru_cache-1.5/backports/0000755000372000037200000000000013235714717022231 5ustar travistravis00000000000000backports.functools_lru_cache-1.5/backports/__init__.py0000644000372000037200000000010113235714662024331 0ustar travistravis00000000000000__path__ = __import__('pkgutil').extend_path(__path__, __name__) backports.functools_lru_cache-1.5/backports/functools_lru_cache.py0000644000372000037200000001622513235714662026631 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.5/backports.functools_lru_cache.egg-info/0000755000372000037200000000000013235714717027743 5ustar travistravis00000000000000backports.functools_lru_cache-1.5/backports.functools_lru_cache.egg-info/PKG-INFO0000644000372000037200000000332213235714717031040 0ustar travistravis00000000000000Metadata-Version: 1.2 Name: backports.functools-lru-cache Version: 1.5 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-Content-Type: 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/travis/jaraco/backports.functools_lru_cache/master.svg :target: https://travis-ci.org/jaraco/backports.functools_lru_cache .. .. image:: https://readthedocs.org/projects/backportsfunctools_lru_cache/badge/?version=latest .. :target: https://backportsfunctools_lru_cache.readthedocs.io/en/latest/?badge=latest 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.5/backports.functools_lru_cache.egg-info/SOURCES.txt0000644000372000037200000000107313235714717031630 0ustar travistravis00000000000000.gitignore .readthedocs.yml .travis.yml CHANGES.rst LICENSE 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/namespace_packages.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.5/backports.functools_lru_cache.egg-info/dependency_links.txt0000644000372000037200000000000113235714717034011 0ustar travistravis00000000000000 backports.functools_lru_cache-1.5/backports.functools_lru_cache.egg-info/namespace_packages.txt0000644000372000037200000000000113235714717034265 0ustar travistravis00000000000000 backports.functools_lru_cache-1.5/backports.functools_lru_cache.egg-info/requires.txt0000644000372000037200000000014113235714717032337 0ustar travistravis00000000000000 [docs] sphinx jaraco.packaging>=3.2 rst.linker>=1.9 [testing] pytest>=2.8 collective.checkdocs backports.functools_lru_cache-1.5/backports.functools_lru_cache.egg-info/top_level.txt0000644000372000037200000000001213235714717032466 0ustar travistravis00000000000000backports backports.functools_lru_cache-1.5/docs/0000755000372000037200000000000013235714717021171 5ustar travistravis00000000000000backports.functools_lru_cache-1.5/docs/conf.py0000644000372000037200000000115113235714662022465 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.5/docs/history.rst0000644000372000037200000000012113235714662023415 0ustar travistravis00000000000000:tocdepth: 2 .. _changes: History ******* .. include:: ../CHANGES (links).rst backports.functools_lru_cache-1.5/docs/index.rst0000644000372000037200000000052613235714662023034 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.5/tests/0000755000372000037200000000000013235714717021403 5ustar travistravis00000000000000backports.functools_lru_cache-1.5/tests/test_lru_cache.py0000644000372000037200000000025213235714662024737 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.5/.gitignore0000644000372000037200000000143113235714662022227 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.5/.readthedocs.yml0000644000372000037200000000011213235714662023320 0ustar travistravis00000000000000python: version: 3 extra_requirements: - docs pip_install: true backports.functools_lru_cache-1.5/.travis.yml0000644000372000037200000000223513235714662022353 0ustar travistravis00000000000000dist: trusty sudo: false language: python python: - 2.7 - &latest_py3 3.6 jobs: fast_finish: true include: - stage: deploy if: tag IS present python: *latest_py3 install: skip script: skip deploy: provider: pypi on: tags: true all_branches: true user: jaraco 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= distributions: dists skip_cleanup: true skip_upload_docs: true cache: pip install: - pip install tox tox-venv script: tox backports.functools_lru_cache-1.5/CHANGES.rst0000644000372000037200000000062513235714662022045 0ustar travistravis000000000000001.5 === Refresh package metadata including publishing license with the wheel (#11). 1.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.5/LICENSE0000644000372000037200000000203213235714662021242 0ustar travistravis00000000000000Copyright Jason R. Coombs Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. backports.functools_lru_cache-1.5/README.rst0000644000372000037200000000163413235714662021733 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/travis/jaraco/backports.functools_lru_cache/master.svg :target: https://travis-ci.org/jaraco/backports.functools_lru_cache .. .. image:: https://readthedocs.org/projects/backportsfunctools_lru_cache/badge/?version=latest .. :target: https://backportsfunctools_lru_cache.readthedocs.io/en/latest/?badge=latest 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.5/appveyor.yml0000644000372000037200000000063713235714662022636 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-venv" - "tox" version: '{build}' backports.functools_lru_cache-1.5/pytest.ini0000644000372000037200000000016213235714662022270 0ustar travistravis00000000000000[pytest] norecursedirs=dist build .tox .eggs addopts=--doctest-modules doctest_optionflags=ALLOW_UNICODE ELLIPSIS backports.functools_lru_cache-1.5/setup.cfg0000644000372000037200000000025613235714717022065 0ustar travistravis00000000000000[aliases] release = dists upload dists = clean --all sdist bdist_wheel [bdist_wheel] universal = 1 [metadata] license_file = LICENSE [egg_info] tag_build = tag_date = 0 backports.functools_lru_cache-1.5/setup.py0000644000372000037200000000274213235714662021757 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 = '' nspkg_technique = 'native' """ Does this package use "native" namespace packages or pkg_resources "managed" namespace packages? """ 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, namespace_packages=( name.split('.')[:-1] if nspkg_technique == 'managed' else [] ), python_requires='>=2.6', install_requires=[ ], extras_require={ 'testing': [ 'pytest>=2.8', # 'pytest-sugar', 'collective.checkdocs', ], '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.5/tox.ini0000644000372000037200000000045013235714662021552 0ustar travistravis00000000000000[tox] envlist = python minversion = 2.4 [testenv] deps = setuptools>=31.0.1 commands = py.test {posargs} python setup.py checkdocs usedevelop = True extras = testing [testenv:build-docs] extras = docs testing changedir = docs commands = python -m sphinx . {toxinidir}/build/html backports.functools_lru_cache-1.5/PKG-INFO0000644000372000037200000000332213235714717021336 0ustar travistravis00000000000000Metadata-Version: 1.2 Name: backports.functools_lru_cache Version: 1.5 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-Content-Type: 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/travis/jaraco/backports.functools_lru_cache/master.svg :target: https://travis-ci.org/jaraco/backports.functools_lru_cache .. .. image:: https://readthedocs.org/projects/backportsfunctools_lru_cache/badge/?version=latest .. :target: https://backportsfunctools_lru_cache.readthedocs.io/en/latest/?badge=latest 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