diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2011-06-02 17:40:37 -0400 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2011-06-02 17:40:37 -0400 |
| commit | 72edc4db75771aa1be6cad322f86d3a486b33898 (patch) | |
| tree | 6c8150e067d05ce0c387e6be29fffcb7a11fd65d /passlib/utils | |
| parent | 45151c2ceda481ff891f0fe35c500aebda7f1aea (diff) | |
| download | passlib-72edc4db75771aa1be6cad322f86d3a486b33898.tar.gz | |
updated changelog
Diffstat (limited to 'passlib/utils')
| -rw-r--r-- | passlib/utils/__init__.py | 15 |
1 files changed, 15 insertions, 0 deletions
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 #================================================================================= |
