From 4634cbc237239da771e0f6a81f78171ecec726ba Mon Sep 17 00:00:00 2001 From: David Bolen Date: Wed, 7 Mar 2012 11:07:42 +0100 Subject: fdo#46859: adapt string type checks to work with both Python 2 and 3 (regression from a09ce46818fd4d5e08b3af9a478501cd8ef5b4fe) --- pyuno/source/module/uno.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'pyuno') diff --git a/pyuno/source/module/uno.py b/pyuno/source/module/uno.py index f93ac5e13fcc..e82d2fee0cb4 100644 --- a/pyuno/source/module/uno.py +++ b/pyuno/source/module/uno.py @@ -35,6 +35,12 @@ try: except ImportError: import builtins as __builtin__ +try: + unicode +except NameError: + # Python 3 compatibility + unicode = str + import socket # since on Windows sal3.dll no longer calls WSAStartup # all functions and variables starting with a underscore (_) must be considered private @@ -159,9 +165,9 @@ class Bool(object): Note: This class is deprecated. Use python's True and False directly instead """ def __new__(cls, value): - if isinstance(value, str) and value == "true": + if isinstance(value, (str, unicode)) and value == "true": return True - if isinstance(value, str) and value == "false": + if isinstance(value, (str, unicode)) and value == "false": return False if value: return True @@ -171,7 +177,7 @@ class Char: "Represents a UNO char, use an instance of this class to explicitly pass a char to UNO" # @param value pass a Unicode string with length 1 def __init__(self,value): - assert isinstance(value, str) + assert isinstance(value, unicode) assert len(value) == 1 self.value=value @@ -179,7 +185,7 @@ class Char: return "" % (self.value, ) def __eq__(self, that): - if isinstance(that, str): + if isinstance(that, (str, unicode)): if len(that) > 1: return False return self.value == that[0] -- cgit