vbox的更動 59798 路徑 trunk/src/libs
- 時間撮記:
- 2016-2-24 下午02:35:47 (9 年 以前)
- 位置:
- trunk/src/libs/xpcom18a4/python
- 檔案:
-
- 修改 15 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/libs/xpcom18a4/python/Makefile.kmk
r59795 r59798 5 5 6 6 # 7 # Copyright (C) 2009-201 5Oracle Corporation7 # Copyright (C) 2009-2016 Oracle Corporation 8 8 # 9 9 # This file is part of VirtualBox Open Source Edition (OSE), as … … 27 27 # 28 28 # List of supported Python versions, defining a number of 29 # VBOX_PYTHON[25|26|27|DEF]_[INC|LIB] variables which get picked up below. 29 # VBOX_PYTHON[26|27|31|32|33|34|35|DEF]_[INC|LIB] variables 30 # which get picked up below. 30 31 # 31 32 ifeq ($(KBUILD_TARGET),darwin) # Relatively predictable, don't script. 32 ifeq ($(KBUILD_TARGET_ARCH),x86)33 VBOX_PYTHON25_INC = $(VBOX_PATH_MACOSX_SDK)/usr/include/python2.534 VBOX_PYTHON25_LIB = $(VBOX_PATH_MACOSX_SDK)/usr/lib/libpython2.5.dylib35 VBOX_PYTHON25_LIB_X86 = $(VBOX_PYTHON25_LIB)36 endif37 33 if !defined(VBOX_WITHOUT_VBOXPYTHON_FOR_OSX_10_6) \ 38 34 && ( !defined(VBOX_OSE) \ … … 49 45 VBOX_PYTHON27_LIB_X86 = $(VBOX_PYTHON27_LIB) 50 46 endif 47 # No Python 3.x yet as part of OSX versions including El Capitan, 10.11. 51 48 52 49 else … … 115 112 116 113 117 ifdef VBOX_PYTHON23_INC118 #119 # Python 2.3 version120 #121 DLLS += VBoxPython2_3122 VBoxPython2_3_EXTENDS = VBoxPythonBase123 VBoxPython2_3_EXTENDS_BY = appending124 VBoxPython2_3_TEMPLATE = XPCOM$(if-expr "$(KBUILD_TARGET)" == "darwin",OSX104,)125 VBoxPython2_3_INCS = $(VBOX_PYTHON23_INC)126 VBoxPython2_3_LIBS = $(VBOX_PYTHON23_LIB)127 128 ifdef VBOX_WITH_32_ON_64_MAIN_API129 DLLS += VBoxPython2_3_x86130 VBoxPython2_3_x86_EXTENDS = VBoxPythonBase_x86131 VBoxPython2_3_x86_EXTENDS_BY = appending132 VBoxPython2_3_x86_TEMPLATE = XPCOM$(if-expr "$(KBUILD_TARGET)" == "darwin",OSX104,-x86)133 VBoxPython2_3_x86_INCS = $(VBOX_PYTHON23_INC)134 VBoxPython2_3_x86_LIBS = $(VBOX_PYTHON23_LIB_X86)135 endif136 endif137 138 ifdef VBOX_PYTHON24_INC139 #140 # Python 2.4 version141 #142 DLLS += VBoxPython2_4143 VBoxPython2_4_EXTENDS = VBoxPythonBase144 VBoxPython2_4_EXTENDS_BY = appending145 VBoxPython2_4_INCS = $(VBOX_PYTHON24_INC)146 VBoxPython2_4_LIBS = $(VBOX_PYTHON24_LIB)147 148 ifdef VBOX_WITH_32_ON_64_MAIN_API149 DLLS += VBoxPython2_4_x86150 VBoxPython2_4_x86_EXTENDS = VBoxPythonBase_x86151 VBoxPython2_4_x86_EXTENDS_BY = appending152 VBoxPython2_4_x86_INCS = $(VBOX_PYTHON24_INC)153 VBoxPython2_4_x86_LIBS = $(VBOX_PYTHON24_LIB_X86)154 endif155 endif156 157 ifdef VBOX_PYTHON25_INC158 #159 # Python 2.5 version160 #161 DLLS += VBoxPython2_5162 VBoxPython2_5_EXTENDS = VBoxPythonBase163 VBoxPython2_5_EXTENDS_BY = appending164 VBoxPython2_5_INCS = $(VBOX_PYTHON25_INC)165 VBoxPython2_5_LIBS = $(VBOX_PYTHON25_LIB)166 167 ifdef VBOX_WITH_32_ON_64_MAIN_API168 DLLS += VBoxPython2_5_x86169 VBoxPython2_5_x86_EXTENDS = VBoxPythonBase_x86170 VBoxPython2_5_x86_EXTENDS_BY = appending171 VBoxPython2_5_x86_INCS = $(VBOX_PYTHON25_INC)172 VBoxPython2_5_x86_LIBS = $(VBOX_PYTHON25_LIB_X86)173 endif174 endif175 176 114 ifdef VBOX_PYTHON26_INC 177 115 # … … 213 151 VBoxPython2_7_x86_INCS = $(VBOX_PYTHON27_INC) 214 152 VBoxPython2_7_x86_LIBS = $(VBOX_PYTHON27_LIB_X86) 153 endif 154 endif 155 156 ifdef VBOX_PYTHON31_INC 157 # 158 # Python 3.1 version 159 # 160 DLLS += VBoxPython3_1 161 VBoxPython3_1_EXTENDS = VBoxPythonBase 162 VBoxPython3_1_EXTENDS_BY = appending 163 VBoxPython3_1_TEMPLATE = XPCOM 164 VBoxPython3_1_INCS = $(VBOX_PYTHON31_INC) 165 VBoxPython3_1_LIBS = $(VBOX_PYTHON31_LIB) 166 167 ifdef VBOX_WITH_32_ON_64_MAIN_API 168 DLLS += VBoxPython3_1_x86 169 VBoxPython3_1_x86_EXTENDS = VBoxPythonBase_x86 170 VBoxPython3_1_x86_EXTENDS_BY = appending 171 VBoxPython3_1_x86_TEMPLATE = XPCOM 172 VBoxPython3_1_x86_INCS = $(VBOX_PYTHON31_INC) 173 VBoxPython3_1_x86_LIBS = $(VBOX_PYTHON31_LIB_X86) 174 endif 175 endif 176 177 ifdef VBOX_PYTHON32_INC 178 # 179 # Python 3.2 version 180 # 181 DLLS += VBoxPython3_2 182 VBoxPython3_2_EXTENDS = VBoxPythonBase 183 VBoxPython3_2_EXTENDS_BY = appending 184 VBoxPython3_2_TEMPLATE = XPCOM 185 VBoxPython3_2_INCS = $(VBOX_PYTHON32_INC) 186 VBoxPython3_2_LIBS = $(VBOX_PYTHON32_LIB) 187 188 ifdef VBOX_WITH_32_ON_64_MAIN_API 189 DLLS += VBoxPython3_2_x86 190 VBoxPython3_2_x86_EXTENDS = VBoxPythonBase_x86 191 VBoxPython3_2_x86_EXTENDS_BY = appending 192 VBoxPython3_2_x86_TEMPLATE = XPCOM 193 VBoxPython3_2_x86_INCS = $(VBOX_PYTHON32_INC) 194 VBoxPython3_2_x86_LIBS = $(VBOX_PYTHON32_LIB_X86) 195 endif 196 endif 197 198 ifdef VBOX_PYTHON33_INC 199 # 200 # Python 3.3 version 201 # 202 DLLS += VBoxPython3_3 203 VBoxPython3_3_EXTENDS = VBoxPythonBase 204 VBoxPython3_3_EXTENDS_BY = appending 205 VBoxPython3_3_TEMPLATE = XPCOM 206 VBoxPython3_3_INCS = $(VBOX_PYTHON33_INC) 207 VBoxPython3_3_LIBS = $(VBOX_PYTHON33_LIB) 208 209 ifdef VBOX_WITH_32_ON_64_MAIN_API 210 DLLS += VBoxPython3_3_x86 211 VBoxPython3_3_x86_EXTENDS = VBoxPythonBase_x86 212 VBoxPython3_3_x86_EXTENDS_BY = appending 213 VBoxPython3_3_x86_TEMPLATE = XPCOM 214 VBoxPython3_3_x86_INCS = $(VBOX_PYTHON33_INC) 215 VBoxPython3_3_x86_LIBS = $(VBOX_PYTHON33_LIB_X86) 216 endif 217 endif 218 219 ifdef VBOX_PYTHON34_INC 220 # 221 # Python 3.4 version 222 # 223 DLLS += VBoxPython3_4 224 VBoxPython3_4_EXTENDS = VBoxPythonBase 225 VBoxPython3_4_EXTENDS_BY = appending 226 VBoxPython3_4_TEMPLATE = XPCOM 227 VBoxPython3_4_INCS = $(VBOX_PYTHON34_INC) 228 VBoxPython3_4_LIBS = $(VBOX_PYTHON34_LIB) 229 230 ifdef VBOX_WITH_32_ON_64_MAIN_API 231 DLLS += VBoxPython3_4_x86 232 VBoxPython3_4_x86_EXTENDS = VBoxPythonBase_x86 233 VBoxPython3_4_x86_EXTENDS_BY = appending 234 VBoxPython3_4_x86_TEMPLATE = XPCOM 235 VBoxPython3_4_x86_INCS = $(VBOX_PYTHON34_INC) 236 VBoxPython3_4_x86_LIBS = $(VBOX_PYTHON34_LIB_X86) 237 endif 238 endif 239 240 ifdef VBOX_PYTHON35_INC 241 # 242 # Python 3.5 version 243 # 244 DLLS += VBoxPython3_5 245 VBoxPython3_5_EXTENDS = VBoxPythonBase 246 VBoxPython3_5_EXTENDS_BY = appending 247 VBoxPython3_5_TEMPLATE = XPCOM 248 VBoxPython3_5_INCS = $(VBOX_PYTHON35_INC) 249 VBoxPython3_5_LIBS = $(VBOX_PYTHON35_LIB) 250 251 ifdef VBOX_WITH_32_ON_64_MAIN_API 252 DLLS += VBoxPython3_5_x86 253 VBoxPython3_5_x86_EXTENDS = VBoxPythonBase_x86 254 VBoxPython3_5_x86_EXTENDS_BY = appending 255 VBoxPython3_5_x86_TEMPLATE = XPCOM 256 VBoxPython3_5_x86_INCS = $(VBOX_PYTHON35_INC) 257 VBoxPython3_5_x86_LIBS = $(VBOX_PYTHON35_LIB_X86) 215 258 endif 216 259 endif -
trunk/src/libs/xpcom18a4/python/__init__.py
r59795 r59798 38 38 39 39 # The XPCOM (Cross Platform COM) package. 40 import exceptions 40 from __future__ import print_function 41 import sys 42 if sys.version_info[0] <= 2: 43 import exceptions 44 XPCOMBaseException = exceptions.Exception 45 else: 46 XPCOMBaseException = Exception 41 47 42 48 # A global "verbose" flag - currently used by the … … 48 54 # The standard XPCOM exception object. 49 55 # Instances of this class are raised by the XPCOM extension module. 50 class Exception( exceptions.Exception):56 class Exception(XPCOMBaseException): 51 57 def __init__(self, errno, message = None): 52 58 assert int(errno) == errno, "The errno param must be an integer" 53 59 self.errno = errno 54 60 self.msg = message 55 exceptions.Exception.__init__(self, errno)61 XPCOMBaseException.__init__(self, errno) 56 62 def __str__(self): 57 63 if not hr_map: 58 import nsError59 for name, val in nsError.__dict__.items():64 from . import nsError 65 for name, val in list(nsError.__dict__.items()): 60 66 if type(val)==type(0): 61 67 hr_map[val] = name … … 80 86 def __init__(self, errno=None, *args, **kw): 81 87 if errno is None: 82 import nsError88 from . import nsError 83 89 errno = nsError.NS_ERROR_FAILURE 84 90 Exception.__init__(self, errno, *args, **kw) … … 98 104 pass 99 105 def write(self, msg): 100 import _xpcom106 import xpcom._xpcom as _xpcom 101 107 _xpcom.LogConsoleMessage(msg) 102 108 def close(self): … … 104 110 105 111 def setupLogging(): 106 import sys, os, threading, thread 112 import os 113 if sys.version_info[0] <= 2: 114 import threading, thread 107 115 hdlr = logging.StreamHandler(ConsoleServiceStream()) 108 116 fmt = logging.Formatter(logging.BASIC_FORMAT) … … 113 121 # Later versions of logging use an RLock, so we detect an "old" style 114 122 # handler and update its lock 115 if type(hdlr.lock) == thread.LockType: 116 hdlr.lock = threading.RLock() 123 if sys.version_info[0] <= 2: 124 if type(hdlr.lock) == thread.LockType: 125 hdlr.lock = threading.RLock() 117 126 118 127 logger.addHandler(hdlr) … … 126 135 # open without buffering so never pending output 127 136 stream = open(filename, "wU", 0) 128 except IOError, why: 129 print >> sys.stderr, "pyxpcom failed to open log file '%s': %s" \ 130 % (filename, why) 137 except IOError as why: 138 print("pyxpcom failed to open log file '%s': %s" % (filename, why), file=sys.stderr) 131 139 # stream remains default 132 140 133 141 hdlr = logging.StreamHandler(stream) 134 142 # see above - fix a deadlock problem on this handler too. 135 if type(hdlr.lock) == thread.LockType: 136 hdlr.lock = threading.RLock() 143 if sys.version_info[0] <= 2: 144 if type(hdlr.lock) == thread.LockType: 145 hdlr.lock = threading.RLock() 137 146 138 147 fmt = logging.Formatter(logging.BASIC_FORMAT) -
trunk/src/libs/xpcom18a4/python/client/__init__.py
r59795 r59798 37 37 38 38 import os 39 import new 39 from types import MethodType 40 40 import logging 41 41 from xpcom import xpt, COMException, nsError, logger … … 126 126 # Exec the code object 127 127 tempNameSpace = {} 128 exec codeObject in globals(), tempNameSpace128 exec(codeObject, globals(), tempNameSpace) 129 129 ret = tempNameSpace[name] 130 if not interface_method_cache.has_key(iid):130 if iid not in interface_method_cache: 131 131 interface_method_cache[iid] = {} 132 132 interface_method_cache[iid][name] = ret … … 153 153 if flags & FLAGS_TO_IGNORE == 0: 154 154 if flags & XPT_MD_SETTER: 155 param_flags = map(lambda x: (x.param_flags,) + xpt.MakeReprForInvoke(x), m.params)155 param_flags = list([(x.param_flags,) + xpt.MakeReprForInvoke(x) for x in m.params]) 156 156 setters[m.name] = m.method_index, param_flags 157 157 elif flags & XPT_MD_GETTER: 158 param_flags = map(lambda x: (x.param_flags,) + xpt.MakeReprForInvoke(x), m.params)158 param_flags = list([(x.param_flags,) + xpt.MakeReprForInvoke(x) for x in m.params]) 159 159 getters[m.name] = m.method_index, param_flags 160 160 else: … … 220 220 except COMException: 221 221 pass 222 raise ValueError , "This object does not support automatic numeric conversion to this type"222 raise ValueError("This object does not support automatic numeric conversion to this type") 223 223 224 224 def __int__(self): … … 281 281 for nominated_iid in interface_infos: 282 282 # Interface may appear twice in the class info list, so check this here. 283 if no t self.__dict__['_interface_infos_'].has_key(nominated_iid):283 if nominated_iid not in self.__dict__['_interface_infos_']: 284 284 # Just invoke our QI on the object 285 285 self.queryInterface(nominated_iid) … … 290 290 contractid_info_cache[real_cid] = contractid_info 291 291 else: 292 for key, val in contractid_info.items():292 for key, val in list(contractid_info.items()): 293 293 self.__dict__[key].update(val) 294 294 … … 300 300 # rebuild the world for each new object. 301 301 iis = self.__dict__['_interface_infos_'] 302 assert not iis.has_key(iid), "Already remembered this interface!"302 assert iid not in iis, "Already remembered this interface!" 303 303 try: 304 304 method_infos, getters, setters, constants = BuildInterfaceInfo(iid) 305 except COMException ,why:305 except COMException as why: 306 306 # Failing to build an interface info generally isn't a real 307 307 # problem - its probably just that the interface is non-scriptable. … … 314 314 iis[iid] = method_infos, getters, setters, constants 315 315 names = self.__dict__['_name_to_interface_iid_'] 316 for name in method_infos.keys(): names[name] = iid317 for name in getters.keys(): names[name] = iid318 for name in setters.keys(): names[name] = iid319 for name in constants.keys(): names[name] = iid316 for name in list(method_infos.keys()): names[name] = iid 317 for name in list(getters.keys()): names[name] = iid 318 for name in list(setters.keys()): names[name] = iid 319 for name in list(constants.keys()): names[name] = iid 320 320 321 321 def QueryInterface(self, iid): 322 if self._interfaces_.has_key(iid):323 assert self._interface_names_.has_key(iid.name), "_interfaces_ has the key, but _interface_names_ does not!"322 if iid in self._interfaces_: 323 assert iid_name in self._interface_names_, "_interfaces_ has the key, but _interface_names_ does not!" 324 324 return self 325 325 # Haven't seen this before - do a real QI. 326 if not self._interface_infos_.has_key(iid):326 if iid not in self._interface_infos_: 327 327 self._remember_interface_info(iid) 328 328 iface_info = self._interface_infos_[iid] … … 350 350 def __getattr__(self, attr): 351 351 if attr in _special_getattr_names: 352 raise AttributeError , attr352 raise AttributeError(attr) 353 353 # First allow the interface name to return the "raw" interface 354 354 interface = self.__dict__['_interface_names_'].get(attr, None) … … 375 375 # Some interfaces may provide this name via "native" support. 376 376 # Loop over all interfaces, and if found, cache it for next time. 377 for interface in self.__dict__['_interfaces_'].values():377 for interface in list(self.__dict__['_interfaces_'].values()): 378 378 try: 379 379 ret = getattr(interface, attr) … … 382 382 except AttributeError: 383 383 pass 384 raise AttributeError , "XPCOM component '%s' has no attribute '%s'" % (self._object_name_, attr)384 raise AttributeError("XPCOM component '%s' has no attribute '%s'" % (self._object_name_, attr)) 385 385 386 386 def __setattr__(self, attr, val): … … 397 397 setattr(interface, attr, val) 398 398 return 399 raise AttributeError , "XPCOM component '%s' has no attribute '%s'" % (self._object_name_, attr)399 raise AttributeError("XPCOM component '%s' has no attribute '%s'" % (self._object_name_, attr)) 400 400 401 401 def _get_classinfo_repr_(self): … … 410 410 self.__dict__['_tried_classinfo_'] = 0 411 411 412 iface_names = self.__dict__['_interface_names_'].keys()412 iface_names = list(self.__dict__['_interface_names_'].keys()) 413 413 try: 414 414 iface_names.remove("nsISupports") … … 436 436 self.__dict__.update(constants) 437 437 # We remember the constant names to prevent the user trying to assign to them! 438 self.__dict__['_constant_names_'] = constants.keys()438 self.__dict__['_constant_names_'] = list(constants.keys()) 439 439 440 440 def __getattr__(self, attr): 441 441 # Allow the underlying interface to provide a better implementation if desired. 442 442 if attr in _special_getattr_names: 443 raise AttributeError , attr443 raise AttributeError(attr) 444 444 445 445 ret = getattr(self.__dict__['_comobj_'], attr, None) … … 449 449 unbound_method = self.__dict__['_methods_'].get(attr, None) 450 450 if unbound_method is not None: 451 return new.instancemethod(unbound_method, self, self.__class__)451 return MethodType(unbound_method, self) 452 452 453 453 getters = self.__dict__['_property_getters_'] … … 456 456 method_index, param_infos = info 457 457 if len(param_infos)!=1: # Only expecting a retval 458 raise RuntimeError , "Can't get properties with this many args!"458 raise RuntimeError("Can't get properties with this many args!") 459 459 args = ( param_infos, () ) 460 460 return XPTC_InvokeByIndex(self._comobj_, method_index, args) … … 467 467 # Cache it locally 468 468 self.__dict__['_methods_'][attr] = unbound_method 469 return new.instancemethod(unbound_method, self, self.__class__)470 471 raise AttributeError , "XPCOM component '%s' has no attribute '%s'" % (self._object_name_, attr)469 return MethodType(unbound_method, self) 470 471 raise AttributeError("XPCOM component '%s' has no attribute '%s'" % (self._object_name_, attr)) 472 472 473 473 def __setattr__(self, attr, val): 474 474 # If we already have a __dict__ item of that name, and its not one of 475 475 # our constants, we just directly set it, and leave. 476 if self.__dict__.has_key(attr)and attr not in self.__dict__['_constant_names_']:476 if attr in self.__dict__ and attr not in self.__dict__['_constant_names_']: 477 477 self.__dict__[attr] = val 478 478 return … … 481 481 info = setters.get(attr) 482 482 if info is None: 483 raise AttributeError , "XPCOM component '%s' can not set attribute '%s'" % (self._object_name_, attr)483 raise AttributeError("XPCOM component '%s' can not set attribute '%s'" % (self._object_name_, attr)) 484 484 method_index, param_infos = info 485 485 if len(param_infos)!=1: # Only expecting a single input val 486 raise RuntimeError , "Can't set properties with this many args!"486 raise RuntimeError("Can't set properties with this many args!") 487 487 real_param_infos = ( param_infos, (val,) ) 488 488 return XPTC_InvokeByIndex(self._comobj_, method_index, real_param_infos) … … 527 527 try: 528 528 return Component(self._comobj_.QueryReferent(iid)._comobj_, iid) 529 except COMException ,details:529 except COMException as details: 530 530 if details.errno != nsError.NS_ERROR_NULL_POINTER: 531 531 raise -
trunk/src/libs/xpcom18a4/python/components.py
r59795 r59798 37 37 38 38 # This module provides the JavaScript "components" interface 39 import xpt 40 import xpcom, _xpcom 39 from . import xpt 40 import xpcom 41 import xpcom._xpcom as _xpcom 41 42 import xpcom.client 42 43 import xpcom.server 43 import types 44 45 StringTypes = [types.StringType, types.UnicodeType] 44 45 StringTypes = [bytes, str] 46 46 47 47 def _get_good_iid(iid): … … 79 79 if self._dict_data is None: 80 80 self._dict_data = self._build_dict() 81 return self._dict_data.keys()81 return list(self._dict_data.keys()) 82 82 def items(self): 83 83 if self._dict_data is None: 84 84 self._dict_data = self._build_dict() 85 return self._dict_data.items()85 return list(self._dict_data.items()) 86 86 def values(self): 87 87 if self._dict_data is None: 88 88 self._dict_data = self._build_dict() 89 return self._dict_data.values()90 def has_key(self, key):91 if self._dict_data is None:92 self._dict_data = self._build_dict()93 return self._dict_data.has_key(key)89 return list(self._dict_data.values()) 90 # def has_key(self, key): 91 # if self._dict_data is None: 92 # self._dict_data = self._build_dict() 93 # return self._dict_data.has_key(key) 94 94 95 95 def __len__(self): … … 99 99 100 100 def __getattr__(self, attr): 101 if self._dict_data is not None and self._dict_data.has_key(attr):101 if self._dict_data is not None and attr in self._dict_data: 102 102 return self._dict_data[attr] 103 103 return self._get_one(attr) 104 104 def __getitem__(self, item): 105 if self._dict_data is not None and self._dict_data.has_key(item):105 if self._dict_data is not None and item in self._dict_data: 106 106 return self._dict_data[item] 107 107 return self._get_one(item) … … 120 120 other_iid = getattr(other, "_iidobj_", other) 121 121 return cmp(this_iid, other_iid) 122 def __eq__(self, other): 123 this_iid = self._iidobj_ 124 other_iid = getattr(other, "_iidobj_", other) 125 return this_iid == other_iid 122 126 def __hash__(self): 123 127 return hash(self._iidobj_) … … 125 129 return str(self._iidobj_) 126 130 def __getitem__(self, item): 127 raise TypeError , "components.interface objects are not subscriptable"131 raise TypeError("components.interface objects are not subscriptable") 128 132 def __setitem__(self, item, value): 129 raise TypeError , "components.interface objects are not subscriptable"133 raise TypeError("components.interface objects are not subscriptable") 130 134 def __setattr__(self, attr, value): 131 raise AttributeError , "Can not set attributes on components.Interface objects"135 raise AttributeError("Can not set attributes on components.Interface objects") 132 136 def __getattr__(self, attr): 133 137 # Support constants as attributes. … … 139 143 c[c_ob.name] = c_ob.value 140 144 _constants_by_iid_map[self._iidobj_] = c 141 if c.has_key(attr):145 if attr in c: 142 146 return c[attr] 143 raise AttributeError , "'%s' interfaces do not define a constant '%s'" % (self.name, attr)147 raise AttributeError("'%s' interfaces do not define a constant '%s'" % (self.name, attr)) 144 148 145 149 … … 148 152 try: 149 153 item = interfaceInfoManager.GetInfoForName(name) 150 except xpcom.COMException ,why:154 except xpcom.COMException as why: 151 155 # Present a better exception message, and give a more useful error code. 152 import nsError156 from . import nsError 153 157 raise xpcom.COMException(nsError.NS_ERROR_NO_INTERFACE, "The interface '%s' does not exist" % (name,)) 154 158 return _Interface(item.GetName(), item.GetIID()) … … 180 184 self.clsid = rc 181 185 return rc 182 raise AttributeError , "%s class has no attribute '%s'" % (self.contractid, attr)186 raise AttributeError("%s class has no attribute '%s'" % (self.contractid, attr)) 183 187 def createInstance(self, iid = None): 184 188 import xpcom.client 185 189 try: 186 190 return xpcom.client.Component(self.contractid, _get_good_iid(iid)) 187 except xpcom.COMException ,details:188 import nsError191 except xpcom.COMException as details: 192 from . import nsError 189 193 # Handle "no such component" in a cleaner way for the user. 190 194 if details.errno == nsError.NS_ERROR_FACTORY_NOT_REGISTERED: … … 219 223 220 224 # The ID function 221 ID = _xpcom.I ID225 ID = _xpcom.ID 222 226 223 227 # A helper to cleanup our namespace as xpcom shuts down. -
trunk/src/libs/xpcom18a4/python/file.py
r59795 r59798 156 156 self.close() 157 157 if mode != "r": 158 raise ValueError , "only 'r' mode supported'"158 raise ValueError("only 'r' mode supported") 159 159 io_service = components.classes["@mozilla.org/network/io-service;1"] \ 160 160 .getService(components.interfaces.nsIIOService) … … 165 165 # Mozilla asserts and starts saying "NULL POINTER" if this is wrong! 166 166 if not url_ob.scheme: 167 raise ValueError ,("The URI '%s' is invalid (no scheme)"167 raise ValueError("The URI '%s' is invalid (no scheme)" 168 168 % (url_ob.spec,)) 169 169 self.channel = io_service.newChannelFromURI(url_ob) … … 202 202 self.inputStream.init(self.fileIO) 203 203 else: 204 raise ValueError , "Unknown mode"204 raise ValueError("Unknown mode") 205 205 206 206 def close(self): … … 226 226 got = got + file.read() 227 227 if got != expected: 228 raise RuntimeError , "Reading '%s' failed - got %d bytes, but expected %d bytes" % (file, len(got), len(expected))228 raise RuntimeError("Reading '%s' failed - got %d bytes, but expected %d bytes" % (file, len(got), len(expected))) 229 229 230 230 def _DoTestBufferRead(file, expected): … … 240 240 got = got + str(buffer[:num]) 241 241 if got != expected: 242 raise RuntimeError , "Reading '%s' failed - got %d bytes, but expected %d bytes" % (file, len(got), len(expected))242 raise RuntimeError("Reading '%s' failed - got %d bytes, but expected %d bytes" % (file, len(got), len(expected))) 243 243 244 244 def _TestLocalFile(): … … 266 266 # Open the same file again for writing - this should delete the old one. 267 267 if not os.path.isfile(fname): 268 raise RuntimeError , "The file '%s' does not exist, but we are explicitly testing create semantics when it does" % (fname,)268 raise RuntimeError("The file '%s' does not exist, but we are explicitly testing create semantics when it does" % (fname,)) 269 269 test_file = LocalFile(fname, "w") 270 270 test_file.write(data) … … 305 305 def _TestURI(url): 306 306 test_file = URIFile(url) 307 print "Opened file is", test_file307 print("Opened file is", test_file) 308 308 got = test_file.read() 309 print "Read %d bytes of data from %r" % (len(got), url)309 print("Read %d bytes of data from %r" % (len(got), url)) 310 310 test_file.close() 311 311 … … 313 313 import sys 314 314 if len(sys.argv) < 2: 315 print "No URL specified on command line - performing self-test"315 print("No URL specified on command line - performing self-test") 316 316 _TestAll() 317 317 else: -
trunk/src/libs/xpcom18a4/python/gen_python_deps.py
r59795 r59798 2 2 3 3 """ 4 Copyright (C) 2009-201 3Oracle Corporation4 Copyright (C) 2009-2016 Oracle Corporation 5 5 6 6 This file is part of VirtualBox Open Source Edition (OSE), as … … 14 14 15 15 import os,sys 16 from distutils.version import StrictVersion 16 17 17 versions = ["2. 3", "2.4", "2.5", "2.6", "2.7",]18 versions = ["2.6", "2.7", "3.1", "3.2", "3.3", "3.4", "3.5"] 18 19 prefixes = ["/usr", "/usr/local", "/opt", "/opt/local"] 19 20 known = {} … … 41 42 42 43 def print_vars(vers, known, sep, bitness_magic): 43 print "VBOX_PYTHON%s_INC=%s%s" %(vers, known[0], sep)44 print("VBOX_PYTHON%s_INC=%s%s" %(vers, known[0], sep)) 44 45 if bitness_magic > 0: 45 print "VBOX_PYTHON%s_LIB=%s%s" %(vers, known[2], sep)46 print "VBOX_PYTHON%s_LIB_X86=%s%s" %(vers, known[1], sep)46 print("VBOX_PYTHON%s_LIB=%s%s" %(vers, known[2], sep)) 47 print("VBOX_PYTHON%s_LIB_X86=%s%s" %(vers, known[1], sep)) 47 48 else: 48 print "VBOX_PYTHON%s_LIB=%s%s" %(vers, known[1], sep)49 print("VBOX_PYTHON%s_LIB=%s%s" %(vers, known[1], sep)) 49 50 50 51 … … 91 92 92 93 for v in versions: 94 if StrictVersion(v) < StrictVersion('2.6'): 95 continue 93 96 for p in prefixes: 94 97 c = checkPair(p, v, dllpre, dllsuff, bitness_magic) … … 96 99 known[v] = c 97 100 break 98 keys = known.keys()101 keys = list(known.keys()) 99 102 # we want default to be the lowest versioned Python 100 103 keys.sort() -
trunk/src/libs/xpcom18a4/python/primitives.py
r59795 r59798 35 35 better = _primitives_map[prin.type] 36 36 except KeyError: 37 raise ValueError , "This primitive type (%d) is not supported" % (prin.type,)37 raise ValueError("This primitive type (%d) is not supported" % (prin.type,)) 38 38 prin = prin.QueryInterface(better) 39 39 return prin.data -
trunk/src/libs/xpcom18a4/python/server/__init__.py
r59795 r59798 38 38 # The xpcom.server package. 39 39 40 from policy import DefaultPolicy40 from xpcom.server.policy import DefaultPolicy 41 41 from xpcom import _xpcom 42 42 … … 80 80 # Python! 81 81 def NS_GetModule( serviceManager, nsIFile ): 82 import loader82 from . import loader 83 83 iid = _xpcom.IID_nsIModule 84 84 return WrapObject(loader.MakePythonComponentLoaderModule(serviceManager, nsIFile), iid, bWrapClient = 0) 85 85 86 86 def _shutdown(): 87 from policy import _shutdown87 from server.policy import _shutdown 88 88 _shutdown() -
trunk/src/libs/xpcom18a4/python/server/loader.py
r59795 r59798 38 38 import xpcom 39 39 from xpcom import components, logger 40 41 import module 42 43 import glob, os, types 44 40 from . import module 41 import glob 42 import os 45 43 from xpcom.client import Component 46 44 … … 57 55 # For now, just run over all classes looking for likely candidates. 58 56 comps = [] 59 for name, object in py_module.__dict__.items():57 for name, object in list(py_module.__dict__.items()): 60 58 try: 61 if (type(object) == type s.ClassTypeor issubclass(object, object)) and \59 if (type(object) == type or issubclass(object, object)) and \ 62 60 _has_good_attr(object, "_com_interfaces_") and \ 63 61 _has_good_attr(object, "_reg_clsid_") and \ … … 148 146 self.autoRegisterComponent(when, entry) 149 147 # Handle some common user errors 150 except xpcom.COMException ,details:148 except xpcom.COMException as details: 151 149 from xpcom import nsError 152 150 # If the interface name does not exist, suppress the traceback … … 156 154 else: 157 155 logger.exception("Registration of '%s' failed!", entry.leafName) 158 except SyntaxError ,details:156 except SyntaxError as details: 159 157 # Syntax error in source file - no useful traceback here either. 160 158 logger.error("Registration of '%s' failed\n %s", … … 226 224 227 225 def MakePythonComponentLoaderModule(serviceManager, nsIFile): 228 import module226 from . import module 229 227 return module.Module( [PythonComponentLoader] ) -
trunk/src/libs/xpcom18a4/python/server/module.py
r59795 r59798 39 39 from xpcom import nsError 40 40 41 import factory41 from . import factory 42 42 43 43 import types … … 66 66 # void function. 67 67 fname = os.path.basename(location.path) 68 for klass in self.components.values():68 for klass in list(self.components.values()): 69 69 reg_contractid = klass._reg_contractid_ 70 print "Registering '%s' (%s)" % (reg_contractid, fname)70 print("Registering '%s' (%s)" % (reg_contractid, fname)) 71 71 reg_desc = getattr(klass, "_reg_desc_", reg_contractid) 72 72 compMgr = compMgr.queryInterface(components.interfaces.nsIComponentRegistrar) … … 85 85 def unregisterSelf(self, compMgr, location, loaderStr): 86 86 # void function. 87 for klass in self.components.values():87 for klass in list(self.components.values()): 88 88 ok = 1 89 89 try: … … 99 99 ok = 0 100 100 if ok: 101 print "Successfully unregistered", klass.__name__101 print("Successfully unregistered", klass.__name__) 102 102 else: 103 print "Unregistration of", klass.__name__, "failed. (probably just not already registered)"103 print("Unregistration of", klass.__name__, "failed. (probably just not already registered)") 104 104 105 105 def canUnload(self, compMgr): -
trunk/src/libs/xpcom18a4/python/server/policy.py
r59795 r59798 43 43 import types 44 44 import logging 45 import sys 45 46 46 47 … … 61 62 _supports_primitives_map_ = {} # Filled on first use. 62 63 63 _interface_sequence_types_ = types.TupleType, types.ListType 64 _string_types_ = types.StringType, types.UnicodeType 64 _interface_sequence_types_ = tuple, list 65 if sys.version_info[0] <= 2: 66 _string_types_ = str, unicode 67 else: 68 _string_types_ = bytes, str 65 69 XPTI_GetInterfaceInfoManager = _xpcom.XPTI_GetInterfaceInfoManager 66 70 … … 142 146 self._iid_ = iid 143 147 if ni is None: 144 raise ValueError , "The object '%r' can not be used as a COM object" % (instance,)148 raise ValueError("The object '%r' can not be used as a COM object" % (instance,)) 145 149 # This is really only a check for the user 146 150 if __debug__: … … 286 290 if logger.isEnabledFor(logging.DEBUG): 287 291 try: 288 raise exc_info[0] , exc_info[1], exc_info[2]292 raise exc_info[0](exc_info[1]).with_traceback(exc_info[2]) 289 293 except: 290 294 logger.debug("'%s' raised COM Exception %s", … … 294 298 # As above, trick the logging module to handle Python 2.3 295 299 try: 296 raise exc_info[0] , exc_info[1], exc_info[2]300 raise exc_info[0](exc_info[1]).with_traceback(exc_info[2]) 297 301 except: 298 302 logger.exception("Unhandled exception calling '%s'", func_name) … … 331 335 _supports_primitives_data_ = [ 332 336 ("nsISupportsCString", "__str__", str), 333 ("nsISupportsString", "__unicode__", unicode),334 ("nsISupportsPRUint64", "__long__", long),335 ("nsISupportsPRInt64", "__long__", long),337 ("nsISupportsString", "__unicode__", str), 338 ("nsISupportsPRUint64", "__long__", int), 339 ("nsISupportsPRInt64", "__long__", int), 336 340 ("nsISupportsPRUint32", "__int__", int), 337 341 ("nsISupportsPRInt32", "__int__", int), -
trunk/src/libs/xpcom18a4/python/src/PyXPCOM.h
r59795 r59798 133 133 # endif 134 134 135 # if PY_MAJOR_VERSION >= 3 136 # define PyInt_FromLong(l) PyLong_FromLong(l) 137 # define PyInt_Check(o) PyLong_Check(o) 138 # define PyInt_AsLong(o) PyLong_AsLong(o) 139 # define PyNumber_Int(o) PyNumber_Long(o) 140 # ifndef PyUnicode_AsUTF8 141 # define PyUnicode_AsUTF8(o) _PyUnicode_AsString(o) 142 # endif 143 # ifndef PyUnicode_AsUTF8AndSize 144 # define PyUnicode_AsUTF8AndSize(o,s) _PyUnicode_AsStringAndSize(o,s) 145 # endif 146 typedef struct PyMethodChain 147 { 148 PyMethodDef *methods; 149 struct PyMethodChain *link; 150 } PyMethodChain; 151 # endif 152 135 153 #endif /* VBOX_PYXPCOM */ 136 154 … … 268 286 static int Py_setattr(PyObject *op, char *name, PyObject *v); 269 287 static int Py_cmp(PyObject *ob1, PyObject *ob2); 288 static PyObject *Py_richcmp(PyObject *ob1, PyObject *ob2, int op); 270 289 static long Py_hash(PyObject *self); 271 290 }; … … 419 438 /* Python support */ 420 439 static PyObject *PyTypeMethod_getattr(PyObject *self, char *name); 440 #if PY_MAJOR_VERSION <= 2 421 441 static int PyTypeMethod_compare(PyObject *self, PyObject *ob); 442 #endif 443 static PyObject *PyTypeMethod_richcompare(PyObject *self, PyObject *ob, int op); 422 444 static PyObject *PyTypeMethod_repr(PyObject *self); 423 445 static long PyTypeMethod_hash(PyObject *self); -
trunk/src/libs/xpcom18a4/python/test/test_test_component.py
r59795 r59798 253 253 test_attribute(c, "iid_value", component_iid, new_iid) 254 254 test_attribute(c, "iid_value", component_iid, str(new_iid), new_iid) 255 test_attribute(c, "iid_value", component_iid, xpcom._xpcom.I ID(new_iid))255 test_attribute(c, "iid_value", component_iid, xpcom._xpcom.ID(new_iid)) 256 256 257 257 test_attribute_failure(c, "no_attribute", "boo", AttributeError) -
trunk/src/libs/xpcom18a4/python/vboxxpcom.py
r59795 r59798 1 1 """ 2 Copyright (C) 2008-201 2Oracle Corporation2 Copyright (C) 2008-2016 Oracle Corporation 3 3 4 4 This file is part of VirtualBox Open Source Edition (OSE), as … … 47 47 _oVBoxPythonMod = __import__(m) 48 48 break 49 except Exception ,x:50 print 'm=%s x=%s' % (m, x);49 except Exception as x: 50 print('m=%s x=%s' % (m, x)) 51 51 #except: 52 52 # pass -
trunk/src/libs/xpcom18a4/python/xpt.py
r59795 r59798 72 72 import xpcom._xpcom 73 73 74 from xpcom_consts import *74 from .xpcom_consts import * 75 75 76 76 class Interface: … … 100 100 if xpcom.verbose: 101 101 # The user may be confused as to why this is happening! 102 print "The parent interface of IID '%s' can not be located - assuming nsISupports"102 print("The parent interface of IID '%s' can not be located - assuming nsISupports") 103 103 return Interface(xpcom._xpcom.IID_nsISupports) 104 104 105 105 def Describe_Python(self): 106 106 method_reprs = [] 107 methods = filter(lambda m: not m.IsNotXPCOM(), self.methods)107 methods = [m for m in self.methods if not m.IsNotXPCOM()] 108 108 for m in methods: 109 109 method_reprs.append(m.Describe_Python()) … … 130 130 s = s + ' Scriptable: ' + word + '\n' 131 131 s = s + ' Methods:\n' 132 methods = filter(lambda m: not m.IsNotXPCOM(), self.methods)132 methods = [m for m in self.methods if not m.IsNotXPCOM()] 133 133 if len(methods): 134 134 for m in methods: … … 153 153 except xpcom.Exception: 154 154 if xpcom.verbose: 155 print "** GetMethodCount failed?? - assuming no methods"155 print("** GetMethodCount failed?? - assuming no methods") 156 156 self.items = [] 157 157 def __len__(self): … … 252 252 253 253 def desc(a): return a.Describe() 254 method_desc = string.join( map(desc, self.params), ', ')254 method_desc = string.join(list(map(desc, self.params)), ', ') 255 255 result_type = TypeDescriber(self.result_desc[0], None) 256 256 return_desc = result_type.Describe() … … 329 329 except xpcom.Exception: 330 330 if xpcom.verbose: 331 print "** GetConstantCount failed?? - assuming no constants"331 print("** GetConstantCount failed?? - assuming no constants") 332 332 self.items = [] 333 333 def __len__(self): … … 452 452 describer_name = describer_name + "_" + mode.capitalize() 453 453 describer = getattr(interface, describer_name) 454 print describer()454 print(describer()) 455 455 456 456 if __name__=='__main__': 457 457 if len(sys.argv) == 1: 458 print "Usage: xpt.py [-xptinfo] interface_name, ..."459 print " -info: Dump in a style similar to the xptdump tool"460 print "Dumping nsISupports and nsIInterfaceInfo"458 print("Usage: xpt.py [-xptinfo] interface_name, ...") 459 print(" -info: Dump in a style similar to the xptdump tool") 460 print("Dumping nsISupports and nsIInterfaceInfo") 461 461 sys.argv.append('nsIInterfaceInfo') 462 462 sys.argv.append('-xptinfo')
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器