diff options
author | Tres Seaver <tseaver@palladion.com> | 2009-05-13 22:49:50 +0000 |
---|---|---|
committer | Tres Seaver <tseaver@palladion.com> | 2009-05-13 22:49:50 +0000 |
commit | 50e7b6955cc0f398693f158ba1cae1ab35793183 (patch) | |
tree | a1a9cc06e7efe15f2f89a209b4051be94ae9fa01 | |
parent | e2e12dc280e94bb8f65fecdfe417c3bded9239e4 (diff) | |
download | zope-security-50e7b6955cc0f398693f158ba1cae1ab35793183.tar.gz |
Made ``pytz`` a soft dependency.
The checker for ``pytz.UTC`` is created / tested only if the package
is already present.
Run ``bin/test_pytz`` to run the tests with ``pytz`` on the path.
-rw-r--r-- | CHANGES.txt | 4 | ||||
-rw-r--r-- | buildout.cfg | 6 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | src/zope/security/checker.py | 15 | ||||
-rw-r--r-- | src/zope/security/tests/test_standard_checkers.py | 7 |
5 files changed, 25 insertions, 9 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index ce33a27..98432c3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,7 +5,9 @@ CHANGES 3.6.4 (unreleased) ------------------ -- None so far. +- Made ``pytz`` a soft dependency: the checker for ``pytz.UTC`` is + created / tested only if the package is already present. Run + ``bin/test_pytz`` to run the tests with ``pytz`` on the path. 3.6.3 (2009-03-23) ------------------ diff --git a/buildout.cfg b/buildout.cfg index dbd6e62..58536c2 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -1,11 +1,15 @@ [buildout] develop = . -parts = test python coverage-test coverage-report +parts = test test_pytz python coverage-test coverage-report [test] recipe = zc.recipe.testrunner eggs = zope.security [test] +[test_pytz] +recipe = zc.recipe.testrunner +eggs = zope.security [test,pytz] + [python] recipe = zc.recipe.egg eggs = zope.security [untrustedpython] @@ -61,7 +61,6 @@ setup(name='zope.security', ]), ], install_requires=['setuptools', - 'pytz', 'zope.component', 'zope.configuration', 'zope.exceptions', @@ -74,6 +73,7 @@ setup(name='zope.security', extras_require = dict( untrustedpython=["RestrictedPython"], test=["RestrictedPython"], + pytz=["pytz"], ), include_package_data = True, zip_safe = False, diff --git a/src/zope/security/checker.py b/src/zope/security/checker.py index 603c37d..21840de 100644 --- a/src/zope/security/checker.py +++ b/src/zope/security/checker.py @@ -30,7 +30,6 @@ import sys import types import datetime import decimal -import pytz import weakref from zope.exceptions import DuplicationError @@ -605,7 +604,7 @@ class BasicTypes(dict): super(BasicTypes.__class__, self).update(d) _checkers.update(d) -BasicTypes = BasicTypes({ +_basic_types = { object: NoProxy, int: NoProxy, float: NoProxy, @@ -621,8 +620,16 @@ BasicTypes = BasicTypes({ datetime.date: NoProxy, datetime.time: NoProxy, datetime.tzinfo: NoProxy, - type(pytz.UTC): NoProxy, -}) +} +try: + import pytz +except ImportError: + pass +else: + _basic_types[type(pytz.UTC)] = NoProxy + +BasicTypes = BasicTypes(_basic_types) +del _basic_types # Available for tests. Located here so it can be kept in sync with BasicTypes. BasicTypes_examples = { diff --git a/src/zope/security/tests/test_standard_checkers.py b/src/zope/security/tests/test_standard_checkers.py index 3c33948..108fee2 100644 --- a/src/zope/security/tests/test_standard_checkers.py +++ b/src/zope/security/tests/test_standard_checkers.py @@ -421,8 +421,11 @@ def test_rocks(): >>> int(type(ProxyFactory( tzinfo() )) is tzinfo) 1 - >>> from pytz import UTC - >>> int(type(ProxyFactory( UTC )) is type(UTC)) + >>> try: + ... from pytz import UTC + ... except ImportError: # pytz checker only if pytz is present. + ... UTC = None + >>> int(UTC is None or type(ProxyFactory( UTC )) is type(UTC)) 1 """ |