diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2014-02-08 19:05:23 -0500 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2014-02-08 19:05:23 -0500 |
commit | e9c17cbc34ca99d31f351e899eecc0a62d4293bb (patch) | |
tree | 04781d0c298e3d44bbf0f6d639f30559a4b1c6a8 | |
parent | 7529e4109be9537c99217933f6130f7b7f978c05 (diff) | |
parent | c1fdaa5757863528be6718e38b29eca8393e2713 (diff) | |
download | pies-e9c17cbc34ca99d31f351e899eecc0a62d4293bb.tar.gz |
Merge branch 'release/2.6.0'2.6.0
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | pies/__init__.py | 47 | ||||
-rw-r--r-- | pies/_utils.py | 64 | ||||
-rw-r--r-- | pies/functools.py | 23 | ||||
-rw-r--r-- | pies/overrides.py | 43 | ||||
-rw-r--r-- | pies/urllib/request.py | 2 | ||||
-rw-r--r-- | pies2overrides/setup.py | 4 | ||||
-rw-r--r-- | setup.py | 4 |
8 files changed, 102 insertions, 88 deletions
@@ -2,7 +2,8 @@ ==================== [![PyPI version](https://badge.fury.io/py/pies.png)](http://badge.fury.io/py/pies) [![PyPi downloads](https://pypip.in/d/pies/badge.png)](https://crate.io/packages/pies/) -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/timothycrosley/isort/trend.png)](https://bitdeli.com/free "Bitdeli Badge") +[![License](https://pypip.in/license/pies/badge.png)](https://pypi.python.org/pypi/pies/) +[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/timothycrosley/pies/trend.png)](https://bitdeli.com/free "Bitdeli Badge") The simplest (and tastiest) way to write one program that runs on both Python 2.6+ and Python 3. diff --git a/pies/__init__.py b/pies/__init__.py index d768f63..29e7ef4 100644 --- a/pies/__init__.py +++ b/pies/__init__.py @@ -1,32 +1,31 @@ -""" - pies/__init__.py +"""pies/__init__.py. - Adds necessary hooks to allow Python code to run on multiple major versions of Python at once - (currently 2.6 - 3.x) +Adds necessary hooks to allow Python code to run on multiple major versions of Python at once +(currently 2.6 - 3.x) - Usage: - Anywhere you want to gain support for multiple versions of Python simply add the following two lines - from __future__ import absolute_import, division, print_function, unicode_literals - from pies.overrides import * +Usage: + Anywhere you want to gain support for multiple versions of Python simply add the following two lines + from __future__ import absolute_import, division, print_function, unicode_literals + from pies.overrides import * - And for changed stdlibs: - from pies import [libname] + And for changed stdlibs: + from pies import [libname] - Copyright (C) 2013 Timothy Edmund Crosley +Copyright (C) 2013 Timothy Edmund Crosley - 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: +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 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. -""" +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. -__version__ = "2.5.5" +""" +__version__ = "2.6.0" diff --git a/pies/_utils.py b/pies/_utils.py index 2098ccb..0783183 100644 --- a/pies/_utils.py +++ b/pies/_utils.py @@ -1,43 +1,42 @@ -""" - pies/_utils.py +"""pies/_utils.py. + +Utils internal to the pies library and not meant for direct external usage. - Utils internal to the pies library and not meant for direct external usage. +Copyright (C) 2013 Timothy Edmund Crosley - Copyright (C) 2013 Timothy Edmund Crosley +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: - 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 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. - 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. """ import abc import sys def with_metaclass(meta, *bases): - """ - Enables use of meta classes across Python Versions. - taken from jinja2/_compat.py + """Enables use of meta classes across Python Versions. taken from jinja2/_compat.py. + + Use it like this:: - Use it like this:: + class BaseForm(object): + pass - class BaseForm(object): - pass + class FormType(type): + pass - class FormType(type): - pass + class Form(with_metaclass(FormType, BaseForm)): + pass - class Form(with_metaclass(FormType, BaseForm)): - pass """ class metaclass(meta): __call__ = type.__call__ @@ -50,10 +49,12 @@ def with_metaclass(meta, *bases): def unmodified_isinstance(*bases): - """ - When called in the form MyOverrideClass(unmodified_isinstance(BuiltInClass)) + """When called in the form + + MyOverrideClass(unmodified_isinstance(BuiltInClass)) + + it allows calls against passed in built in instances to pass even if there not a subclass - it allows calls against passed in built in instances to pass even if there not a subclass """ class UnmodifiedIsInstance(type): if sys.version_info[0] == 2 and sys.version_info[1] <= 6: @@ -65,7 +66,12 @@ def unmodified_isinstance(*bases): subclass = getattr(instance, '__class__', None) subtype = type(instance) - if subtype is abc._InstanceType: + instance_type = getattr(abc, '_InstanceType', None) + if not instance_type: + class test_object: + pass + instance_type = type(test_object) + if subtype is instance_type: subtype = subclass if subtype is subclass or subclass is None: return cls.__subclasscheck__(subtype) diff --git a/pies/functools.py b/pies/functools.py index 2f2c157..2e79a45 100644 --- a/pies/functools.py +++ b/pies/functools.py @@ -19,19 +19,20 @@ if sys.version_info < (3, 2): def lru_cache(maxsize=100): """Least-recently-used cache decorator. - Taking from: https://github.com/MiCHiLU/python-functools32/blob/master/functools32/functools32.py - with slight modifications. + Taking from: https://github.com/MiCHiLU/python-functools32/blob/master/functools32/functools32.py + with slight modifications. - If *maxsize* is set to None, the LRU features are disabled and the cache - can grow without bound. + If *maxsize* is set to None, the LRU features are disabled and the cache + can grow without bound. - Arguments to the cached function must be hashable. + 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__. + 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 + See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used + """ def decorating_function(user_function, tuple=tuple, sorted=sorted, len=len, KeyError=KeyError): hits, misses = [0], [0] @@ -80,12 +81,12 @@ if sys.version_info < (3, 2): return result def cache_info(): - """Report CACHE statistics""" + """Report CACHE statistics.""" with lock: return _CacheInfo(hits[0], misses[0], maxsize, len(CACHE)) def cache_clear(): - """Clear the CACHE and CACHE statistics""" + """Clear the CACHE and CACHE statistics.""" with lock: CACHE.clear() hits[0] = misses[0] = 0 diff --git a/pies/overrides.py b/pies/overrides.py index c826897..834904b 100644 --- a/pies/overrides.py +++ b/pies/overrides.py @@ -1,23 +1,23 @@ -""" - pies/overrides.py +"""pies/overrides.py. + +Overrides Python syntax to conform to the Python3 version as much as possible using a '*' import - Overrides Python syntax to conform to the Python3 version as much as possible using a '*' import +Copyright (C) 2013 Timothy Edmund Crosley - Copyright (C) 2013 Timothy Edmund Crosley +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: - 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 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. - 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. """ from __future__ import absolute_import @@ -97,6 +97,10 @@ else: range = xrange integer_types = (int, long) + import sys + reload(sys) + sys.setdefaultencoding('utf-8') + def _create_not_allowed(name): def _not_allow(*args, **kwargs): raise NameError("name '{0}' is not defined".format(name)) @@ -211,10 +215,15 @@ else: def __instancecheck__(cls, instance): if cls.__name__ == "object": return isinstance(instance, native_object) - + subclass = getattr(instance, '__class__', None) subtype = type(instance) - if subtype is abc._InstanceType: + instance_type = getattr(abc, '_InstanceType', None) + if not instance_type: + class test_object: + pass + instance_type = type(test_object) + if subtype is instance_type: subtype = subclass if subtype is subclass or subclass is None: return cls.__subclasscheck__(subtype) diff --git a/pies/urllib/request.py b/pies/urllib/request.py index a1470f1..f2ebb61 100644 --- a/pies/urllib/request.py +++ b/pies/urllib/request.py @@ -1,5 +1,3 @@ - - from __future__ import absolute_import from ..version_info import PY3 diff --git a/pies2overrides/setup.py b/pies2overrides/setup.py index 664b697..e8e1062 100644 --- a/pies2overrides/setup.py +++ b/pies2overrides/setup.py @@ -14,12 +14,12 @@ if sys.version_info[0] == 2 and sys.version_info[1] < 7: install_requires += ['ordereddict', 'argparse'] setup(name='pies2overrides', - version='2.5.5', + version='2.6.0', description='Defines override classes that should be included with pies only if running on Python2.', author='Timothy Crosley', author_email='timothy.crosley@gmail.com', url='https://github.com/timothycrosley/pies', - download_url='https://github.com/timothycrosley/pies/blob/master/pies2overrides/dist/pies2overrides-2.5.5.tar.gz?raw=true', + download_url='https://github.com/timothycrosley/pies/blob/master/pies2overrides/dist/pies2overrides-2.6.0.tar.gz?raw=true', license="MIT", install_requires=install_requires, requires=install_requires, @@ -24,13 +24,13 @@ except (IOError, ImportError, OSError, RuntimeError): readme = '' setup(name='pies', - version='2.5.5', + version='2.6.0', description='The simplest way to write one program that runs on both Python 2 and Python 3.', long_description=readme, author='Timothy Crosley', author_email='timothy.crosley@gmail.com', url='https://github.com/timothycrosley/pies', - download_url='https://github.com/timothycrosley/pies/blob/master/dist/pies-2.5.5.tar.gz?raw=true', + download_url='https://github.com/timothycrosley/pies/blob/master/dist/pies-2.6.0.tar.gz?raw=true', license="MIT", install_requires=install_requires, requires=install_requires, |