diff options
author | Eli Collins <elic@assurancetechnologies.com> | 2012-04-27 00:22:33 -0400 |
---|---|---|
committer | Eli Collins <elic@assurancetechnologies.com> | 2012-04-27 00:22:33 -0400 |
commit | ea0df30de9d73011bd299b69a9b15a1094d009cf (patch) | |
tree | ecae184fc9c664787a332d229d9071eaa4dea0be | |
parent | aa4e6eec42ff77956a612f0f8b2312f3131106b6 (diff) | |
download | passlib-ea0df30de9d73011bd299b69a9b15a1094d009cf.tar.gz |
renamed 'errname' to 'param' for to_unicode, etc; to match some of the other helper functions
-rw-r--r-- | passlib/apache.py | 8 | ||||
-rw-r--r-- | passlib/context.py | 4 | ||||
-rw-r--r-- | passlib/handlers/digests.py | 2 | ||||
-rw-r--r-- | passlib/handlers/misc.py | 4 | ||||
-rw-r--r-- | passlib/handlers/oracle.py | 2 | ||||
-rw-r--r-- | passlib/handlers/postgres.py | 2 | ||||
-rw-r--r-- | passlib/handlers/windows.py | 10 | ||||
-rw-r--r-- | passlib/utils/__init__.py | 52 |
8 files changed, 42 insertions, 42 deletions
diff --git a/passlib/apache.py b/passlib/apache.py index 70ac78d..cd95990 100644 --- a/passlib/apache.py +++ b/passlib/apache.py @@ -314,7 +314,7 @@ class _CommonFile(object): "realm-specific wrapper for _encode_field()" return self._encode_field(realm, "realm") - def _encode_field(self, value, errname="field"): + def _encode_field(self, value, param="field"): """convert field to internal representation. internal representation is always bytes. byte strings are left as-is, @@ -334,13 +334,13 @@ class _CommonFile(object): if isinstance(value, unicode): value = value.encode(self.encoding) elif not isinstance(value, bytes): - raise ExpectedStringError(value, errname) + raise ExpectedStringError(value, param) if len(value) > 255: raise ValueError("%s must be at most 255 characters: %r" % - (errname, value)) + (param, value)) if any(c in _INVALID_FIELD_CHARS for c in value): raise ValueError("%s contains invalid characters: %r" % - (errname, value,)) + (param, value,)) return value def _decode_field(self, value): diff --git a/passlib/context.py b/passlib/context.py index 5f84202..18bfb74 100644 --- a/passlib/context.py +++ b/passlib/context.py @@ -1443,10 +1443,10 @@ class CryptContext(object): parse_keys = True if isinstance(source, base_string_types): if PY3: - source = to_unicode(source, encoding, errname="source") + source = to_unicode(source, encoding, param="source") else: source = to_bytes(source, "utf-8", source_encoding=encoding, - errname="source") + param="source") source = self._parse_ini_stream(NativeStringIO(source), section, "<string>") elif isinstance(source, CryptContext): diff --git a/passlib/handlers/digests.py b/passlib/handlers/digests.py index 22c1c6a..e5de2eb 100644 --- a/passlib/handlers/digests.py +++ b/passlib/handlers/digests.py @@ -103,7 +103,7 @@ class htdigest(object): @classmethod def _norm_hash(cls, hash): "normalize hash to native string, and validate it" - hash = to_native_str(hash, errname="hash") + hash = to_native_str(hash, param="hash") if len(hash) != 32: raise uh.exc.MalformedHashError(cls, "wrong size") for char in hash: diff --git a/passlib/handlers/misc.py b/passlib/handlers/misc.py index 7121707..ac6e72a 100644 --- a/passlib/handlers/misc.py +++ b/passlib/handlers/misc.py @@ -143,9 +143,9 @@ class unix_disabled(object): # such as ``"!" + original hash``, which glibc uses. # XXX: should this detect mcf header, or other things re: # local system policy? - return to_native_str(config, errname="config") + return to_native_str(config, param="config") else: - return to_native_str(marker or cls.marker, errname="marker") + return to_native_str(marker or cls.marker, param="marker") class plaintext(object): """This class stores passwords in plaintext, and follows the :ref:`password-hash-api`. diff --git a/passlib/handlers/oracle.py b/passlib/handlers/oracle.py index 24ef319..f7083bf 100644 --- a/passlib/handlers/oracle.py +++ b/passlib/handlers/oracle.py @@ -90,7 +90,7 @@ class oracle10(uh.HasUserContext, uh.StaticHandler): # and some answers :) if isinstance(secret, bytes): secret = secret.decode("utf-8") - user = to_unicode(self.user, "utf-8", errname="user") + user = to_unicode(self.user, "utf-8", param="user") input = (user+secret).upper().encode("utf-16-be") hash = des_cbc_encrypt(ORACLE10_MAGIC, input) hash = des_cbc_encrypt(hash, input) diff --git a/passlib/handlers/postgres.py b/passlib/handlers/postgres.py index c794c19..b268905 100644 --- a/passlib/handlers/postgres.py +++ b/passlib/handlers/postgres.py @@ -47,7 +47,7 @@ class postgres_md5(uh.HasUserContext, uh.StaticHandler): def _calc_checksum(self, secret): if isinstance(secret, unicode): secret = secret.encode("utf-8") - user = to_bytes(self.user, "utf-8", errname="user") + user = to_bytes(self.user, "utf-8", param="user") return str_to_uascii(md5(secret + user).hexdigest()) #========================================================= diff --git a/passlib/handlers/windows.py b/passlib/handlers/windows.py index fc77d40..1670d5c 100644 --- a/passlib/handlers/windows.py +++ b/passlib/handlers/windows.py @@ -150,7 +150,7 @@ class nthash(uh.StaticHandler): :returns: returns string of raw bytes """ - secret = to_unicode(secret, "utf-8", errname="secret") + secret = to_unicode(secret, "utf-8", param="secret") # XXX: found refs that say only first 128 chars are used. return md4(secret.encode("utf-16-le")).digest() @@ -256,8 +256,8 @@ class msdcc(uh.HasUserContext, uh.StaticHandler): :returns: returns string of raw bytes """ - secret = to_unicode(secret, "utf-8", errname="secret").encode("utf-16-le") - user = to_unicode(user, "utf-8", errname="user").lower().encode("utf-16-le") + secret = to_unicode(secret, "utf-8", param="secret").encode("utf-16-le") + user = to_unicode(user, "utf-8", param="user").lower().encode("utf-16-le") return md4(md4(secret).digest() + user).digest() #========================================================= @@ -301,8 +301,8 @@ class msdcc2(uh.HasUserContext, uh.StaticHandler): :returns: returns string of raw bytes """ from passlib.utils.pbkdf2 import pbkdf2 - secret = to_unicode(secret, "utf-8", errname="secret").encode("utf-16-le") - user = to_unicode(user, "utf-8", errname="user").lower().encode("utf-16-le") + secret = to_unicode(secret, "utf-8", param="secret").encode("utf-16-le") + user = to_unicode(user, "utf-8", param="user").lower().encode("utf-16-le") tmp = md4(md4(secret).digest() + user).digest() return pbkdf2(tmp, user, 10240, 16, 'hmac-sha1') diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py index f329b9d..aea7abf 100644 --- a/passlib/utils/__init__.py +++ b/passlib/utils/__init__.py @@ -355,7 +355,7 @@ def splitcomma(source, sep=","): # pragma: no cover if elem.strip() ] -def saslprep(source, errname="value"): +def saslprep(source, param="value"): """normalizes unicode string using SASLPrep stringprep profile. The SASLPrep profile is defined in :rfc:`4013`. @@ -368,7 +368,7 @@ def saslprep(source, errname="value"): :arg source: unicode string to normalize & validate - :param errname: + :param param: optionally override noun used to refer to source in error messages, defaults to ``value``; mainly useful to make caller's error messages make more sense. @@ -421,7 +421,7 @@ def saslprep(source, errname="value"): is_ral_char = stringprep.in_table_d1 if is_ral_char(data[0]): if not is_ral_char(data[-1]): - raise ValueError("malformed bidi sequence in " + errname) + raise ValueError("malformed bidi sequence in " + param) # forbid L chars within R/AL sequence. is_forbidden_bidi_char = stringprep.in_table_d2 else: @@ -445,36 +445,36 @@ def saslprep(source, errname="value"): # check for forbidden chars if in_table_a1(c): - raise ValueError("unassigned code points forbidden in " + errname) + raise ValueError("unassigned code points forbidden in " + param) if in_table_c21_c22(c): - raise ValueError("control characters forbidden in " + errname) + raise ValueError("control characters forbidden in " + param) if in_table_c3(c): - raise ValueError("private use characters forbidden in " + errname) + raise ValueError("private use characters forbidden in " + param) if in_table_c4(c): - raise ValueError("non-char code points forbidden in " + errname) + raise ValueError("non-char code points forbidden in " + param) if in_table_c5(c): - raise ValueError("surrogate codes forbidden in " + errname) + raise ValueError("surrogate codes forbidden in " + param) if in_table_c6(c): - raise ValueError("non-plaintext chars forbidden in " + errname) + raise ValueError("non-plaintext chars forbidden in " + param) if in_table_c7(c): # XXX: should these have been caught by normalize? # if so, should change this to an assert - raise ValueError("non-canonical chars forbidden in " + errname) + raise ValueError("non-canonical chars forbidden in " + param) if in_table_c8(c): raise ValueError("display-modifying / deprecated chars " - "forbidden in" + errname) + "forbidden in" + param) if in_table_c9(c): - raise ValueError("tagged characters forbidden in " + errname) + raise ValueError("tagged characters forbidden in " + param) # do bidi constraint check chosen by bidi init, above if is_forbidden_bidi_char(c): - raise ValueError("forbidden bidi character in " + errname) + raise ValueError("forbidden bidi character in " + param) return data # replace saslprep() with stub when stringprep is missing if stringprep is None: - def saslprep(source, errname="value"): + def saslprep(source, param="value"): "stub for saslprep()" raise NotImplementedError("saslprep() support requires the 'stringprep' " "module, which is " + _stringprep_missing_reason) @@ -567,7 +567,7 @@ def is_ascii_safe(source): r = _B80 if isinstance(source, bytes) else _U80 return all(c < r for c in source) -def to_bytes(source, encoding="utf-8", errname="value", source_encoding=None): +def to_bytes(source, encoding="utf-8", param="value", source_encoding=None): """helper to normalize input to bytes. :arg source: @@ -576,7 +576,7 @@ def to_bytes(source, encoding="utf-8", errname="value", source_encoding=None): :arg encoding: Target encoding (defaults to ``"utf-8"``). - :param errname: + :param param: Optional name of variable/noun to reference when raising errors :param source_encoding: @@ -602,9 +602,9 @@ def to_bytes(source, encoding="utf-8", errname="value", source_encoding=None): elif isinstance(source, unicode): return source.encode(encoding) else: - raise ExpectedStringError(source, errname) + raise ExpectedStringError(source, param) -def to_unicode(source, source_encoding="utf-8", errname="value"): +def to_unicode(source, source_encoding="utf-8", param="value"): """helper to normalize input to unicode. :arg source: @@ -613,7 +613,7 @@ def to_unicode(source, source_encoding="utf-8", errname="value"): :arg source_encoding: encoding to use when decoding bytes instances. - :param errname: + :param param: optional name of variable/noun to reference when raising errors. :raises TypeError: if source is not unicode or bytes. @@ -628,24 +628,24 @@ def to_unicode(source, source_encoding="utf-8", errname="value"): elif isinstance(source, bytes): return source.decode(source_encoding) else: - raise ExpectedStringError(source, errname) + raise ExpectedStringError(source, param) if PY3: - def to_native_str(source, encoding="utf-8", errname="value"): + def to_native_str(source, encoding="utf-8", param="value"): if isinstance(source, bytes): return source.decode(encoding) elif isinstance(source, unicode): return source else: - raise ExpectedStringError(source, errname) + raise ExpectedStringError(source, param) else: - def to_native_str(source, encoding="utf-8", errname="value"): + def to_native_str(source, encoding="utf-8", param="value"): if isinstance(source, bytes): return source elif isinstance(source, unicode): return source.encode(encoding) else: - raise ExpectedStringError(source, errname) + raise ExpectedStringError(source, param) add_doc(to_native_str, """take in unicode or bytes, return native string. @@ -662,7 +662,7 @@ add_doc(to_native_str, encoding to use when encoding unicode or decoding bytes. this defaults to ``"utf-8"``. - :param errname: + :param param: optional name of variable/noun to reference when raising errors. :returns: :class:`str` instance @@ -671,7 +671,7 @@ add_doc(to_native_str, @deprecated_function(deprecated="1.6", removed="1.7") def to_hash_str(source, encoding="ascii"): # pragma: no cover "deprecated, use to_native_str() instead" - return to_native_str(source, encoding, errname="hash") + return to_native_str(source, encoding, param="hash") #================================================================================= # base64-variant encoding |