From d1252cfb8ef613e290a23e0e9cabd9d135a129ca Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 26 Jan 2016 16:49:23 +0100 Subject: cli: Don't encode/decode for stdin/stdout on Python 3 https://fedorahosted.org/freeipa/ticket/5638 Reviewed-By: Jan Cholasta --- ipalib/cli.py | 41 ++++++++++++++++++++++++----------------- 1 file 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: -- cgit