summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2016-01-26 16:49:23 +0100
committerJan Cholasta <jcholast@redhat.com>2016-02-17 10:41:29 +0100
commitd1252cfb8ef613e290a23e0e9cabd9d135a129ca (patch)
tree5ff4e420b4d76ac46913a8c6ef7530e39bb886cf
parent5b6a1ce8a81a9dac85f13a4f52b9ddddb822590a (diff)
downloadfreeipa-d1252cfb8ef613e290a23e0e9cabd9d135a129ca.tar.gz
freeipa-d1252cfb8ef613e290a23e0e9cabd9d135a129ca.tar.xz
freeipa-d1252cfb8ef613e290a23e0e9cabd9d135a129ca.zip
cli: Don't encode/decode for stdin/stdout on Python 3
https://fedorahosted.org/freeipa/ticket/5638 Reviewed-By: Jan Cholasta <jcholast@redhat.com>
-rw-r--r--ipalib/cli.py41
1 files changed, 24 insertions, 17 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 136e0aeb8..e1abaa5d5 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -130,24 +130,31 @@ class textui(backend.Backend):
return 'UTF-8'
return stream.encoding
- def decode(self, value):
- """
- Decode text from stdin.
- """
- if type(value) is bytes:
- encoding = self.__get_encoding(sys.stdin)
- return value.decode(encoding)
- elif type(value) in (list, tuple):
- return tuple(self.decode(v) for v in value)
- return value
+ if six.PY2:
+ def decode(self, value):
+ """
+ Decode text from stdin.
+ """
+ if type(value) is bytes:
+ encoding = self.__get_encoding(sys.stdin)
+ return value.decode(encoding)
+ elif type(value) in (list, tuple):
+ return tuple(self.decode(v) for v in value)
+ return value
- def encode(self, unicode_text):
- """
- Encode text for output to stdout.
- """
- assert type(unicode_text) is unicode
- encoding = self.__get_encoding(sys.stdout)
- return unicode_text.encode(encoding)
+ def encode(self, unicode_text):
+ """
+ Encode text for output to stdout.
+ """
+ assert type(unicode_text) is unicode
+ encoding = self.__get_encoding(sys.stdout)
+ return unicode_text.encode(encoding)
+ else:
+ def decode(self, value):
+ return value
+
+ def encode(self, value):
+ return value
def choose_number(self, n, singular, plural=None):
if n == 1 or plural is None: