summaryrefslogtreecommitdiffstats
path: root/ipapython
diff options
context:
space:
mode:
authorJan Cholasta <jcholast@redhat.com>2015-08-31 09:08:38 +0200
committerJan Cholasta <jcholast@redhat.com>2015-09-07 08:00:11 +0200
commitcc53526fd21d3faa7b90cd873713279c3ce049f5 (patch)
treefc2edb6f2ab2027cdce60f796134488f3ec358c7 /ipapython
parentcf9bf9dcafa6c6d434440e7b106f1886614eec05 (diff)
downloadfreeipa-cc53526fd21d3faa7b90cd873713279c3ce049f5.tar.gz
freeipa-cc53526fd21d3faa7b90cd873713279c3ce049f5.tar.xz
freeipa-cc53526fd21d3faa7b90cd873713279c3ce049f5.zip
Decode script arguments using file system encoding
This mimics Python 3's behavior, where sys.argv is automatically decoded using file system encoding, as returned by sys.getfilesystemencoding(). This includes reimplementation of os.fsdecode() from Python 3. Reviewed-By: Petr Viktorin <pviktori@redhat.com>
Diffstat (limited to 'ipapython')
-rw-r--r--ipapython/ipautil.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
index 80f79aac5..2402689cc 100644
--- a/ipapython/ipautil.py
+++ b/ipapython/ipautil.py
@@ -1352,3 +1352,22 @@ def private_ccache(path=None):
if os.path.exists(path):
os.remove(path)
+
+
+if six.PY2:
+ def fsdecode(value):
+ """
+ Decode argument using the file system encoding, as returned by
+ `sys.getfilesystemencoding()`.
+ """
+ if isinstance(value, six.binary_type):
+ return value.decode(sys.getfilesystemencoding())
+ elif isinstance(value, six.text_type):
+ return value
+ else:
+ raise TypeError("expect {0} or {1}, not {2}".format(
+ six.binary_type.__name__,
+ six.text_type.__name__,
+ type(value).__name__))
+else:
+ fsdecode = os.fsdecode #pylint: disable=no-member