uno.py (162b3dbe) | uno.py (77dc4149) |
---|---|
1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance --- 7 unchanged lines hidden (view full) --- 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. 19# 20#************************************************************** 21import sys 22 23import pyuno | 1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance --- 7 unchanged lines hidden (view full) --- 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. 19# 20#************************************************************** 21import sys 22 23import pyuno |
24import __builtin__ | 24try: 25 import __builtin__ as builtins 26except: 27 import builtins |
25 26try: 27 unicode | 28 29try: 30 unicode |
31 bytes = str 32 bytearray = str |
|
28except NameError: 29 unicode = str 30 31import socket # since on Windows sal3.dll no longer calls WSAStartup 32 33# all functions and variables starting with a underscore (_) must be considered private 34# and can be changed at any time. Don't use them 35_g_ctx = pyuno.getComponentContext( ) | 33except NameError: 34 unicode = str 35 36import socket # since on Windows sal3.dll no longer calls WSAStartup 37 38# all functions and variables starting with a underscore (_) must be considered private 39# and can be changed at any time. Don't use them 40_g_ctx = pyuno.getComponentContext( ) |
36_g_delegatee = __builtin__.__dict__["__import__"] | 41_g_delegatee = builtins.__dict__["__import__"] |
37 38def getComponentContext(): 39 """ returns the UNO component context, that was used to initialize the python runtime. 40 """ 41 return _g_ctx 42 43def getConstantByName( constant ): 44 "Looks up the value of a idl constant by giving its explicit name" --- 129 unchanged lines hidden (view full) --- 174 return False 175 return self.value == that[0] 176 if isinstance(that, Char): 177 return self.value == that.value 178 return False 179 180class ByteSequence: 181 def __init__(self, value): | 42 43def getComponentContext(): 44 """ returns the UNO component context, that was used to initialize the python runtime. 45 """ 46 return _g_ctx 47 48def getConstantByName( constant ): 49 "Looks up the value of a idl constant by giving its explicit name" --- 129 unchanged lines hidden (view full) --- 179 return False 180 return self.value == that[0] 181 if isinstance(that, Char): 182 return self.value == that.value 183 return False 184 185class ByteSequence: 186 def __init__(self, value): |
182 if isinstance(value, str): | 187 if isinstance(value, (bytes, bytearray)): |
183 self.value = value 184 elif isinstance(value, ByteSequence): 185 self.value = value.value 186 else: 187 raise TypeError("expected string or bytesequence") 188 189 def __repr__(self): 190 return "<ByteSequence instance '%s'>" % (self.value, ) 191 192 def __eq__(self, that): 193 if isinstance( that, ByteSequence): 194 return self.value == that.value | 188 self.value = value 189 elif isinstance(value, ByteSequence): 190 self.value = value.value 191 else: 192 raise TypeError("expected string or bytesequence") 193 194 def __repr__(self): 195 return "<ByteSequence instance '%s'>" % (self.value, ) 196 197 def __eq__(self, that): 198 if isinstance( that, ByteSequence): 199 return self.value == that.value |
195 if isinstance(that, str): | 200 elif isinstance(that, (bytes, bytearray)): |
196 return self.value == that 197 return False 198 199 def __len__(self): 200 return len(self.value) 201 202 def __getitem__(self, index): 203 return self.value[index] 204 205 def __iter__( self ): 206 return self.value.__iter__() 207 208 def __add__( self , b ): | 201 return self.value == that 202 return False 203 204 def __len__(self): 205 return len(self.value) 206 207 def __getitem__(self, index): 208 return self.value[index] 209 210 def __iter__( self ): 211 return self.value.__iter__() 212 213 def __add__( self , b ): |
209 if isinstance( b, str ): | 214 if isinstance( b, (bytes, bytearray) ): |
210 return ByteSequence( self.value + b ) 211 elif isinstance( b, ByteSequence ): 212 return ByteSequence( self.value + b.value ) 213 raise TypeError( "expected string or ByteSequence as operand" ) 214 215 def __hash__( self ): 216 return self.value.hash() 217 --- 28 unchanged lines hidden (view full) --- 246 mod = None 247 d = sys.modules 248 for x in modnames: 249 if x in d: 250 mod = d[x] 251 else: 252 mod = pyuno.__class__(x) # How to create a module ?? 253 d = mod.__dict__ | 215 return ByteSequence( self.value + b ) 216 elif isinstance( b, ByteSequence ): 217 return ByteSequence( self.value + b.value ) 218 raise TypeError( "expected string or ByteSequence as operand" ) 219 220 def __hash__( self ): 221 return self.value.hash() 222 --- 28 unchanged lines hidden (view full) --- 251 mod = None 252 d = sys.modules 253 for x in modnames: 254 if x in d: 255 mod = d[x] 256 else: 257 mod = pyuno.__class__(x) # How to create a module ?? 258 d = mod.__dict__ |
254 | 259 |
255 RuntimeException = pyuno.getClass( "com.sun.star.uno.RuntimeException" ) 256 for x in fromlist: 257 if x not in d: 258 if x.startswith( "typeOf" ): 259 try: 260 d[x] = pyuno.getTypeByName( name + "." + x[6:len(x)] ) 261 except RuntimeException as e: 262 raise ImportError( "type " + name + "." + x[6:len(x)] +" is unknown" ) --- 10 unchanged lines hidden (view full) --- 273 try: 274 d[x] = getConstantByName( name + "." + x ) 275 except RuntimeException as e3: 276 # no known uno type ! 277 raise ImportError( "type "+ name + "." +x + " is unknown" ) 278 return mod 279 280# hook into the __import__ chain | 260 RuntimeException = pyuno.getClass( "com.sun.star.uno.RuntimeException" ) 261 for x in fromlist: 262 if x not in d: 263 if x.startswith( "typeOf" ): 264 try: 265 d[x] = pyuno.getTypeByName( name + "." + x[6:len(x)] ) 266 except RuntimeException as e: 267 raise ImportError( "type " + name + "." + x[6:len(x)] +" is unknown" ) --- 10 unchanged lines hidden (view full) --- 278 try: 279 d[x] = getConstantByName( name + "." + x ) 280 except RuntimeException as e3: 281 # no known uno type ! 282 raise ImportError( "type "+ name + "." +x + " is unknown" ) 283 return mod 284 285# hook into the __import__ chain |
281__builtin__.__dict__["__import__"] = _uno_import | 286builtins.__dict__["__import__"] = _uno_import |
282 283# private, referenced from the pyuno shared library 284def _uno_struct__init__(self,*args): 285 if len(args) == 1 and hasattr(args[0], "__class__") and args[0].__class__ == self.__class__ : 286 self.__dict__["value"] = args[0] 287 else: 288 self.__dict__["value"] = pyuno._createUnoStructHelper(self.__class__.__pyunostruct__,args) 289 290# private, referenced from the pyuno shared library 291def _uno_struct__getattr__(self,name): | 287 288# private, referenced from the pyuno shared library 289def _uno_struct__init__(self,*args): 290 if len(args) == 1 and hasattr(args[0], "__class__") and args[0].__class__ == self.__class__ : 291 self.__dict__["value"] = args[0] 292 else: 293 self.__dict__["value"] = pyuno._createUnoStructHelper(self.__class__.__pyunostruct__,args) 294 295# private, referenced from the pyuno shared library 296def _uno_struct__getattr__(self,name): |
292 return __builtin__.getattr(self.__dict__["value"],name) | 297 return getattr(self.__dict__["value"],name) |
293 294# private, referenced from the pyuno shared library 295def _uno_struct__setattr__(self,name,value): | 298 299# private, referenced from the pyuno shared library 300def _uno_struct__setattr__(self,name,value): |
296 return __builtin__.setattr(self.__dict__["value"],name,value) | 301 return setattr(self.__dict__["value"],name,value) |
297 298# private, referenced from the pyuno shared library 299def _uno_struct__repr__(self): 300 return repr(self.__dict__["value"]) 301 302def _uno_struct__str__(self): 303 return str(self.__dict__["value"]) 304 305# private, referenced from the pyuno shared library 306def _uno_struct__eq__(self,cmp): 307 if hasattr(cmp,"value"): 308 return self.__dict__["value"] == cmp.__dict__["value"] 309 return False 310 | 302 303# private, referenced from the pyuno shared library 304def _uno_struct__repr__(self): 305 return repr(self.__dict__["value"]) 306 307def _uno_struct__str__(self): 308 return str(self.__dict__["value"]) 309 310# private, referenced from the pyuno shared library 311def _uno_struct__eq__(self,cmp): 312 if hasattr(cmp,"value"): 313 return self.__dict__["value"] == cmp.__dict__["value"] 314 return False 315 |
316def _uno_struct__dir__(self): 317 return dir(self.__dict__["value"]) + list(self.__dict__.keys()) + \ 318 list(self.__class__.__dict__.keys()) 319 |
|
311# referenced from pyuno shared lib and pythonscript.py 312def _uno_extract_printable_stacktrace( trace ): 313 mod = None 314 try: 315 mod = __import__("traceback") 316 except ImportError as e: 317 pass 318 ret = "" 319 if mod: 320 lst = mod.extract_tb( trace ) 321 max = len(lst) 322 for j in range(max): 323 i = lst[max-j-1] 324 ret = ret + " " + str(i[0]) + ":" + \ 325 str(i[1]) + " in function " + \ 326 str(i[2]) + "() [" + str(i[3]) + "]\n" 327 else: 328 ret = "Couldn't import traceback module" 329 return ret | 320# referenced from pyuno shared lib and pythonscript.py 321def _uno_extract_printable_stacktrace( trace ): 322 mod = None 323 try: 324 mod = __import__("traceback") 325 except ImportError as e: 326 pass 327 ret = "" 328 if mod: 329 lst = mod.extract_tb( trace ) 330 max = len(lst) 331 for j in range(max): 332 i = lst[max-j-1] 333 ret = ret + " " + str(i[0]) + ":" + \ 334 str(i[1]) + " in function " + \ 335 str(i[2]) + "() [" + str(i[3]) + "]\n" 336 else: 337 ret = "Couldn't import traceback module" 338 return ret |