diff options
| -rw-r--r-- | CHANGES | 4 | ||||
| -rw-r--r-- | passlib/utils/__init__.py | 15 |
2 files changed, 18 insertions, 1 deletions
@@ -6,7 +6,9 @@ Release History **1.5** (NOT YET RELEASED) - * added support for using BCryptor as bcrypt backend + * added support for FSHP family of hashes + * added support for Cryptacular's PBKDF2 format + * added support for using BCryptor as BCrypt backend * added quickstart guide to documentation * removed deprecated parts of :mod:`passlib.utils.handlers`. diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py index b49d3cd..176074a 100644 --- a/passlib/utils/__init__.py +++ b/passlib/utils/__init__.py @@ -91,6 +91,21 @@ class UndefType(object): #: singleton used as default kwd value in some functions, indicating "NO VALUE" Undef = UndefType() +#========================================================== +#bytes/unicode helpers +#========================================================== +if sys.version_info < (2,6): + bytes = str + +def to_bytes(source, name="value", encoding="utf8"): + "helper to convert unicode to utf8; passes existing code through unchanged" + if isinstance(source, unicode): + return source.encode(encoding) + elif isinstance(source, bytes): + return source + else: + raise TypeError(name + " must be bytes or unicode") + #================================================================================= #os crypt helpers #================================================================================= |
