diff options
author | Eli Collins <elic@assurancetechnologies.com> | 2011-03-28 01:51:39 -0400 |
---|---|---|
committer | Eli Collins <elic@assurancetechnologies.com> | 2011-03-28 01:51:39 -0400 |
commit | 929f59a76b45ecd3101f5609493f3dd6e1fcd723 (patch) | |
tree | 588858bff51f221ba1f2524e5497fe4e78d97cfd | |
parent | d477d89822dbfc94bc52bc569f5352ffe402a7c4 (diff) | |
download | passlib-929f59a76b45ecd3101f5609493f3dd6e1fcd723.tar.gz |
replaced "raise exc, msg" with "raise exc(msg)" everywhere (working on py3k compat, changes made by 2to3)
-rw-r--r-- | passlib/apache.py | 12 | ||||
-rw-r--r-- | passlib/context.py | 30 | ||||
-rw-r--r-- | passlib/handlers/bcrypt.py | 8 | ||||
-rw-r--r-- | passlib/handlers/des_crypt.py | 30 | ||||
-rw-r--r-- | passlib/handlers/digests.py | 4 | ||||
-rw-r--r-- | passlib/handlers/ldap_digests.py | 10 | ||||
-rw-r--r-- | passlib/handlers/md5_crypt.py | 10 | ||||
-rw-r--r-- | passlib/handlers/misc.py | 8 | ||||
-rw-r--r-- | passlib/handlers/mysql.py | 8 | ||||
-rw-r--r-- | passlib/handlers/nthash.py | 10 | ||||
-rw-r--r-- | passlib/handlers/oracle.py | 12 | ||||
-rw-r--r-- | passlib/handlers/pbkdf2.py | 22 | ||||
-rw-r--r-- | passlib/handlers/phpass.py | 8 | ||||
-rw-r--r-- | passlib/handlers/postgres.py | 4 | ||||
-rw-r--r-- | passlib/handlers/sha1_crypt.py | 8 | ||||
-rw-r--r-- | passlib/handlers/sha2_crypt.py | 14 | ||||
-rw-r--r-- | passlib/handlers/sun_md5_crypt.py | 4 | ||||
-rw-r--r-- | passlib/registry.py | 22 | ||||
-rw-r--r-- | passlib/tests/genconfig.py | 8 | ||||
-rw-r--r-- | passlib/tests/test_utils_handlers.py | 4 | ||||
-rw-r--r-- | passlib/tests/utils.py | 26 | ||||
-rw-r--r-- | passlib/utils/__init__.py | 14 | ||||
-rw-r--r-- | passlib/utils/h64.py | 14 | ||||
-rw-r--r-- | passlib/utils/handlers.py | 52 | ||||
-rw-r--r-- | passlib/utils/pbkdf2.py | 10 |
25 files changed, 176 insertions, 176 deletions
diff --git a/passlib/apache.py b/passlib/apache.py index 9b99203..e910023 100644 --- a/passlib/apache.py +++ b/passlib/apache.py @@ -78,7 +78,7 @@ class _CommonFile(object): """ path = self.path if not path: - raise RuntimeError, "no load path specified" + raise RuntimeError("no load path specified") if not force and self.mtime and self.mtime == os.path.getmtime(path): return False with file(path, "rU") as fh: @@ -104,7 +104,7 @@ class _CommonFile(object): def save(self): "save entries to file" if not self.path: - raise RuntimeError, "no save path specified" + raise RuntimeError("no save path specified") rl = self._render_line entry_order = self._entry_order entry_map = self._entry_map @@ -146,18 +146,18 @@ class _CommonFile(object): def _validate_user(self, user): if len(user) > 255: - raise ValueError, "user must be at most 255 characters: %r" % (user,) + raise ValueError("user must be at most 255 characters: %r" % (user,)) ic = self.invalid_chars if any(c in ic for c in user): - raise ValueError, "user contains invalid characters: %r" % (user,) + raise ValueError("user contains invalid characters: %r" % (user,)) return True def _validate_realm(self, realm): if len(realm) > 255: - raise ValueError, "realm must be at most 255 characters: %r" % (realm,) + raise ValueError("realm must be at most 255 characters: %r" % (realm,)) ic = self.invalid_chars if any(c in ic for c in realm): - raise ValueError, "realm contains invalid characters: %r" % (realm,) + raise ValueError("realm contains invalid characters: %r" % (realm,)) return True #FIXME: htpasswd doc sez passwords limited to 255 chars under Windows & MPE, diff --git a/passlib/context.py b/passlib/context.py index 8b15796..4ac3e00 100644 --- a/passlib/context.py +++ b/passlib/context.py @@ -45,7 +45,7 @@ def _parse_policy_key(key): elif len(parts) == 3: cat, name, opt = parts else: - raise KeyError, "keys must have 0..2 separators: %r" % (orig,) + raise KeyError("keys must have 0..2 separators: %r" % (orig,)) if cat == "default": cat = None assert name @@ -77,13 +77,13 @@ def parse_policy_items(source): cat, name, opt = _parse_policy_key(key) if name == "context": if cat and opt == "schemes": - raise KeyError, "current code does not support per-category schemes" + raise KeyError("current code does not support per-category schemes") #NOTE: forbidding this because it would really complicate the behavior # of CryptContext.identify & CryptContext.lookup. # most useful behaviors here can be had by overridding deprecated and default, anyways. else: if opt == "salt": - raise KeyError, "'salt' option is not allowed to be set via a policy object" + raise KeyError("'salt' option is not allowed to be set via a policy object") #NOTE: doing this for security purposes, why would you ever want a fixed salt? value = _parse_policy_value(cat, name, opt, value) yield cat, name, opt, value @@ -143,7 +143,7 @@ class CryptPolicy(object): """ p = ConfigParser() if not p.read([path]): - raise EnvironmentError, "failed to read config file" + raise EnvironmentError("failed to read config file") return cls(**dict(p.items(section))) @classmethod @@ -189,7 +189,7 @@ class CryptPolicy(object): else: #other strings should be filepath return cls.from_path(source) else: - raise TypeError, "source must be CryptPolicy, dict, config string, or file path: %r" % (type(source),) + raise TypeError("source must be CryptPolicy, dict, config string, or file path: %r" % (type(source),)) @classmethod def from_sources(cls, sources): @@ -207,7 +207,7 @@ class CryptPolicy(object): #check for no sources - should we return blank policy in that case? if len(sources) == 0: #XXX: er, would returning an empty policy be the right thing here? - raise ValueError, "no sources specified" + raise ValueError("no sources specified") #check if only one source if len(sources) == 1: @@ -313,11 +313,11 @@ class CryptPolicy(object): handler = get_crypt_handler(scheme) name = handler.name if not name: - raise TypeError, "handler lacks name: %r" % (handler,) + raise TypeError("handler lacks name: %r" % (handler,)) #check name hasn't been re-used if name in seen: - raise KeyError, "multiple handlers with same name: %r" % (name,) + raise KeyError("multiple handlers with same name: %r" % (name,)) seen.add(name) #add to handler list @@ -340,7 +340,7 @@ class CryptPolicy(object): if handlers: for scheme in deps: if scheme not in seen: - raise KeyError, "known scheme in deprecated list: %r" % (scheme,) + raise KeyError("known scheme in deprecated list: %r" % (scheme,)) dmap[cat] = frozenset(deps) #default scheme @@ -350,7 +350,7 @@ class CryptPolicy(object): if hasattr(fb, "name"): fb = fb.name if fb not in seen: - raise KeyError, "unknown scheme set as default: %r" % (fb,) + raise KeyError("unknown scheme set as default: %r" % (fb,)) fmap[cat] = self.get_handler(fb, required=True) else: fmap[cat] = fb @@ -409,9 +409,9 @@ class CryptPolicy(object): handlers = self._handlers if handlers: return handlers[0] - raise KeyError, "no crypt algorithms supported" + raise KeyError("no crypt algorithms supported") if required: - raise KeyError, "no crypt algorithm by that name: %r" % (name,) + raise KeyError("no crypt algorithm by that name: %r" % (name,)) return None def get_options(self, name, category=None): @@ -840,7 +840,7 @@ class CryptContext(object): #NOTE: this doesn't use category in any way, but accepts it for consistency if hash is None: if required: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") return None handler = None for handler in self.policy.iter_handlers(): @@ -851,8 +851,8 @@ class CryptContext(object): return handler.name if required: if handler is None: - raise KeyError, "no crypt algorithms supported" - raise ValueError, "hash could not be identified" + raise KeyError("no crypt algorithms supported") + raise ValueError("hash could not be identified") return None def encrypt(self, secret, scheme=None, category=None, **kwds): diff --git a/passlib/handlers/bcrypt.py b/passlib/handlers/bcrypt.py index ff386b1..8707b70 100644 --- a/passlib/handlers/bcrypt.py +++ b/passlib/handlers/bcrypt.py @@ -87,10 +87,10 @@ class bcrypt(MultiBackendHandler): def norm_ident(cls, ident, strict=False): if not ident: if strict: - raise ValueError, "no ident specified" + raise ValueError("no ident specified") ident = "2a" if ident not in ("2", "2a"): - raise ValueError, "invalid ident: %r" % (ident,) + raise ValueError("invalid ident: %r" % (ident,)) return ident #========================================================= @@ -112,10 +112,10 @@ class bcrypt(MultiBackendHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") m = cls._pat.match(hash) if not m: - raise ValueError, "invalid bcrypt hash" + raise ValueError("invalid bcrypt hash") ident, rounds, salt, chk = m.group("ident", "rounds", "salt", "chk") return cls( rounds=int(rounds), diff --git a/passlib/handlers/des_crypt.py b/passlib/handlers/des_crypt.py index e358208..9fee4fa 100644 --- a/passlib/handlers/des_crypt.py +++ b/passlib/handlers/des_crypt.py @@ -89,7 +89,7 @@ def raw_crypt(secret, salt): try: salt_value = h64.decode_int12(salt) except ValueError: #pragma: no cover - always caught by class - raise ValueError, "invalid chars in salt" + raise ValueError("invalid chars in salt") #FIXME: ^ this will throws error if bad salt chars are used # whereas linux crypt does something (inexplicable) with it @@ -109,13 +109,13 @@ def raw_ext_crypt(secret, rounds, salt): try: salt_value = h64.decode_int24(salt) except ValueError: #pragma: no cover - always caught by class - raise ValueError, "invalid salt" + raise ValueError("invalid salt") #validate secret if '\x00' in secret: #pragma: no cover - always caught by class #builtin linux crypt doesn't like this, so we don't either #XXX: would make more sense to raise ValueError, but want to be compatible w/ stdlib crypt - raise ValueError, "secret must be string without null bytes" + raise ValueError("secret must be string without null bytes") #convert secret string into an integer key_value = _crypt_secret_to_key(secret) @@ -181,10 +181,10 @@ class des_crypt(MultiBackendHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") m = cls._pat.match(hash) if not m: - raise ValueError, "invalid des-crypt hash" + raise ValueError("invalid des-crypt hash") salt, chk = m.group("salt", "chk") return cls(salt=salt, checksum=chk, strict=bool(chk)) @@ -205,7 +205,7 @@ class des_crypt(MultiBackendHandler): def _calc_checksum_builtin(self, secret): #forbidding nul chars because linux crypt (and most C implementations) won't accept it either. if '\x00' in secret: - raise ValueError, "null char in secret" + raise ValueError("null char in secret") #gotta do something - no official policy since des-crypt predates unicode if isinstance(secret, unicode): secret = secret.encode("utf-8") @@ -214,7 +214,7 @@ class des_crypt(MultiBackendHandler): def _calc_checksum_os_crypt(self, secret): #os_crypt() would raise less useful error if '\x00' in secret: - raise ValueError, "null char in secret" + raise ValueError("null char in secret") #gotta do something - no official policy since des-crypt predates unicode if isinstance(secret, unicode): secret = secret.encode("utf-8") @@ -285,10 +285,10 @@ class bsdi_crypt(ExtendedHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") m = cls._pat.match(hash) if not m: - raise ValueError, "invalid ext-des-crypt hash" + raise ValueError("invalid ext-des-crypt hash") rounds, salt, chk = m.group("rounds", "salt", "chk") return cls( rounds=h64.decode_int24(rounds), @@ -356,13 +356,13 @@ class bigcrypt(ExtendedHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") m = cls._pat.match(hash) if not m: - raise ValueError, "invalid bigcrypt hash" + raise ValueError("invalid bigcrypt hash") salt, chk = m.group("salt", "chk") if chk and len(chk) % 11: - raise ValueError, "invalid bigcrypt hash" + raise ValueError("invalid bigcrypt hash") return cls(salt=salt, checksum=chk, strict=bool(chk)) def to_string(self): @@ -431,10 +431,10 @@ class crypt16(ExtendedHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") m = cls._pat.match(hash) if not m: - raise ValueError, "invalid crypt16 hash" + raise ValueError("invalid crypt16 hash") salt, chk = m.group("salt", "chk") return cls(salt=salt, checksum=chk, strict=bool(chk)) @@ -454,7 +454,7 @@ class crypt16(ExtendedHandler): try: salt_value = h64.decode_int12(self.salt) except ValueError: #pragma: no cover - caught by class - raise ValueError, "invalid chars in salt" + raise ValueError("invalid chars in salt") #convert first 8 byts of secret string into an integer, key1 = _crypt_secret_to_key(secret) diff --git a/passlib/handlers/digests.py b/passlib/handlers/digests.py index c4d13a6..4681be3 100644 --- a/passlib/handlers/digests.py +++ b/passlib/handlers/digests.py @@ -46,13 +46,13 @@ class HexDigestHash(SimpleHandler): if isinstance(secret, unicode): secret = secret.encode("utf-8") if hash is not None and not cls.identify(hash): - raise ValueError, "not a %s hash" % (cls.name,) + raise ValueError("not a %s hash" % (cls.name,)) return cls._hash(secret).hexdigest() @classmethod def verify(cls, secret, hash): if hash is None: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") return cls.genhash(secret, hash) == hash.lower() def create_hex_hash(hash): diff --git a/passlib/handlers/ldap_digests.py b/passlib/handlers/ldap_digests.py index 743de88..7acc2e2 100644 --- a/passlib/handlers/ldap_digests.py +++ b/passlib/handlers/ldap_digests.py @@ -44,7 +44,7 @@ class _Base64DigestHelper(SimpleHandler): if isinstance(secret, unicode): secret = secret.encode("utf-8") if hash is not None and not cls.identify(hash): - raise ValueError, "not a %s hash" % (cls.name,) + raise ValueError("not a %s hash" % (cls.name,)) return cls._ident + cls._hash(secret).digest().encode("base64").strip() class _SaltedBase64DigestHelper(ExtendedHandler): @@ -65,10 +65,10 @@ class _SaltedBase64DigestHelper(ExtendedHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") m = cls._pat.match(hash) if not m: - raise ValueError, "not a %s hash" % (cls.name,) + raise ValueError("not a %s hash" % (cls.name,)) tmp = m.group("tmp").decode("base64") chk, salt = tmp[:-4], tmp[-4:] return cls(checksum=chk, salt=salt, strict=True) @@ -168,7 +168,7 @@ class ldap_plaintext(SimpleHandler): @classmethod def genhash(cls, secret, hash): if hash is not None and not cls.identify(hash): - raise ValueError, "not a valid ldap_cleartext hash" + raise ValueError("not a valid ldap_cleartext hash") if secret is None: raise TypeError, "secret must be string" if isinstance(secret, unicode): @@ -178,7 +178,7 @@ class ldap_plaintext(SimpleHandler): @classmethod def verify(cls, secret, hash): if hash is None: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") return hash == cls.genhash(secret, hash) #TODO: support {CRYPT} somehow (adapt per host?) diff --git a/passlib/handlers/md5_crypt.py b/passlib/handlers/md5_crypt.py index c7ce561..cb25f1e 100644 --- a/passlib/handlers/md5_crypt.py +++ b/passlib/handlers/md5_crypt.py @@ -31,7 +31,7 @@ def raw_md5_crypt(secret, salt, apr=False): #validate secret if not isinstance(secret, str): - raise TypeError, "secret must be string" + raise TypeError("secret must be string") #validate salt if len(salt) > 8: @@ -176,10 +176,10 @@ class md5_crypt(MultiBackendHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") m = cls._pat.match(hash) if not m: - raise ValueError, "invalid md5-crypt hash" + raise ValueError("invalid md5-crypt hash") salt, chk = m.group("salt", "chk") return cls(salt=salt, checksum=chk, strict=bool(chk)) @@ -257,10 +257,10 @@ class apr_md5_crypt(ExtendedHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") m = cls._pat.match(hash) if not m: - raise ValueError, "invalid md5-crypt hash" + raise ValueError("invalid md5-crypt hash") salt, chk = m.group("salt", "chk") return cls(salt=salt, checksum=chk, strict=bool(chk)) diff --git a/passlib/handlers/misc.py b/passlib/handlers/misc.py index c0c402a..612929d 100644 --- a/passlib/handlers/misc.py +++ b/passlib/handlers/misc.py @@ -46,15 +46,15 @@ class unix_fallback(SimpleHandler): @classmethod def genhash(cls, secret, hash): if secret is None: - raise TypeError, "secret must be string" + raise TypeError("secret must be string") if hash is None: - raise ValueError, "no hash provided" + raise ValueError("no hash provided") return hash @classmethod def verify(cls, secret, hash): if hash is None: - raise ValueError, "no hash provided" + raise ValueError("no hash provided") return not hash class plaintext(SimpleHandler): @@ -81,7 +81,7 @@ class plaintext(SimpleHandler): @classmethod def verify(cls, secret, hash): if hash is None: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") return hash == cls.genhash(secret, hash) #========================================================= diff --git a/passlib/handlers/mysql.py b/passlib/handlers/mysql.py index c8f8331..750c31d 100644 --- a/passlib/handlers/mysql.py +++ b/passlib/handlers/mysql.py @@ -70,7 +70,7 @@ class mysql323(SimpleHandler): @classmethod def genhash(cls, secret, config): if config and not cls.identify(config): - raise ValueError, "not a mysql-41 hash" + raise ValueError("not a mysql-41 hash") #FIXME: no idea if mysql has a policy about handling unicode passwords if isinstance(secret, unicode): @@ -99,7 +99,7 @@ class mysql323(SimpleHandler): @classmethod def verify(cls, secret, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") return hash.lower() == cls.genhash(secret, hash) #========================================================= @@ -139,7 +139,7 @@ class mysql41(SimpleHandler): @classmethod def genhash(cls, secret, config): if config and not cls.identify(config): - raise ValueError, "not a mysql-41 hash" + raise ValueError("not a mysql-41 hash") #FIXME: no idea if mysql has a policy about handling unicode passwords if isinstance(secret, unicode): secret = secret.encode("utf-8") @@ -153,7 +153,7 @@ class mysql41(SimpleHandler): @classmethod def verify(cls, secret, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") return hash.upper() == cls.genhash(secret, hash) #========================================================= diff --git a/passlib/handlers/nthash.py b/passlib/handlers/nthash.py index 0824710..3dafcd4 100644 --- a/passlib/handlers/nthash.py +++ b/passlib/handlers/nthash.py @@ -48,10 +48,10 @@ class nthash(ExtendedHandler): def norm_ident(cls, value, strict=False): if value is None: if strict: - raise ValueError, "no ident specified" + raise ValueError("no ident specified") return "3" if value not in ("3", "NT"): - raise ValueError, "invalid ident" + raise ValueError("invalid ident") return value #========================================================= @@ -71,10 +71,10 @@ class nthash(ExtendedHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") m = cls._pat.match(hash) if not m: - raise ValueError, "invalid nthash" + raise ValueError("invalid nthash") ident, chk = m.group("ident", "chk") return cls(ident=ident.strip("$"), checksum=chk, strict=True) @@ -97,7 +97,7 @@ class nthash(ExtendedHandler): def calc_checksum(self, secret): if secret is None: - raise TypeError, "secret must be a string" + raise TypeError("secret must be a string") return self.raw_nthash(secret, hex=True) @staticmethod diff --git a/passlib/handlers/oracle.py b/passlib/handlers/oracle.py index 1e67b53..5ac788e 100644 --- a/passlib/handlers/oracle.py +++ b/passlib/handlers/oracle.py @@ -84,7 +84,7 @@ class oracle10(object): @classmethod def genhash(cls, secret, config, user): if config and not cls.identify(config): - raise ValueError, "not a oracle10g hash" + raise ValueError("not a oracle10g hash") return cls.encrypt(secret, user) #========================================================= @@ -93,9 +93,9 @@ class oracle10(object): @classmethod def encrypt(cls, secret, user): if secret is None: - raise TypeError, "secret must be specified" + raise TypeError("secret must be specified") if not user: - raise ValueError, "user keyword must be specified for this algorithm" + raise ValueError("user keyword must be specified for this algorithm") #FIXME: not sure how oracle handles unicode. # online docs about 10g hash indicate it puts ascii chars @@ -125,7 +125,7 @@ class oracle10(object): @classmethod def verify(cls, secret, hash, user): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") return cls.genhash(secret, hash, user) == hash.upper() #========================================================= @@ -164,10 +164,10 @@ class oracle11(ExtendedHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash provided" + raise ValueError("no hash provided") m = cls._pat.match(hash) if not m: - raise ValueError, "invalid oracle11g hash" + raise ValueError("invalid oracle11g hash") salt, chk = m.group("salt", "chk") return cls(salt=salt, checksum=chk.upper(), strict=True) diff --git a/passlib/handlers/pbkdf2.py b/passlib/handlers/pbkdf2.py index 5b0426d..825f7e4 100644 --- a/passlib/handlers/pbkdf2.py +++ b/passlib/handlers/pbkdf2.py @@ -57,10 +57,10 @@ class Pbkdf2DigestHandler(ExtendedHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") ident = cls._ident if not hash.startswith(ident): - raise ValueError, "invalid %s hash" % (cls.name,) + raise ValueError("invalid %s hash" % (cls.name,)) parts = hash[len(ident):].split("$") if len(parts) == 3: rounds, salt, chk = parts @@ -68,10 +68,10 @@ class Pbkdf2DigestHandler(ExtendedHandler): rounds, salt = parts chk = None else: - raise ValueError, "invalid %s hash" % (cls.name,) + raise ValueError("invalid %s hash" % (cls.name,)) int_rounds = int(rounds) if rounds != str(int_rounds): #forbid zero padding, etc. - raise ValueError, "invalid %s hash" % (cls.name,) + raise ValueError("invalid %s hash" % (cls.name,)) raw_salt = adapted_b64_decode(salt) raw_chk = adapted_b64_decode(chk) if chk else None return cls( @@ -194,13 +194,13 @@ class dlitz_pbkdf2_sha1(ExtendedHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") m = cls._pat.match(hash) if not m: - raise ValueError, "invalid dlitz_pbkdf2_crypt hash" + raise ValueError("invalid dlitz_pbkdf2_crypt hash") rounds, salt, chk = m.group("rounds", "salt", "chk") if rounds.startswith("0"): #zero not allowed, nor left-padded with zeroes - raise ValueError, "invalid dlitz_pbkdf2_crypt hash" + raise ValueError("invalid dlitz_pbkdf2_crypt hash") rounds = int(rounds, 16) if rounds else 400 return cls( rounds=rounds, @@ -277,10 +277,10 @@ class grub_pbkdf2_sha512(ExtendedHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") ident = cls._ident if not hash.startswith(ident): - raise ValueError, "invalid %s hash" % (cls.name,) + raise ValueError("invalid %s hash" % (cls.name,)) parts = hash[len(ident):].split(".") if len(parts) == 3: rounds, salt, chk = parts @@ -288,10 +288,10 @@ class grub_pbkdf2_sha512(ExtendedHandler): rounds, salt = parts chk = None else: - raise ValueError, "invalid %s hash" % (cls.name,) + raise ValueError("invalid %s hash" % (cls.name,)) int_rounds = int(rounds) if rounds != str(int_rounds): #forbid zero padding, etc. - raise ValueError, "invalid %s hash" % (cls.name,) + raise ValueError("invalid %s hash" % (cls.name,)) raw_salt = unhexlify(salt) raw_chk = unhexlify(chk) if chk else None return cls( diff --git a/passlib/handlers/phpass.py b/passlib/handlers/phpass.py index 6c93554..bb9bfd9 100644 --- a/passlib/handlers/phpass.py +++ b/passlib/handlers/phpass.py @@ -78,10 +78,10 @@ class phpass(ExtendedHandler): def norm_ident(cls, ident, strict=False): if not ident: if strict: - raise ValueError, "no ident specified" + raise ValueError("no ident specified") ident = "P" if ident not in ("P", "H"): - raise ValueError, "invalid ident: %r" % (ident,) + raise ValueError("invalid ident: %r" % (ident,)) return ident #========================================================= @@ -111,10 +111,10 @@ class phpass(ExtendedHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") m = cls._pat.match(hash) if not m: - raise ValueError, "invalid phpass portable hash" + raise ValueError("invalid phpass portable hash") ident, rounds, salt, chk = m.group("ident", "rounds", "salt", "chk") return cls( ident=ident, diff --git a/passlib/handlers/postgres.py b/passlib/handlers/postgres.py index 8ce4abf..0e8bb33 100644 --- a/passlib/handlers/postgres.py +++ b/passlib/handlers/postgres.py @@ -56,7 +56,7 @@ class postgres_md5(object): @classmethod def genhash(cls, secret, config, user): if config and not cls.identify(config): - raise ValueError, "not a postgres-md5 hash" + raise ValueError("not a postgres-md5 hash") return cls.encrypt(secret, user) #========================================================= @@ -76,7 +76,7 @@ class postgres_md5(object): @classmethod def verify(cls, secret, hash, user): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") return hash == cls.genhash(secret, hash, user) #========================================================= diff --git a/passlib/handlers/sha1_crypt.py b/passlib/handlers/sha1_crypt.py index ab7af26..a4c4926 100644 --- a/passlib/handlers/sha1_crypt.py +++ b/passlib/handlers/sha1_crypt.py @@ -4,7 +4,7 @@ #========================================================= #imports #========================================================= -from __future__ import with_statement, absolute_import + #core from hmac import new as hmac from hashlib import sha1 @@ -75,13 +75,13 @@ class sha1_crypt(ExtendedHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") m = cls._pat.match(hash) if not m: - raise ValueError, "invalid sha1_crypt hash" + raise ValueError("invalid sha1_crypt hash") rounds, salt, chk = m.group("rounds", "salt", "chk") if rounds.startswith("0"): - raise ValueError, "invalid sha1-crypt hash (zero-padded rounds)" + raise ValueError("invalid sha1-crypt hash (zero-padded rounds)") return cls( rounds=int(rounds), salt=salt, diff --git a/passlib/handlers/sha2_crypt.py b/passlib/handlers/sha2_crypt.py index c430d09..6bd1de0 100644 --- a/passlib/handlers/sha2_crypt.py +++ b/passlib/handlers/sha2_crypt.py @@ -45,7 +45,7 @@ def raw_sha_crypt(secret, salt, rounds, hash): #validate salt if any(c in salt for c in '\x00$'): - raise ValueError, "invalid chars in salt" + raise ValueError("invalid chars in salt") if len(salt) > 16: salt = salt[:16] @@ -288,15 +288,15 @@ class sha256_crypt(MultiBackendHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") #TODO: write non-regexp based parser, # and rely on norm_salt etc to handle more of the validation. m = cls._pat.match(hash) if not m: - raise ValueError, "invalid sha256-crypt hash" + raise ValueError("invalid sha256-crypt hash") rounds, salt1, salt2, chk = m.group("rounds", "salt1", "salt2", "chk") if rounds and rounds.startswith("0"): - raise ValueError, "invalid sha256-crypt hash (zero-padded rounds)" + raise ValueError("invalid sha256-crypt hash (zero-padded rounds)") return cls( implicit_rounds = not rounds, rounds=int(rounds) if rounds else 5000, @@ -435,15 +435,15 @@ class sha512_crypt(MultiBackendHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") #TODO: write non-regexp based parser, # and rely on norm_salt etc to handle more of the validation. m = cls._pat.match(hash) if not m: - raise ValueError, "invalid sha512-crypt hash" + raise ValueError("invalid sha512-crypt hash") rounds, salt1, salt2, chk = m.group("rounds", "salt1", "salt2", "chk") if rounds and rounds.startswith("0"): - raise ValueError, "invalid sha512-crypt hash (zero-padded rounds)" + raise ValueError("invalid sha512-crypt hash (zero-padded rounds)") return cls( implicit_rounds = not rounds, rounds=int(rounds) if rounds else 5000, diff --git a/passlib/handlers/sun_md5_crypt.py b/passlib/handlers/sun_md5_crypt.py index 514c4de..375fc08 100644 --- a/passlib/handlers/sun_md5_crypt.py +++ b/passlib/handlers/sun_md5_crypt.py @@ -246,10 +246,10 @@ class sun_md5_crypt(ExtendedHandler): @classmethod def from_string(cls, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") m = cls._pat.match(hash) if not m: - raise ValueError, "invalid sun-md5-crypt hash" + raise ValueError("invalid sun-md5-crypt hash") rounds, salt, chk = m.group("rounds", "salt", "chk") #NOTE: this is *additional* rounds added to base 4096 specified by spec. #XXX: should we note whether "$" or "," was used as rounds separator? diff --git a/passlib/registry.py b/passlib/registry.py index 6cbad47..df60874 100644 --- a/passlib/registry.py +++ b/passlib/registry.py @@ -34,12 +34,12 @@ class PasslibRegistryProxy(object): def __getattr__(self, attr): if attr.startswith("_"): - raise AttributeError, "missing attribute: %r" % (attr,) + raise AttributeError("missing attribute: %r" % (attr,)) handler = get_crypt_handler(attr, None) if handler: return handler else: - raise AttributeError, "unknown password hash: %r" % (attr,) + raise AttributeError("unknown password hash: %r" % (attr,)) def __setattr__(self, attr, value): register_crypt_handler(value, name=attr) @@ -165,28 +165,28 @@ def register_crypt_handler(handler, force=False, name=None): #validate handler if not is_crypt_handler(handler): - raise TypeError, "object does not appear to be a crypt handler: %r" % (handler,) + raise TypeError("object does not appear to be a crypt handler: %r" % (handler,)) assert handler, "crypt handlers must be boolean True: %r" % (handler,) #if name specified, make sure it matched #(this is mainly used as a check to help __setattr__) if name: if name != handler.name: - raise ValueError, "handlers must be stored only under their own name" + raise ValueError("handlers must be stored only under their own name") else: name = handler.name #validate name if not name: - raise ValueError, "name is null: %r" % (name,) + raise ValueError("name is null: %r" % (name,)) if name.lower() != name: - raise ValueError, "name must be lower-case: %r" % (name,) + raise ValueError("name must be lower-case: %r" % (name,)) if not _name_re.match(name): - raise ValueError, "invalid characters in name (must be 3+ characters, begin with a-z, and contain only underscore, a-z, 0-9): %r" % (name,) + raise ValueError("invalid characters in name (must be 3+ characters, begin with a-z, and contain only underscore, a-z, 0-9): %r" % (name,)) if '__' in name: - raise ValueError, "name may not contain double-underscores: %r" % (name,) + raise ValueError("name may not contain double-underscores: %r" % (name,)) if name in _forbidden_names: - raise ValueError, "that name is not allowed: %r" % (name,) + raise ValueError("that name is not allowed: %r" % (name,)) #check for existing handler other = _handlers.get(name) @@ -196,7 +196,7 @@ def register_crypt_handler(handler, force=False, name=None): if force: log.warning("overriding previous handler registered to name %r: %r", name, other) else: - raise KeyError, "a handler has already registered for the name %r: %r (use force=True to override)" % (name, other) + raise KeyError("a handler has already registered for the name %r: %r (use force=True to override)" % (name, other)) #register handler in dict _handlers[name] = handler @@ -258,7 +258,7 @@ def get_crypt_handler(name, default=Undef): #fail! if default is Undef: - raise KeyError, "no crypt handler found for algorithm: %r" % (name,) + raise KeyError("no crypt handler found for algorithm: %r" % (name,)) else: return default diff --git a/passlib/tests/genconfig.py b/passlib/tests/genconfig.py index c836b80..0abdaab 100644 --- a/passlib/tests/genconfig.py +++ b/passlib/tests/genconfig.py @@ -45,7 +45,7 @@ class HashTimer(object): # self.handler = handler = get_crypt_handler(name) if 'rounds' not in handler.setting_kwds: - raise ValueError, "scheme does not support rounds: %r" % (handler.name,) + raise ValueError("scheme does not support rounds: %r" % (handler.name,)) self.min_rounds = getattr(handler, "min_rounds", 2) self.max_rounds = getattr(handler, "max_rounds", (1<<32)-1) rc = self.rounds_cost = getattr(handler, "rounds_cost", "linear") @@ -66,7 +66,7 @@ class HashTimer(object): return int(logb(rps*target,2)+.5) erradj = 1.1 else: - raise NotImplementedError, "unknown rounds cost function: %r" % (rc,) + raise NotImplementedError("unknown rounds cost function: %r" % (rc,)) self.get_rps = get_rps self.guess_rounds = guess_rounds self.erradj = erradj @@ -109,7 +109,7 @@ class HashTimer(object): to taking about ``target`` seconds to hash a password. """ if target <= 0: - raise ValueError, "target must be > 0" + raise ValueError("target must be > 0") log = self.log name = self.handler.name @@ -201,7 +201,7 @@ class HashTimer(object): "return estimated rounds per second based on cached results" cache = self.cache if not cache: - raise RuntimeError, "should not be called until cache populated by find_rounds()" + raise RuntimeError("should not be called until cache populated by find_rounds()") get_rps = self.get_rps rps = sum(r*get_rps(r,d) for r,d in cache.iteritems())/sum(cache) if rps > 1000: #for almost all cases, we'd return integer diff --git a/passlib/tests/test_utils_handlers.py b/passlib/tests/test_utils_handlers.py index 1750113..66fb168 100644 --- a/passlib/tests/test_utils_handlers.py +++ b/passlib/tests/test_utils_handlers.py @@ -223,7 +223,7 @@ class UnsaltedHash(ExtendedHandler): @classmethod def from_string(cls, hash): if not cls.identify(hash): - raise ValueError, "not a unsalted-example hash" + raise ValueError("not a unsalted-example hash") return cls(checksum=hash, strict=True) def to_string(self): @@ -250,7 +250,7 @@ class SaltedHash(ExtendedHandler): @classmethod def from_string(cls, hash): if not cls.identify(hash): - raise ValueError, "not a salted-example hash" + raise ValueError("not a salted-example hash") return cls(salt=hash[5:7], checksum=hash[7:], strict=True) _stub_checksum = '0' * 40 diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py index e7b59e1..ef6d9b4 100644 --- a/passlib/tests/utils.py +++ b/passlib/tests/utils.py @@ -348,10 +348,10 @@ class HandlerCase(TestCase): raise SkipTest if not cls.name: - raise AssertionError, "class must have .name attribute set" + raise AssertionError("class must have .name attribute set") if cls.setting_kwds is None: - raise AssertionError, "class must have .setting_kwds attribute set" + raise AssertionError("class must have .setting_kwds attribute set") def test_05_ext_handler(self): "check configuration of ExtendedHandler-derived classes" @@ -360,37 +360,37 @@ class HandlerCase(TestCase): raise SkipTest if any(k not in cls.setting_kwds for k in cls._extra_init_settings): - raise AssertionError, "_extra_init_settings must be subset of setting_kwds" + raise AssertionError("_extra_init_settings must be subset of setting_kwds") if 'salt' in cls.setting_kwds: if cls.min_salt_chars > cls.max_salt_chars: - raise AssertionError, "min salt chars too large" + raise AssertionError("min salt chars too large") if cls.default_salt_chars < cls.min_salt_chars: - raise AssertionError, "default salt chars too small" + raise AssertionError("default salt chars too small") if cls.default_salt_chars > cls.max_salt_chars: - raise AssertionError, "default salt chars too large" + raise AssertionError("default salt chars too large") if any(c not in cls.salt_charset for c in cls.default_salt_charset): - raise AssertionError, "default salt charset not subset of salt charset" + raise AssertionError("default salt charset not subset of salt charset") if 'rounds' in cls.setting_kwds: if cls.max_rounds is None: - raise AssertionError, "max rounds not specified" + raise AssertionError("max rounds not specified") if cls.min_rounds > cls.max_rounds: - raise AssertionError, "min rounds too large" + raise AssertionError("min rounds too large") if cls.default_rounds is not None: if cls.default_rounds < cls.min_rounds: - raise AssertionError, "default rounds too small" + raise AssertionError("default rounds too small") if cls.default_rounds > cls.max_rounds: - raise AssertionError, "default rounds too large" + raise AssertionError("default rounds too large") if cls.rounds_cost not in ("linear", "log2"): - raise AssertionError, "unknown rounds cost function" + raise AssertionError("unknown rounds cost function") def test_06_backend_handler(self): "check configuration of MultiBackendHandler-derived classes" @@ -413,7 +413,7 @@ class HandlerCase(TestCase): self.assertRaises(ValueError, h.set_backend, backend) else: #failure eg: used classmethod instead of classproperty in _has_backend_xxx - raise TypeError, "has_backend(%r) returned invalid value: %r" % (backend, r,) + raise TypeError("has_backend(%r) returned invalid value: %r" % (backend, r,)) finally: h.set_backend(orig) diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py index 08e7b8f..1cf8d4b 100644 --- a/passlib/utils/__init__.py +++ b/passlib/utils/__init__.py @@ -259,18 +259,18 @@ def list_to_bytes(value, bytes=None, order="big"): """ #make sure all elements have valid values if any( elem < 0 or elem > 255 for elem in value): - raise ValueError, "value must be list of integers in range(0,256): %r" % (value,) + raise ValueError("value must be list of integers in range(0,256): %r" % (value,)) #validate bytes / upper if bytes is None: bytes = len(value) if bytes == 0: - raise ValueError, "empty list not allowed" + raise ValueError("empty list not allowed") else: if bytes < 1: - raise ValueError, "bytes must be None or >= 1: %r" % (bytes,) + raise ValueError("bytes must be None or >= 1: %r" % (bytes,)) if len(value) > bytes: - raise ValueError, "list too large for number of bytes: bytes=%r len=%r" % (bytes, len(value)) + raise ValueError("list too large for number of bytes: bytes=%r len=%r" % (bytes, len(value))) #encode list in big endian mode out = ''.join( chr(elem) for elem in value ) @@ -348,7 +348,7 @@ def adapted_b64_decode(data, sixthree="."): if off == 0: return b64decode(data, "./") elif off == 1: - raise ValueError, "invalid bas64 input" + raise ValueError("invalid bas64 input") elif off == 2: return b64decode(data + "==", "./") else: @@ -433,10 +433,10 @@ def getrandstr(rng, charset, count): """return character string containg *count* number of chars, whose elements are drawn from specified charset, using specified rng""" #check alphabet & count if count < 0: - raise ValueError, "count must be >= 0" + raise ValueError("count must be >= 0") letters = len(charset) if letters == 0: - raise ValueError, "alphabet must not be empty" + raise ValueError("alphabet must not be empty") if letters == 1: return charset * count diff --git a/passlib/utils/h64.py b/passlib/utils/h64.py index 27c376c..3582e2b 100644 --- a/passlib/utils/h64.py +++ b/passlib/utils/h64.py @@ -81,7 +81,7 @@ def decode_bytes(source): tail = end % 4 if tail == 1: #only 6 bits left, can't encode a whole byte! - raise ValueError, "input string length cannot be == 1 mod 4" + raise ValueError("input string length cannot be == 1 mod 4") end -= tail idx = 0 while idx < end: @@ -124,12 +124,12 @@ def decode_int6(value): try: return decode_6bit(value) except KeyError: - raise ValueError, "invalid character" + raise ValueError("invalid character") def encode_int6(value): "encodes 6-bit integer -> single hash64 character" if value < 0 or value > 63: - raise ValueError, "value out of range" + raise ValueError("value out of range") return encode_6bit(value) #--------------------------------------------------------------------- @@ -140,7 +140,7 @@ def decode_int12(value): try: return (decode_6bit(value[1])<<6)+decode_6bit(value[0]) except KeyError: - raise ValueError, "invalid character" + raise ValueError("invalid character") def encode_int12(value): "encodes 12-bit integer -> 2 char hash64 string (little-endian order)" @@ -177,7 +177,7 @@ def decode_int24(value): (decode_6bit(value[2])<<12)+\ (decode_6bit(value[3])<<18) except KeyError: - raise ValueError, "invalid character" + raise ValueError("invalid character") def encode_int24(value): "encodes 24-bit integer -> 4 char hash64 string (little-endian order)" @@ -237,7 +237,7 @@ def decode_int(source, big=False): out = (out<<6) + decode_6bit(c) return out except KeyError: - raise ValueError, "invalid character in string" + raise ValueError("invalid character in string") def encode_int(value, count, big=False): """encode integer into hash-64 format @@ -250,7 +250,7 @@ def encode_int(value, count, big=False): a hash64 string of length ``count``. """ if value < 0: - raise ValueError, "value cannot be negative" + raise ValueError("value cannot be negative") if big: itr = xrange(6*count-6, -6, -6) else: diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py index d2428d6..23d5ed1 100644 --- a/passlib/utils/handlers.py +++ b/passlib/utils/handlers.py @@ -65,7 +65,7 @@ class SimpleHandler(object): "attr for checking if class has ANY settings, memoizes itself on first use" if cls.name is None: #otherwise this would optimize itself away prematurely - raise RuntimeError, "_has_settings must only be called on subclass: %r" % (cls,) + raise RuntimeError("_has_settings must only be called on subclass: %r" % (cls,)) value = cls._has_settings = bool(cls.setting_kwds) return value @@ -89,15 +89,15 @@ class SimpleHandler(object): @classmethod def genconfig(cls, **settings): if cls._has_settings: - raise NotImplementedError, "%s subclass must implement genconfig()" % (cls,) + raise NotImplementedError("%s subclass must implement genconfig()" % (cls,)) else: if settings: - raise TypeError, "%s genconfig takes no kwds" % (cls.name,) + raise TypeError("%s genconfig takes no kwds" % (cls.name,)) return None @classmethod def genhash(cls, secret, config): - raise NotImplementedError, "%s subclass must implement genhash()" % (cls,) + raise NotImplementedError("%s subclass must implement genhash()" % (cls,)) #===================================================== #secondary interface (rarely subclassed) @@ -110,7 +110,7 @@ class SimpleHandler(object): @classmethod def verify(cls, secret, hash): if not hash: - raise ValueError, "no hash specified" + raise ValueError("no hash specified") return hash == cls.genhash(secret, hash) #===================================================== @@ -241,7 +241,7 @@ class ExtendedHandler(SimpleHandler): def _has_salt(cls): "attr for checking if salts are supported, memoizes itself on first use" if cls is ExtendedHandler: - raise RuntimeError, "not allowed for ExtendedHandler directly" + raise RuntimeError("not allowed for ExtendedHandler directly") value = cls._has_salt = 'salt' in cls.setting_kwds return value @@ -249,7 +249,7 @@ class ExtendedHandler(SimpleHandler): def _has_rounds(cls): "attr for checking if variable are supported, memoizes itself on first use" if cls is ExtendedHandler: - raise RuntimeError, "not allowed for ExtendedHandler directly" + raise RuntimeError("not allowed for ExtendedHandler directly") value = cls._has_rounds = 'rounds' in cls.setting_kwds return value @@ -260,7 +260,7 @@ class ExtendedHandler(SimpleHandler): # need to clean it all up. for now, there's this property, # to begin sweeping things under the rug. if cls is ExtendedHandler: - raise RuntimeError, "not allowed for ExtendedHandler directly" + raise RuntimeError("not allowed for ExtendedHandler directly") value = cls._salt_is_bytes = cls._has_salt and cls.salt_charset == ALL_BYTE_VALUES return value @@ -273,10 +273,10 @@ class ExtendedHandler(SimpleHandler): return None cc = cls.checksum_chars if cc and len(checksum) != cc: - raise ValueError, "%s checksum must be %d characters" % (cls.name, cc) + raise ValueError("%s checksum must be %d characters" % (cls.name, cc)) cs = cls.checksum_charset if cs and any(c not in cs for c in checksum): - raise ValueError, "invalid characters in %s checksum" % (cls.name,) + raise ValueError("invalid characters in %s checksum" % (cls.name,)) return checksum @classmethod @@ -304,12 +304,12 @@ class ExtendedHandler(SimpleHandler): if not cls._has_salt: #NOTE: special casing schemes which have no salt... if salt is not None: - raise TypeError, "%s does not support ``salt`` parameter" % (cls.name,) + raise TypeError("%s does not support ``salt`` parameter" % (cls.name,)) return None if salt is None: if strict: - raise ValueError, "no salt specified" + raise ValueError("no salt specified") if cls._salt_is_bytes: return getrandbytes(rng, cls.default_salt_chars) else: @@ -322,16 +322,16 @@ class ExtendedHandler(SimpleHandler): sc = cls.salt_charset for c in salt: if c not in sc: - raise ValueError, "invalid character in %s salt: %r" % (cls.name, c) + raise ValueError("invalid character in %s salt: %r" % (cls.name, c)) mn = cls.min_salt_chars if mn and len(salt) < mn: - raise ValueError, "%s salt string must be at least %d characters" % (cls.name, mn) + raise ValueError("%s salt string must be at least %d characters" % (cls.name, mn)) mx = cls.max_salt_chars if len(salt) > mx: if strict: - raise ValueError, "%s salt string must be at most %d characters" % (cls.name, mx) + raise ValueError("%s salt string must be at most %d characters" % (cls.name, mx)) salt = salt[:mx] return salt @@ -363,15 +363,15 @@ class ExtendedHandler(SimpleHandler): if not cls._has_rounds: #NOTE: special casing schemes which don't have rounds if rounds is not None: - raise TypeError, "%s does not support ``rounds``" % (cls.name,) + raise TypeError("%s does not support ``rounds``" % (cls.name,)) return None if rounds is None: if strict: - raise ValueError, "no rounds specified" + raise ValueError("no rounds specified") rounds = cls.default_rounds if rounds is None: - raise ValueError, "%s rounds value must be specified explicitly" % (cls.name,) + raise ValueError("%s rounds value must be specified explicitly" % (cls.name,)) return rounds if cls._strict_rounds_bounds: @@ -380,14 +380,14 @@ class ExtendedHandler(SimpleHandler): mn = cls.min_rounds if rounds < mn: if strict: - raise ValueError, "%s rounds must be >= %d" % (cls.name, mn) + raise ValueError("%s rounds must be >= %d" % (cls.name, mn)) warn("%s does not allow less than %d rounds: %d" % (cls.name, mn, rounds)) rounds = mn mx = cls.max_rounds if rounds > mx: if strict: - raise ValueError, "%s rounds must be <= %d" % (cls.name, mx) + raise ValueError("%s rounds must be <= %d" % (cls.name, mx)) warn("%s does not allow more than %d rounds: %d" % (cls.name, mx, rounds)) rounds = mx @@ -411,11 +411,11 @@ class ExtendedHandler(SimpleHandler): @classmethod def from_string(cls, hash): #pragma: no cover "return parsed instance from hash/configuration string; raising ValueError on invalid inputs" - raise NotImplementedError, "%s must implement from_string()" % (cls,) + raise NotImplementedError("%s must implement from_string()" % (cls,)) def to_string(self): #pragma: no cover "render instance to hash or configuration string (depending on if checksum attr is set)" - raise NotImplementedError, "%s must implement from_string()" % (type(self),) + raise NotImplementedError("%s must implement from_string()" % (type(self),)) ##def to_config_string(self): ## "helper for generating configuration string (ignoring hash)" @@ -437,7 +437,7 @@ class ExtendedHandler(SimpleHandler): if cls._has_settings: return cls(**settings).to_string() elif settings: - raise TypeError, "%s.genconfig() takes no arguments" % (cls.name,) + raise TypeError("%s.genconfig() takes no arguments" % (cls.name,)) else: return None @@ -452,7 +452,7 @@ class ExtendedHandler(SimpleHandler): def calc_checksum(self, secret): #pragma: no cover "given secret; calcuate and return encoded checksum portion of hash string, taking config from object state" - raise NotImplementedError, "%s must implement calc_checksum()" % (cls,) + raise NotImplementedError("%s must implement calc_checksum()" % (cls,)) #========================================================= #'application' interface (default implementation) @@ -521,9 +521,9 @@ class MultiBackendHandler(ExtendedHandler): if cls.has_backend(name): break else: - raise EnvironmentError, cls._no_backends_msg() + raise EnvironmentError(cls._no_backends_msg()) elif not cls.has_backend(name): - raise ValueError, "%s backend not available: %r" % (cls.name, name) + raise ValueError("%s backend not available: %r" % (cls.name, name)) cls.calc_checksum = getattr(cls, "_calc_checksum_" + name) cls._backend = name return name diff --git a/passlib/utils/pbkdf2.py b/passlib/utils/pbkdf2.py index 460925c..be965b6 100644 --- a/passlib/utils/pbkdf2.py +++ b/passlib/utils/pbkdf2.py @@ -73,7 +73,7 @@ def _resolve_prf(prf): #fall back to stdlib implementation digest_const = getattr(hashlib, digest, None) if not digest_const: - raise ValueError, "unknown hash algorithm: %r" % (digest,) + raise ValueError("unknown hash algorithm: %r" % (digest,)) digest_size = digest_const().digest_size hmac_const = hmac.new def encode_block(key, msg): @@ -81,7 +81,7 @@ def _resolve_prf(prf): return encode_block, digest_size else: - raise ValueError, "unknown prf algorithm: %r" % (prf,) + raise ValueError("unknown prf algorithm: %r" % (prf,)) elif callable(prf): #assume it's a callable, use it directly @@ -89,7 +89,7 @@ def _resolve_prf(prf): return prf, digest_size else: - raise TypeError, "prf must be string or callable" + raise TypeError("prf must be string or callable") def pbkdf2(secret, salt, rounds, keylen, prf="hmac-sha1"): """pkcs#5 password-based key derivation v2.0 @@ -137,7 +137,7 @@ def pbkdf2(secret, salt, rounds, keylen, prf="hmac-sha1"): if prf == "hmac-sha1" and _EVP: #NOTE: doing check here, because M2crypto won't take longs (which this is, under 32bit) if keylen > MAX_HMAC_SHA1_KEYLEN: - raise ValueError, "key length too long" + raise ValueError("key length too long") #NOTE: M2crypto reliably segfaults for me if given keylengths # larger than 40 (crashes at 41 on one system, 61 on another). @@ -151,7 +151,7 @@ def pbkdf2(secret, salt, rounds, keylen, prf="hmac-sha1"): #figure out how many blocks we'll need bcount = (keylen+digest_size-1)//digest_size if bcount >= MAX_BLOCKS: - raise ValueError, "key length to long" + raise ValueError("key length to long") #build up key from blocks out = StringIO() |