diff options
author | Michael Stahl <mstahl@redhat.com> | 2012-11-25 15:57:38 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-11-25 16:06:40 +0100 |
commit | a38b59265c08276fce6d73ce541cadb41aa6d347 (patch) | |
tree | afd49db7620084f2381b71a97dcacec01180a47c /pyuno | |
parent | 87c923be603d0b3706c481281549a79c8b8bcd41 (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')
-rw-r--r-- | pyuno/source/loader/pythonloader.py | 2 | ||||
-rw-r--r-- | pyuno/source/module/uno.py | 14 |
2 files changed, 11 insertions, 5 deletions
diff --git a/pyuno/source/loader/pythonloader.py b/pyuno/source/loader/pythonloader.py index a6f1cd543a62..03bf7d21b24f 100644 --- a/pyuno/source/loader/pythonloader.py +++ b/pyuno/source/loader/pythonloader.py @@ -90,7 +90,7 @@ class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ): # read the file filename = unohelper.fileUrlToSystemPath( url ) - fileHandle = file( filename ) + fileHandle = open( filename ) src = fileHandle.read().replace("\r","") if not src.endswith( "\n" ): src = src + "\n" 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" ) |