summaryrefslogtreecommitdiff
path: root/pyuno/source/module/uno.py
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2012-11-25 15:57:38 +0100
committerMichael Stahl <mstahl@redhat.com>2012-11-25 16:06:40 +0100
commita38b59265c08276fce6d73ce541cadb41aa6d347 (patch)
treeafd49db7620084f2381b71a97dcacec01180a47c /pyuno/source/module/uno.py
parent87c923be603d0b3706c481281549a79c8b8bcd41 (diff)
pyuno: adjust uno.ByteSequence to work with "bytes"
This is necessary for Python3; "str" type is still accepted so it runs on Python 2 as well. Change-Id: I51098feca00e4cd8ce3ceebf663d4ce79252cbcd
Diffstat (limited to 'pyuno/source/module/uno.py')
-rw-r--r--pyuno/source/module/uno.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/pyuno/source/module/uno.py b/pyuno/source/module/uno.py
index 4ff2606b1e46..86011f3b4c97 100644
--- a/pyuno/source/module/uno.py
+++ b/pyuno/source/module/uno.py
@@ -199,8 +199,10 @@ class Char:
class ByteSequence:
def __init__(self, value):
- if isinstance(value, str):
+ if isinstance(value, bytes):
self.value = value
+ elif isinstance(value, str):
+ self.value = value.encode("utf-8") # Python 2 compatibility
elif isinstance(value, ByteSequence):
self.value = value.value
else:
@@ -212,8 +214,10 @@ class ByteSequence:
def __eq__(self, that):
if isinstance( that, ByteSequence):
return self.value == that.value
- if isinstance(that, str):
+ if isinstance(that, bytes):
return self.value == that
+ if isinstance(that, str):
+ return self.value == that.encode("utf-8")
return False
def __len__(self):
@@ -226,8 +230,10 @@ class ByteSequence:
return self.value.__iter__()
def __add__( self , b ):
- if isinstance( b, str ):
- return ByteSequence( self.value + b )
+ if isinstance( b, bytes):
+ return ByteSequence(self.value + b)
+ elif isinstance( b, str ):
+ return ByteSequence( self.value + b.encode("utf-8") )
elif isinstance( b, ByteSequence ):
return ByteSequence( self.value + b.value )
raise TypeError( "expected string or ByteSequence as operand" )