diff options
author | Eli Collins <elic@assurancetechnologies.com> | 2011-12-06 16:08:52 -0500 |
---|---|---|
committer | Eli Collins <elic@assurancetechnologies.com> | 2011-12-06 16:08:52 -0500 |
commit | c5ec1f9c49522a357075c9a0353b028f930e04ad (patch) | |
tree | 936e96672725980be447a6601ca80444a8f36040 | |
parent | e2f085dd5606c4c1547803cfcbddd5796009f50f (diff) | |
download | passlib-c5ec1f9c49522a357075c9a0353b028f930e04ad.tar.gz |
added compat.unicode imports in a number of places
this distinguishes the types, so that for isinstance() tests...
* 'unicode' always means the unicode type
* 'bytes' always means the bytes type
* 'str' always means the native string type
27 files changed, 33 insertions, 16 deletions
diff --git a/passlib/apache.py b/passlib/apache.py index b43e04d..1d50c8f 100644 --- a/passlib/apache.py +++ b/passlib/apache.py @@ -13,7 +13,7 @@ import sys from passlib.context import CryptContext from passlib.utils import render_bytes, bjoin, bytes, b, \ to_unicode, to_bytes, consteq -from passlib.utils.compat import lmap +from passlib.utils.compat import lmap, unicode #pkg #local __all__ = [ @@ -85,7 +85,7 @@ class _CommonFile(object): passwords will be loaded directly from this string, and any files will be ignored. """ - if isinstance(content, unicode): + if instance(content, unicode): content = content.encode(self.encoding or 'utf-8') self.mtime = 0 #XXX: replace this with iterator? diff --git a/passlib/context.py b/passlib/context.py index ca02a1e..ea666e6 100644 --- a/passlib/context.py +++ b/passlib/context.py @@ -20,10 +20,10 @@ except ImportError: resource_string = None #libs from passlib.registry import get_crypt_handler, _unload_handler_name -from passlib.utils import to_bytes, to_unicode, bytes, Undef, \ +from passlib.utils import to_bytes, to_unicode, Undef, \ is_crypt_handler, splitcomma, rng from passlib.utils.compat import is_mapping, iteritems, int_types, \ - PY3, PY_MIN_32 + PY3, PY_MIN_32, unicode, bytes from passlib.utils.compat.aliases import SafeConfigParser, StringIO, BytesIO #pkg #local diff --git a/passlib/ext/django/models.py b/passlib/ext/django/models.py index 76117bd..b86a796 100644 --- a/passlib/ext/django/models.py +++ b/passlib/ext/django/models.py @@ -16,6 +16,7 @@ from django.conf import settings #pkg from passlib.context import CryptContext, CryptPolicy from passlib.utils import is_crypt_context, bytes +from passlib.utils.compat import sb_types, unicode from passlib.ext.django.utils import DEFAULT_CTX, get_category, \ set_django_password_context @@ -34,7 +35,7 @@ def patch(): return if ctx == "passlib-default": ctx = DEFAULT_CTX - if isinstance(ctx, (unicode, bytes)): + if isinstance(ctx, sb_types): ctx = CryptPolicy.from_string(ctx) if isinstance(ctx, CryptPolicy): ctx = CryptContext(policy=ctx) diff --git a/passlib/handlers/bcrypt.py b/passlib/handlers/bcrypt.py index faee765..5119b01 100644 --- a/passlib/handlers/bcrypt.py +++ b/passlib/handlers/bcrypt.py @@ -28,6 +28,7 @@ except ImportError: #pragma: no cover - though should run whole suite w/o bcrypt #libs from passlib.utils import safe_os_crypt, classproperty, handlers as uh, \ h64, to_hash_str, rng, getrandstr, bytes +from passlib.utils.compat import unicode #pkg #local diff --git a/passlib/handlers/des_crypt.py b/passlib/handlers/des_crypt.py index ca095c3..e5b461f 100644 --- a/passlib/handlers/des_crypt.py +++ b/passlib/handlers/des_crypt.py @@ -60,6 +60,7 @@ from warnings import warn #libs from passlib.utils import h64, classproperty, safe_os_crypt, b, bytes, \ to_hash_str, handlers as uh, bord +from passlib.utils.compat import unicode from passlib.utils.des import mdes_encrypt_int_block #pkg #local @@ -336,7 +337,7 @@ class bsdi_crypt(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, uh.GenericHandler def _has_backend_os_crypt(cls): h = u'_/...lLDAxARksGCHin.' return bool(safe_os_crypt and safe_os_crypt(u"test",h)[1]==h) - + def _calc_checksum_builtin(self, secret): if isinstance(secret, unicode): secret = secret.encode("utf-8") diff --git a/passlib/handlers/digests.py b/passlib/handlers/digests.py index 28bc1b1..bbee12f 100644 --- a/passlib/handlers/digests.py +++ b/passlib/handlers/digests.py @@ -10,6 +10,7 @@ from warnings import warn #site #libs from passlib.utils import handlers as uh, to_hash_str, bytes +from passlib.utils.compat import unicode from passlib.utils.md4 import md4 #pkg #local diff --git a/passlib/handlers/django.py b/passlib/handlers/django.py index 823463b..2149da2 100644 --- a/passlib/handlers/django.py +++ b/passlib/handlers/django.py @@ -10,6 +10,7 @@ from warnings import warn #site #libs from passlib.utils import h64, handlers as uh, b, bytes, to_unicode, to_hash_str +from passlib.utils.compat import unicode #pkg #local __all__ = [ diff --git a/passlib/handlers/fshp.py b/passlib/handlers/fshp.py index e9bc23c..46a3413 100644 --- a/passlib/handlers/fshp.py +++ b/passlib/handlers/fshp.py @@ -12,7 +12,7 @@ from warnings import warn #site #libs from passlib.utils import handlers as uh, bytes, b, to_hash_str -from passlib.utils.compat import iteritems +from passlib.utils.compat import iteritems, unicode from passlib.utils.pbkdf2 import pbkdf1 #pkg #local diff --git a/passlib/handlers/ldap_digests.py b/passlib/handlers/ldap_digests.py index 148e288..4964c02 100644 --- a/passlib/handlers/ldap_digests.py +++ b/passlib/handlers/ldap_digests.py @@ -12,6 +12,7 @@ from warnings import warn #site #libs from passlib.utils import handlers as uh, unix_crypt_schemes, b, bytes, to_hash_str +from passlib.utils.compat import unicode #pkg #local __all__ = [ diff --git a/passlib/handlers/md5_crypt.py b/passlib/handlers/md5_crypt.py index 08b5e34..bef6baa 100644 --- a/passlib/handlers/md5_crypt.py +++ b/passlib/handlers/md5_crypt.py @@ -11,7 +11,7 @@ from warnings import warn #libs from passlib.utils import b, bytes, to_bytes, h64, safe_os_crypt, \ classproperty, handlers as uh -from passlib.utils.compat import irange +from passlib.utils.compat import irange, unicode #pkg #local __all__ = [ diff --git a/passlib/handlers/mysql.py b/passlib/handlers/mysql.py index 7b43e00..75b5037 100644 --- a/passlib/handlers/mysql.py +++ b/passlib/handlers/mysql.py @@ -31,6 +31,7 @@ from warnings import warn #libs #pkg from passlib.utils import handlers as uh, to_hash_str, b, bord, bytes +from passlib.utils.compat import unicode #local __all__ = [ 'mysql323', diff --git a/passlib/handlers/oracle.py b/passlib/handlers/oracle.py index 263dd41..ec3806e 100644 --- a/passlib/handlers/oracle.py +++ b/passlib/handlers/oracle.py @@ -13,7 +13,7 @@ from warnings import warn #pkg from passlib.utils import xor_bytes, handlers as uh, bytes, to_unicode, \ to_hash_str, b -from passlib.utils.compat import irange +from passlib.utils.compat import irange, unicode from passlib.utils.des import des_encrypt_block #local __all__ = [ diff --git a/passlib/handlers/pbkdf2.py b/passlib/handlers/pbkdf2.py index 3859517..b957141 100644 --- a/passlib/handlers/pbkdf2.py +++ b/passlib/handlers/pbkdf2.py @@ -12,6 +12,7 @@ from warnings import warn #libs from passlib.utils import adapted_b64_encode, adapted_b64_decode, \ handlers as uh, to_hash_str, to_unicode, bytes, b +from passlib.utils.compat import unicode from passlib.utils.pbkdf2 import pbkdf2 #pkg #local diff --git a/passlib/handlers/phpass.py b/passlib/handlers/phpass.py index f366870..2a1b789 100644 --- a/passlib/handlers/phpass.py +++ b/passlib/handlers/phpass.py @@ -16,6 +16,7 @@ from warnings import warn #site #libs from passlib.utils import h64, handlers as uh, bytes, b, to_unicode, to_hash_str +from passlib.utils.compat import unicode #pkg #local __all__ = [ diff --git a/passlib/handlers/postgres.py b/passlib/handlers/postgres.py index 92f09c9..0aa4366 100644 --- a/passlib/handlers/postgres.py +++ b/passlib/handlers/postgres.py @@ -11,6 +11,7 @@ from warnings import warn #libs #pkg from passlib.utils import handlers as uh, to_unicode, to_hash_str, bytes, b +from passlib.utils.compat import unicode #local __all__ = [ "postgres_md5", diff --git a/passlib/handlers/sha1_crypt.py b/passlib/handlers/sha1_crypt.py index 934f1f8..dcbf2d2 100644 --- a/passlib/handlers/sha1_crypt.py +++ b/passlib/handlers/sha1_crypt.py @@ -15,6 +15,7 @@ from warnings import warn #libs from passlib.utils import h64, handlers as uh, safe_os_crypt, classproperty, \ to_hash_str, to_unicode, bytes, b +from passlib.utils.compat import unicode from passlib.utils.pbkdf2 import hmac_sha1 #pkg #local diff --git a/passlib/handlers/sha2_crypt.py b/passlib/handlers/sha2_crypt.py index 2e56419..3922160 100644 --- a/passlib/handlers/sha2_crypt.py +++ b/passlib/handlers/sha2_crypt.py @@ -11,6 +11,7 @@ from warnings import warn #libs from passlib.utils import h64, safe_os_crypt, classproperty, handlers as uh, \ to_hash_str, to_unicode, bytes, b, bord +from passlib.utils.compat import unicode #pkg #local __all__ = [ diff --git a/passlib/handlers/sun_md5_crypt.py b/passlib/handlers/sun_md5_crypt.py index 6bfab75..22cd9c3 100644 --- a/passlib/handlers/sun_md5_crypt.py +++ b/passlib/handlers/sun_md5_crypt.py @@ -18,7 +18,7 @@ from warnings import warn #site #libs from passlib.utils import h64, handlers as uh, to_hash_str, to_unicode, bytes, b, bord -from passlib.utils.compat import trange +from passlib.utils.compat import trange, unicode #pkg #local __all__ = [ diff --git a/passlib/tests/test_apache.py b/passlib/tests/test_apache.py index 0fb93a1..aa61543 100644 --- a/passlib/tests/test_apache.py +++ b/passlib/tests/test_apache.py @@ -12,7 +12,7 @@ import time #pkg from passlib import apache from passlib.utils import b, native_str, bytes -from passlib.utils.compat import irange +from passlib.utils.compat import irange, unicode from passlib.tests.utils import TestCase, mktemp, gae_env, get_file, set_file #module log = getLogger(__name__) diff --git a/passlib/tests/test_ext_django.py b/passlib/tests/test_ext_django.py index a7f3684..7f7d6d6 100644 --- a/passlib/tests/test_ext_django.py +++ b/passlib/tests/test_ext_django.py @@ -16,7 +16,7 @@ from passlib.hash import sha256_crypt from passlib.tests.utils import TestCase, unittest, ut_version, catch_warnings import passlib.tests.test_drivers as td from passlib.utils import Undef -from passlib.utils.compat import iteritems, get_method_function +from passlib.utils.compat import iteritems, get_method_function, unicode from passlib.registry import get_crypt_handler #module diff --git a/passlib/tests/test_utils.py b/passlib/tests/test_utils.py index c851943..a9b0f48 100644 --- a/passlib/tests/test_utils.py +++ b/passlib/tests/test_utils.py @@ -16,6 +16,7 @@ from passlib import utils from passlib.utils import h64, des, Undef, bytes, b, \ native_str, to_bytes, to_unicode, to_native_str, to_hash_str, \ is_same_codec, is_ascii_safe, safe_os_crypt, md4 as md4_mod +from passlib.utils.compat import unicode from passlib.tests.utils import TestCase, Params as ak, \ enable_option, catch_warnings diff --git a/passlib/tests/test_utils_handlers.py b/passlib/tests/test_utils_handlers.py index 7e4193c..dc3ae86 100644 --- a/passlib/tests/test_utils_handlers.py +++ b/passlib/tests/test_utils_handlers.py @@ -15,6 +15,7 @@ from passlib.registry import _unload_handler_name as unload_handler_name, \ register_crypt_handler, get_crypt_handler from passlib.utils import rng, getrandstr, handlers as uh, bytes, b, \ to_hash_str, to_unicode, MissingBackendError, jython_vm +from passlib.utils.compat import unicode from passlib.tests.utils import HandlerCase, TestCase, catch_warnings, \ dummy_handler_in_registry #module @@ -234,7 +235,7 @@ class SkeletonTest(TestCase): self.assertTrue(d1.has_backend()) d1.set_backend('a') self.assertEqual(obj.calc_checksum('s'), 'a') - + #test unknown backend self.assertRaises(ValueError, d1.set_backend, 'c') self.assertRaises(ValueError, d1.has_backend, 'c') diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py index ae43f61..b442218 100644 --- a/passlib/tests/utils.py +++ b/passlib/tests/utils.py @@ -37,7 +37,8 @@ from passlib import registry, utils from passlib.utils import classproperty, handlers as uh, \ has_rounds_info, has_salt_info, MissingBackendError, \ rounds_cost_values, b, bytes, native_str, NoneType -from passlib.utils.compat import iteritems, irange, callable, sb_types, exc_err +from passlib.utils.compat import iteritems, irange, callable, sb_types, \ + exc_err, unicode #local __all__ = [ #util funcs diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py index e8be491..94c3481 100644 --- a/passlib/utils/__init__.py +++ b/passlib/utils/__init__.py @@ -16,7 +16,7 @@ import time from warnings import warn #site #pkg -from passlib.utils.compat import irange, b, PY3, sys_bits +from passlib.utils.compat import irange, b, PY3, sys_bits, unicode #local __all__ = [ #decorators diff --git a/passlib/utils/_blowfish/__init__.py b/passlib/utils/_blowfish/__init__.py index dff1ca5..5acae8d 100644 --- a/passlib/utils/_blowfish/__init__.py +++ b/passlib/utils/_blowfish/__init__.py @@ -55,7 +55,7 @@ from itertools import chain import struct #pkg from passlib.utils import rng, getrandbytes, bytes, bord -from passlib.utils.compat import b +from passlib.utils.compat import b, unicode from passlib.utils.compat.aliases import BytesIO from passlib.utils._blowfish.unrolled import BlowfishEngine #local diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py index e555421..a6666f5 100644 --- a/passlib/utils/handlers.py +++ b/passlib/utils/handlers.py @@ -17,6 +17,7 @@ from passlib.registry import get_crypt_handler from passlib.utils import to_hash_str, bytes, b, consteq, \ classproperty, h64, getrandstr, getrandbytes, \ rng, is_crypt_handler, ALL_BYTE_VALUES, MissingBackendError +from passlib.utils.compat import unicode #pkg #local __all__ = [ diff --git a/passlib/win32.py b/passlib/win32.py index 4ba694c..f34416e 100644 --- a/passlib/win32.py +++ b/passlib/win32.py @@ -28,6 +28,7 @@ from binascii import hexlify #site #pkg from passlib.utils import to_native_str, b +from passlib.utils.compat import unicode from passlib.utils.des import des_encrypt_block from passlib.hash import nthash #local |