diff options
author | Jonah BrĂ¼chert <jbb@kaidan.im> | 2024-02-13 01:33:23 +0100 |
---|---|---|
committer | Jonah BrĂ¼chert <jbb@kaidan.im> | 2024-02-13 01:33:23 +0100 |
commit | d8254fd9186c3d1c08664fc8a4b3c103c598c836 (patch) | |
tree | b946ed4ae95feac18066d6aa9272e9d0e80e4a91 /src/lib/Bcfg2/Compat.py | |
parent | 20f29bbc3eebcca8b3dd1c6c1dba2867e9af01de (diff) | |
download | bcfg2-d8254fd9186c3d1c08664fc8a4b3c103c598c836.tar.gz bcfg2-d8254fd9186c3d1c08664fc8a4b3c103c598c836.tar.bz2 bcfg2-d8254fd9186c3d1c08664fc8a4b3c103c598c836.zip |
Add back base64 compat
Diffstat (limited to 'src/lib/Bcfg2/Compat.py')
-rw-r--r-- | src/lib/Bcfg2/Compat.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/lib/Bcfg2/Compat.py b/src/lib/Bcfg2/Compat.py index 2e13301f8..251c80f4c 100644 --- a/src/lib/Bcfg2/Compat.py +++ b/src/lib/Bcfg2/Compat.py @@ -102,6 +102,23 @@ 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: |