diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2011-06-22 17:42:07 -0400 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2011-06-22 17:42:07 -0400 |
| commit | 6ed2237c5bb82b35d01c5afe2bb1421161ac967e (patch) | |
| tree | c5674e1779eea26ac88b7c3fb2217edd5494ef84 /passlib/utils | |
| parent | 4d57bdffd00d8870a186f38fca83a5d2fcbd7fc5 (diff) | |
| download | passlib-6ed2237c5bb82b35d01c5afe2bb1421161ac967e.tar.gz | |
replaced redundant code in a few places w/ new identify_prefix() helper
Diffstat (limited to 'passlib/utils')
| -rw-r--r-- | passlib/utils/__init__.py | 2 | ||||
| -rw-r--r-- | passlib/utils/handlers.py | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py index 4b75a53..ffbc60f 100644 --- a/passlib/utils/__init__.py +++ b/passlib/utils/__init__.py @@ -6,7 +6,7 @@ from base64 import b64encode, b64decode from codecs import lookup as _lookup_codec from cStringIO import StringIO -from functools import update_wrapper +##from functools import update_wrapper from hashlib import sha256 import logging; log = logging.getLogger(__name__) from math import log as logb diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py index cfa9381..8d23200 100644 --- a/passlib/utils/handlers.py +++ b/passlib/utils/handlers.py @@ -60,6 +60,18 @@ def identify_regexp(hash, pat): return False return pat.match(hash) is not None +def identify_prefix(hash, prefix): + "identify() helper for matching against prefixes" + #NOTE: prefix may be a tuple of strings (since startswith supports that) + if not hash: + return False + if isinstance(hash, bytes): + try: + hash = hash.decode("ascii") + except UnicodeDecodeError: + return False + return hash.startswith(prefix) + #========================================================= #parsing helpers #========================================================= |
