summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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: