cli: Don't encode/decode for stdin/stdout on Python 3

https://fedorahosted.org/freeipa/ticket/5638

Reviewed-By: Jan Cholasta <jcholast@redhat.com>
This commit is contained in:
Petr Viktorin
2016-01-26 16:49:23 +01:00
committed by Jan Cholasta
parent 5b6a1ce8a8
commit d1252cfb8e

View File

@@ -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: