diff --git a/irods/message/property.py b/irods/message/property.py index 5277f78c..443d3717 100644 --- a/irods/message/property.py +++ b/irods/message/property.py @@ -58,12 +58,18 @@ def __init__(self, length=None): self.length = length super(BinaryProperty, self).__init__() - def format(self, value): - if six.PY3 and not isinstance(value, bytes): - val = b64encode(value.encode('utf-8')) - else: - val = b64encode(value) - return val + if six.PY2: + def format(self, value): + return b64encode(value) + + else: + # Python 3 + def format(self, value): + if isinstance(value, bytes): + return b64encode(value) + else: + return b64encode(value.encode()) + def parse(self, value): val = b64decode(value) @@ -76,10 +82,25 @@ def __init__(self, length=None): self.length = length super(StringProperty, self).__init__() - def format(self, value): - if six.PY2 and isinstance(value, unicode): - return value - return str(value) + + if six.PY2: + def format(self, value): + if isinstance(value, str) or isinstance(value, unicode): + return value + + return str(value) + + else: + # Python 3 + def format(self, value): + if isinstance(value, str): + return value + + if isinstance(value, bytes): + return value.decode() + + return str(value) + def parse(self, value): return value