summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Compat.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-05-07 13:29:50 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-05-07 13:29:50 -0400
commita430fb769d2c0c2bf880a8d572d5bb0c41435dd1 (patch)
tree049e315e9bc2dbbc0f30aa77412a5e20b27363a6 /src/lib/Bcfg2/Compat.py
parent5e2fcd850b334efce569db6b5a5199208520015f (diff)
downloadbcfg2-a430fb769d2c0c2bf880a8d572d5bb0c41435dd1.tar.gz
bcfg2-a430fb769d2c0c2bf880a8d572d5bb0c41435dd1.tar.bz2
bcfg2-a430fb769d2c0c2bf880a8d572d5bb0c41435dd1.zip
Compat: better b64encode/decode funcs for py3k
Diffstat (limited to 'src/lib/Bcfg2/Compat.py')
-rw-r--r--src/lib/Bcfg2/Compat.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/lib/Bcfg2/Compat.py b/src/lib/Bcfg2/Compat.py
index 2ceb7555b..c376b7a2d 100644
--- a/src/lib/Bcfg2/Compat.py
+++ b/src/lib/Bcfg2/Compat.py
@@ -89,17 +89,28 @@ def u_str(string, encoding=None):
else:
return unicode(string)
+try:
+ from functools import wraps
+except ImportError:
+ def wraps(wrapped): # pylint: disable=W0613
+ """ 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
- def b64encode(val):
+ @wraps(_b64encode)
+ def b64encode(val, **kwargs):
try:
- return _b64encode(val)
+ return _b64encode(val, **kwargs)
except TypeError:
- return _b64encode(val.encode('UTF-8')).decode('UTF-8')
+ return _b64encode(val.encode('UTF-8'), **kwargs).decode('UTF-8')
- b64decode = lambda s: _b64decode(s.encode('UTF-8')).decode('UTF-8')
+ @wraps(_b64decode)
+ def b64decode(val, **kwargs):
+ return _b64decode(val.encode('UTF-8'), **kwargs).decode('UTF-8')
else:
from base64 import b64encode, b64decode
@@ -248,14 +259,6 @@ except ImportError:
from md5 import md5
-try:
- from functools import wraps
-except ImportError:
- def wraps(wrapped): # pylint: disable=W0613
- """ implementation of functools.wraps() for python 2.4 """
- return lambda f: f
-
-
def oct_mode(mode):
""" Convert a decimal number describing a POSIX permissions mode
to a string giving the octal mode. In Python 2, this is a synonym