diff options
author | Jonah BrĂ¼chert <jbb@kaidan.im> | 2024-02-01 12:07:24 +0100 |
---|---|---|
committer | Jonah BrĂ¼chert <jbb@kaidan.im> | 2024-02-01 12:13:39 +0100 |
commit | c7b3b32e5768a165bbc156f8abb12af428152ee3 (patch) | |
tree | 2a5a420e949cee95f91150f5e596517d9b9cb5c3 /src/lib/Bcfg2/Compat.py | |
parent | e7eaa48daf65046dedc97574cf433296e27db5bd (diff) | |
download | bcfg2-c7b3b32e5768a165bbc156f8abb12af428152ee3.tar.gz bcfg2-c7b3b32e5768a165bbc156f8abb12af428152ee3.tar.bz2 bcfg2-c7b3b32e5768a165bbc156f8abb12af428152ee3.zip |
Apply changes from the magically working debian package
Diffstat (limited to 'src/lib/Bcfg2/Compat.py')
-rw-r--r-- | src/lib/Bcfg2/Compat.py | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/src/lib/Bcfg2/Compat.py b/src/lib/Bcfg2/Compat.py index 9a8d76c47..2e13301f8 100644 --- a/src/lib/Bcfg2/Compat.py +++ b/src/lib/Bcfg2/Compat.py @@ -88,6 +88,13 @@ def u_str(string, encoding=None): else: return unicode(string) + +def ensure_binary(string, encoding='utf-8'): + if type(string) == unicode: + return string.encode(encoding) + return string + + try: from functools import wraps except ImportError: @@ -95,24 +102,6 @@ except ImportError: """ implementation of functools.wraps() for python 2.4 """ return lambda f: f - -# base64 compat -if sys.hexversion >= 0x03000000: - from base64 import b64encode as _b64encode, b64decode as _b64decode - - @wraps(_b64encode) - def b64encode(val, **kwargs): # pylint: disable=C0111 - try: - return _b64encode(val, **kwargs) - except TypeError: - return _b64encode(val.encode('UTF-8'), **kwargs).decode('UTF-8') - - @wraps(_b64decode) - def b64decode(val, **kwargs): # pylint: disable=C0111 - return _b64decode(val.encode('UTF-8'), **kwargs).decode('UTF-8') -else: - from base64 import b64encode, b64decode - try: input = raw_input except NameError: |