VirtualBox

vbox的更動 59798 路徑 trunk/src/libs


忽略:
時間撮記:
2016-2-24 下午02:35:47 (9 年 以前)
作者:
vboxsync
訊息:

re-applied the Python 3 changes which were backed out in r105674 sans the changes in .cpp

位置:
trunk/src/libs/xpcom18a4/python
檔案:
修改 15 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/libs/xpcom18a4/python/Makefile.kmk

    r59795 r59798  
    55
    66#
    7 # Copyright (C) 2009-2015 Oracle Corporation
     7# Copyright (C) 2009-2016 Oracle Corporation
    88#
    99# This file is part of VirtualBox Open Source Edition (OSE), as
     
    2727#
    2828# 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.
    3031#
    3132ifeq ($(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.5
    34   VBOX_PYTHON25_LIB = $(VBOX_PATH_MACOSX_SDK)/usr/lib/libpython2.5.dylib
    35   VBOX_PYTHON25_LIB_X86 = $(VBOX_PYTHON25_LIB)
    36  endif
    3733 if  !defined(VBOX_WITHOUT_VBOXPYTHON_FOR_OSX_10_6) \
    3834  && (   !defined(VBOX_OSE) \
     
    4945  VBOX_PYTHON27_LIB_X86 = $(VBOX_PYTHON27_LIB)
    5046 endif
     47 # No Python 3.x yet as part of OSX versions including El Capitan, 10.11.
    5148
    5249else
     
    115112
    116113
    117 ifdef VBOX_PYTHON23_INC
    118 #
    119 # Python 2.3 version
    120 #
    121 DLLS += VBoxPython2_3
    122 VBoxPython2_3_EXTENDS    = VBoxPythonBase
    123 VBoxPython2_3_EXTENDS_BY = appending
    124 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_API
    129 DLLS += VBoxPython2_3_x86
    130 VBoxPython2_3_x86_EXTENDS    = VBoxPythonBase_x86
    131 VBoxPython2_3_x86_EXTENDS_BY = appending
    132 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  endif
    136 endif
    137 
    138 ifdef VBOX_PYTHON24_INC
    139 #
    140 # Python 2.4 version
    141 #
    142 DLLS += VBoxPython2_4
    143 VBoxPython2_4_EXTENDS    = VBoxPythonBase
    144 VBoxPython2_4_EXTENDS_BY = appending
    145 VBoxPython2_4_INCS       = $(VBOX_PYTHON24_INC)
    146 VBoxPython2_4_LIBS       = $(VBOX_PYTHON24_LIB)
    147 
    148  ifdef VBOX_WITH_32_ON_64_MAIN_API
    149 DLLS += VBoxPython2_4_x86
    150 VBoxPython2_4_x86_EXTENDS    = VBoxPythonBase_x86
    151 VBoxPython2_4_x86_EXTENDS_BY = appending
    152 VBoxPython2_4_x86_INCS       = $(VBOX_PYTHON24_INC)
    153 VBoxPython2_4_x86_LIBS       = $(VBOX_PYTHON24_LIB_X86)
    154  endif
    155 endif
    156 
    157 ifdef VBOX_PYTHON25_INC
    158 #
    159 # Python 2.5 version
    160 #
    161 DLLS += VBoxPython2_5
    162 VBoxPython2_5_EXTENDS    = VBoxPythonBase
    163 VBoxPython2_5_EXTENDS_BY = appending
    164 VBoxPython2_5_INCS       = $(VBOX_PYTHON25_INC)
    165 VBoxPython2_5_LIBS       = $(VBOX_PYTHON25_LIB)
    166 
    167  ifdef VBOX_WITH_32_ON_64_MAIN_API
    168 DLLS += VBoxPython2_5_x86
    169 VBoxPython2_5_x86_EXTENDS    = VBoxPythonBase_x86
    170 VBoxPython2_5_x86_EXTENDS_BY = appending
    171 VBoxPython2_5_x86_INCS       = $(VBOX_PYTHON25_INC)
    172 VBoxPython2_5_x86_LIBS       = $(VBOX_PYTHON25_LIB_X86)
    173  endif
    174 endif
    175 
    176114ifdef VBOX_PYTHON26_INC
    177115#
     
    213151VBoxPython2_7_x86_INCS       = $(VBOX_PYTHON27_INC)
    214152VBoxPython2_7_x86_LIBS       = $(VBOX_PYTHON27_LIB_X86)
     153 endif
     154endif
     155
     156ifdef VBOX_PYTHON31_INC
     157#
     158# Python 3.1 version
     159#
     160DLLS += VBoxPython3_1
     161VBoxPython3_1_EXTENDS    = VBoxPythonBase
     162VBoxPython3_1_EXTENDS_BY = appending
     163VBoxPython3_1_TEMPLATE   = XPCOM
     164VBoxPython3_1_INCS       = $(VBOX_PYTHON31_INC)
     165VBoxPython3_1_LIBS       = $(VBOX_PYTHON31_LIB)
     166
     167 ifdef VBOX_WITH_32_ON_64_MAIN_API
     168DLLS += VBoxPython3_1_x86
     169VBoxPython3_1_x86_EXTENDS    = VBoxPythonBase_x86
     170VBoxPython3_1_x86_EXTENDS_BY = appending
     171VBoxPython3_1_x86_TEMPLATE   = XPCOM
     172VBoxPython3_1_x86_INCS       = $(VBOX_PYTHON31_INC)
     173VBoxPython3_1_x86_LIBS       = $(VBOX_PYTHON31_LIB_X86)
     174 endif
     175endif
     176
     177ifdef VBOX_PYTHON32_INC
     178#
     179# Python 3.2 version
     180#
     181DLLS += VBoxPython3_2
     182VBoxPython3_2_EXTENDS    = VBoxPythonBase
     183VBoxPython3_2_EXTENDS_BY = appending
     184VBoxPython3_2_TEMPLATE   = XPCOM
     185VBoxPython3_2_INCS       = $(VBOX_PYTHON32_INC)
     186VBoxPython3_2_LIBS       = $(VBOX_PYTHON32_LIB)
     187
     188 ifdef VBOX_WITH_32_ON_64_MAIN_API
     189DLLS += VBoxPython3_2_x86
     190VBoxPython3_2_x86_EXTENDS    = VBoxPythonBase_x86
     191VBoxPython3_2_x86_EXTENDS_BY = appending
     192VBoxPython3_2_x86_TEMPLATE   = XPCOM
     193VBoxPython3_2_x86_INCS       = $(VBOX_PYTHON32_INC)
     194VBoxPython3_2_x86_LIBS       = $(VBOX_PYTHON32_LIB_X86)
     195 endif
     196endif
     197
     198ifdef VBOX_PYTHON33_INC
     199#
     200# Python 3.3 version
     201#
     202DLLS += VBoxPython3_3
     203VBoxPython3_3_EXTENDS    = VBoxPythonBase
     204VBoxPython3_3_EXTENDS_BY = appending
     205VBoxPython3_3_TEMPLATE   = XPCOM
     206VBoxPython3_3_INCS       = $(VBOX_PYTHON33_INC)
     207VBoxPython3_3_LIBS       = $(VBOX_PYTHON33_LIB)
     208
     209 ifdef VBOX_WITH_32_ON_64_MAIN_API
     210DLLS += VBoxPython3_3_x86
     211VBoxPython3_3_x86_EXTENDS    = VBoxPythonBase_x86
     212VBoxPython3_3_x86_EXTENDS_BY = appending
     213VBoxPython3_3_x86_TEMPLATE   = XPCOM
     214VBoxPython3_3_x86_INCS       = $(VBOX_PYTHON33_INC)
     215VBoxPython3_3_x86_LIBS       = $(VBOX_PYTHON33_LIB_X86)
     216 endif
     217endif
     218
     219ifdef VBOX_PYTHON34_INC
     220#
     221# Python 3.4 version
     222#
     223DLLS += VBoxPython3_4
     224VBoxPython3_4_EXTENDS    = VBoxPythonBase
     225VBoxPython3_4_EXTENDS_BY = appending
     226VBoxPython3_4_TEMPLATE   = XPCOM
     227VBoxPython3_4_INCS       = $(VBOX_PYTHON34_INC)
     228VBoxPython3_4_LIBS       = $(VBOX_PYTHON34_LIB)
     229
     230 ifdef VBOX_WITH_32_ON_64_MAIN_API
     231DLLS += VBoxPython3_4_x86
     232VBoxPython3_4_x86_EXTENDS    = VBoxPythonBase_x86
     233VBoxPython3_4_x86_EXTENDS_BY = appending
     234VBoxPython3_4_x86_TEMPLATE   = XPCOM
     235VBoxPython3_4_x86_INCS       = $(VBOX_PYTHON34_INC)
     236VBoxPython3_4_x86_LIBS       = $(VBOX_PYTHON34_LIB_X86)
     237 endif
     238endif
     239
     240ifdef VBOX_PYTHON35_INC
     241#
     242# Python 3.5 version
     243#
     244DLLS += VBoxPython3_5
     245VBoxPython3_5_EXTENDS    = VBoxPythonBase
     246VBoxPython3_5_EXTENDS_BY = appending
     247VBoxPython3_5_TEMPLATE   = XPCOM
     248VBoxPython3_5_INCS       = $(VBOX_PYTHON35_INC)
     249VBoxPython3_5_LIBS       = $(VBOX_PYTHON35_LIB)
     250
     251 ifdef VBOX_WITH_32_ON_64_MAIN_API
     252DLLS += VBoxPython3_5_x86
     253VBoxPython3_5_x86_EXTENDS    = VBoxPythonBase_x86
     254VBoxPython3_5_x86_EXTENDS_BY = appending
     255VBoxPython3_5_x86_TEMPLATE   = XPCOM
     256VBoxPython3_5_x86_INCS       = $(VBOX_PYTHON35_INC)
     257VBoxPython3_5_x86_LIBS       = $(VBOX_PYTHON35_LIB_X86)
    215258 endif
    216259endif
  • trunk/src/libs/xpcom18a4/python/__init__.py

    r59795 r59798  
    3838
    3939# The XPCOM (Cross Platform COM) package.
    40 import exceptions
     40from __future__ import print_function
     41import sys
     42if sys.version_info[0] <= 2:
     43    import exceptions
     44    XPCOMBaseException = exceptions.Exception
     45else:
     46    XPCOMBaseException = Exception
    4147
    4248# A global "verbose" flag - currently used by the
     
    4854# The standard XPCOM exception object.
    4955# Instances of this class are raised by the XPCOM extension module.
    50 class Exception(exceptions.Exception):
     56class Exception(XPCOMBaseException):
    5157    def __init__(self, errno, message = None):
    5258        assert int(errno) == errno, "The errno param must be an integer"
    5359        self.errno = errno
    5460        self.msg = message
    55         exceptions.Exception.__init__(self, errno)
     61        XPCOMBaseException.__init__(self, errno)
    5662    def __str__(self):
    5763        if not hr_map:
    58             import nsError
    59             for name, val in nsError.__dict__.items():
     64            from . import nsError
     65            for name, val in list(nsError.__dict__.items()):
    6066                if type(val)==type(0):
    6167                    hr_map[val] = name
     
    8086    def __init__(self, errno=None, *args, **kw):
    8187        if errno is None:
    82             import nsError
     88            from . import nsError
    8389            errno = nsError.NS_ERROR_FAILURE
    8490        Exception.__init__(self, errno, *args, **kw)
     
    98104        pass
    99105    def write(self, msg):
    100         import _xpcom
     106        import xpcom._xpcom as _xpcom
    101107        _xpcom.LogConsoleMessage(msg)
    102108    def close(self):
     
    104110
    105111def setupLogging():
    106     import sys, os, threading, thread
     112    import os
     113    if sys.version_info[0] <= 2:
     114        import threading, thread
    107115    hdlr = logging.StreamHandler(ConsoleServiceStream())
    108116    fmt = logging.Formatter(logging.BASIC_FORMAT)
     
    113121    # Later versions of logging use an RLock, so we detect an "old" style
    114122    # 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()
    117126
    118127    logger.addHandler(hdlr)
     
    126135            # open without buffering so never pending output
    127136            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)
    131139            # stream remains default
    132140
    133141    hdlr = logging.StreamHandler(stream)
    134142    # 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()
    137146
    138147    fmt = logging.Formatter(logging.BASIC_FORMAT)
  • trunk/src/libs/xpcom18a4/python/client/__init__.py

    r59795 r59798  
    3737
    3838import os
    39 import new
     39from types import MethodType
    4040import logging
    4141from xpcom import xpt, COMException, nsError, logger
     
    126126    # Exec the code object
    127127    tempNameSpace = {}
    128     exec codeObject in globals(), tempNameSpace
     128    exec(codeObject, globals(), tempNameSpace)
    129129    ret = tempNameSpace[name]
    130     if not interface_method_cache.has_key(iid):
     130    if iid not in interface_method_cache:
    131131        interface_method_cache[iid] = {}
    132132    interface_method_cache[iid][name] = ret
     
    153153            if flags & FLAGS_TO_IGNORE == 0:
    154154                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])
    156156                    setters[m.name] = m.method_index, param_flags
    157157                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])
    159159                    getters[m.name] = m.method_index, param_flags
    160160                else:
     
    220220            except COMException:
    221221                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")
    223223
    224224    def __int__(self):
     
    281281                for nominated_iid in interface_infos:
    282282                    # Interface may appear twice in the class info list, so check this here.
    283                     if not self.__dict__['_interface_infos_'].has_key(nominated_iid):
     283                    if nominated_iid not in self.__dict__['_interface_infos_']:
    284284                        # Just invoke our QI on the object
    285285                        self.queryInterface(nominated_iid)
     
    290290                    contractid_info_cache[real_cid] = contractid_info
    291291            else:
    292                 for key, val in contractid_info.items():
     292                for key, val in list(contractid_info.items()):
    293293                    self.__dict__[key].update(val)
    294294
     
    300300        # rebuild the world for each new object.
    301301        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!"
    303303        try:
    304304            method_infos, getters, setters, constants = BuildInterfaceInfo(iid)
    305         except COMException, why:
     305        except COMException as why:
    306306            # Failing to build an interface info generally isn't a real
    307307            # problem - its probably just that the interface is non-scriptable.
     
    314314        iis[iid] = method_infos, getters, setters, constants
    315315        names = self.__dict__['_name_to_interface_iid_']
    316         for name in method_infos.keys(): names[name] = iid
    317         for name in getters.keys(): names[name] = iid
    318         for name in setters.keys(): names[name] = iid
    319         for name in constants.keys():  names[name] = iid
     316        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
    320320
    321321    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!"
    324324            return self
    325325        # 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_:
    327327            self._remember_interface_info(iid)
    328328        iface_info = self._interface_infos_[iid]
     
    350350    def __getattr__(self, attr):
    351351        if attr in _special_getattr_names:
    352             raise AttributeError, attr
     352            raise AttributeError(attr)
    353353        # First allow the interface name to return the "raw" interface
    354354        interface = self.__dict__['_interface_names_'].get(attr, None)
     
    375375        # Some interfaces may provide this name via "native" support.
    376376        # 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()):
    378378            try:
    379379                ret = getattr(interface, attr)
     
    382382            except AttributeError:
    383383                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))
    385385       
    386386    def __setattr__(self, attr, val):
     
    397397            setattr(interface, attr, val)
    398398            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))
    400400
    401401    def _get_classinfo_repr_(self):
     
    410410            self.__dict__['_tried_classinfo_'] = 0
    411411
    412         iface_names = self.__dict__['_interface_names_'].keys()
     412        iface_names = list(self.__dict__['_interface_names_'].keys())
    413413        try:
    414414            iface_names.remove("nsISupports")
     
    436436        self.__dict__.update(constants)
    437437        # 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())
    439439
    440440    def __getattr__(self, attr):
    441441        # Allow the underlying interface to provide a better implementation if desired.
    442442        if attr in _special_getattr_names:
    443             raise AttributeError, attr
     443            raise AttributeError(attr)
    444444
    445445        ret = getattr(self.__dict__['_comobj_'], attr, None)
     
    449449        unbound_method = self.__dict__['_methods_'].get(attr, None)
    450450        if unbound_method is not None:
    451             return new.instancemethod(unbound_method, self, self.__class__)
     451            return MethodType(unbound_method, self)
    452452
    453453        getters = self.__dict__['_property_getters_']
     
    456456            method_index, param_infos = info
    457457            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!")
    459459            args = ( param_infos, () )
    460460            return XPTC_InvokeByIndex(self._comobj_, method_index, args)
     
    467467            # Cache it locally
    468468            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))
    472472
    473473    def __setattr__(self, attr, val):
    474474        # If we already have a __dict__ item of that name, and its not one of
    475475        # 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_']:
    477477            self.__dict__[attr] = val
    478478            return
     
    481481        info = setters.get(attr)
    482482        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))
    484484        method_index, param_infos = info
    485485        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!")
    487487        real_param_infos = ( param_infos, (val,) )
    488488        return XPTC_InvokeByIndex(self._comobj_, method_index, real_param_infos)
     
    527527        try:
    528528            return Component(self._comobj_.QueryReferent(iid)._comobj_, iid)
    529         except COMException, details:
     529        except COMException as details:
    530530            if details.errno != nsError.NS_ERROR_NULL_POINTER:
    531531                raise
  • trunk/src/libs/xpcom18a4/python/components.py

    r59795 r59798  
    3737
    3838# This module provides the JavaScript "components" interface
    39 import xpt
    40 import xpcom, _xpcom
     39from . import xpt
     40import xpcom
     41import xpcom._xpcom as _xpcom
    4142import xpcom.client
    4243import xpcom.server
    43 import types
    44 
    45 StringTypes = [types.StringType, types.UnicodeType]
     44
     45StringTypes = [bytes, str]
    4646
    4747def _get_good_iid(iid):
     
    7979        if self._dict_data is None:
    8080            self._dict_data = self._build_dict()
    81         return self._dict_data.keys()
     81        return list(self._dict_data.keys())
    8282    def items(self):
    8383        if self._dict_data is None:
    8484            self._dict_data = self._build_dict()
    85         return self._dict_data.items()
     85        return list(self._dict_data.items())
    8686    def values(self):
    8787        if self._dict_data is None:
    8888            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)
    9494
    9595    def __len__(self):
     
    9999
    100100    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:
    102102            return self._dict_data[attr]
    103103        return self._get_one(attr)
    104104    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:
    106106            return self._dict_data[item]
    107107        return self._get_one(item)
     
    120120        other_iid = getattr(other, "_iidobj_", other)
    121121        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
    122126    def __hash__(self):
    123127        return hash(self._iidobj_)
     
    125129        return str(self._iidobj_)
    126130    def __getitem__(self, item):
    127         raise TypeError, "components.interface objects are not subscriptable"
     131        raise TypeError("components.interface objects are not subscriptable")
    128132    def __setitem__(self, item, value):
    129         raise TypeError, "components.interface objects are not subscriptable"
     133        raise TypeError("components.interface objects are not subscriptable")
    130134    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")
    132136    def __getattr__(self, attr):
    133137        # Support constants as attributes.
     
    139143                c[c_ob.name] = c_ob.value
    140144            _constants_by_iid_map[self._iidobj_] = c
    141         if c.has_key(attr):
     145        if attr in c:
    142146            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))
    144148
    145149
     
    148152        try:
    149153            item = interfaceInfoManager.GetInfoForName(name)
    150         except xpcom.COMException, why:
     154        except xpcom.COMException as why:
    151155            # Present a better exception message, and give a more useful error code.
    152             import nsError
     156            from . import nsError
    153157            raise xpcom.COMException(nsError.NS_ERROR_NO_INTERFACE, "The interface '%s' does not exist" % (name,))
    154158        return _Interface(item.GetName(), item.GetIID())
     
    180184            self.clsid = rc
    181185            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))
    183187    def createInstance(self, iid = None):
    184188        import xpcom.client
    185189        try:
    186190            return xpcom.client.Component(self.contractid, _get_good_iid(iid))
    187         except xpcom.COMException, details:
    188             import nsError
     191        except xpcom.COMException as details:
     192            from . import nsError
    189193            # Handle "no such component" in a cleaner way for the user.
    190194            if details.errno == nsError.NS_ERROR_FACTORY_NOT_REGISTERED:
     
    219223
    220224# The ID function
    221 ID = _xpcom.IID
     225ID = _xpcom.ID
    222226
    223227# A helper to cleanup our namespace as xpcom shuts down.
  • trunk/src/libs/xpcom18a4/python/file.py

    r59795 r59798  
    156156        self.close()
    157157        if mode != "r":
    158             raise ValueError, "only 'r' mode supported'"
     158            raise ValueError("only 'r' mode supported")
    159159        io_service = components.classes["@mozilla.org/network/io-service;1"] \
    160160                        .getService(components.interfaces.nsIIOService)
     
    165165        # Mozilla asserts and starts saying "NULL POINTER" if this is wrong!
    166166        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)"
    168168                                  % (url_ob.spec,))
    169169        self.channel = io_service.newChannelFromURI(url_ob)
     
    202202            self.inputStream.init(self.fileIO)
    203203        else:
    204             raise ValueError, "Unknown mode"
     204            raise ValueError("Unknown mode")
    205205
    206206    def close(self):
     
    226226    got = got + file.read()
    227227    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)))
    229229
    230230def _DoTestBufferRead(file, expected):
     
    240240        got = got + str(buffer[:num])
    241241    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)))
    243243
    244244def _TestLocalFile():
     
    266266        # Open the same file again for writing - this should delete the old one.
    267267        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,))
    269269        test_file = LocalFile(fname, "w")
    270270        test_file.write(data)
     
    305305def _TestURI(url):
    306306    test_file = URIFile(url)
    307     print "Opened file is", test_file
     307    print("Opened file is", test_file)
    308308    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))
    310310    test_file.close()
    311311
     
    313313    import sys
    314314    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")
    316316        _TestAll()
    317317    else:
  • trunk/src/libs/xpcom18a4/python/gen_python_deps.py

    r59795 r59798  
    22
    33"""
    4 Copyright (C) 2009-2013 Oracle Corporation
     4Copyright (C) 2009-2016 Oracle Corporation
    55
    66This file is part of VirtualBox Open Source Edition (OSE), as
     
    1414
    1515import os,sys
     16from distutils.version import StrictVersion
    1617
    17 versions = ["2.3", "2.4", "2.5", "2.6", "2.7",]
     18versions = ["2.6", "2.7", "3.1", "3.2", "3.3", "3.4", "3.5"]
    1819prefixes = ["/usr", "/usr/local", "/opt", "/opt/local"]
    1920known = {}
     
    4142
    4243def 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))
    4445    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))
    4748    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))
    4950
    5051
     
    9192
    9293    for v in versions:
     94        if StrictVersion(v) < StrictVersion('2.6'):
     95            continue
    9396        for p in prefixes:
    9497            c = checkPair(p, v, dllpre, dllsuff, bitness_magic)
     
    9699                known[v] = c
    97100                break
    98     keys = known.keys()
     101    keys = list(known.keys())
    99102    # we want default to be the lowest versioned Python
    100103    keys.sort()
  • trunk/src/libs/xpcom18a4/python/primitives.py

    r59795 r59798  
    3535        better = _primitives_map[prin.type]
    3636    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,))
    3838    prin = prin.QueryInterface(better)
    3939    return prin.data
  • trunk/src/libs/xpcom18a4/python/server/__init__.py

    r59795 r59798  
    3838# The xpcom.server package.
    3939
    40 from policy import DefaultPolicy
     40from xpcom.server.policy import DefaultPolicy
    4141from xpcom import _xpcom
    4242
     
    8080# Python!
    8181def NS_GetModule( serviceManager, nsIFile ):
    82     import loader
     82    from . import loader
    8383    iid = _xpcom.IID_nsIModule
    8484    return WrapObject(loader.MakePythonComponentLoaderModule(serviceManager, nsIFile), iid, bWrapClient = 0)
    8585
    8686def _shutdown():
    87     from policy import _shutdown
     87    from server.policy import _shutdown
    8888    _shutdown()
  • trunk/src/libs/xpcom18a4/python/server/loader.py

    r59795 r59798  
    3838import xpcom
    3939from xpcom import components, logger
    40 
    41 import module
    42 
    43 import glob, os, types
    44 
     40from . import module
     41import glob
     42import os
    4543from xpcom.client import Component
    4644
     
    5755    # For now, just run over all classes looking for likely candidates.
    5856    comps = []
    59     for name, object in py_module.__dict__.items():
     57    for name, object in list(py_module.__dict__.items()):
    6058        try:
    61             if (type(object) == types.ClassType or issubclass(object, object)) and \
     59            if (type(object) == type or issubclass(object, object)) and \
    6260               _has_good_attr(object, "_com_interfaces_") and \
    6361               _has_good_attr(object, "_reg_clsid_") and \
     
    148146                    self.autoRegisterComponent(when, entry)
    149147                # Handle some common user errors
    150                 except xpcom.COMException, details:
     148                except xpcom.COMException as details:
    151149                    from xpcom import nsError
    152150                    # If the interface name does not exist, suppress the traceback
     
    156154                    else:
    157155                        logger.exception("Registration of '%s' failed!", entry.leafName)
    158                 except SyntaxError, details:
     156                except SyntaxError as details:
    159157                    # Syntax error in source file - no useful traceback here either.
    160158                    logger.error("Registration of '%s' failed\n %s",
     
    226224
    227225def MakePythonComponentLoaderModule(serviceManager, nsIFile):
    228     import module
     226    from . import module
    229227    return module.Module( [PythonComponentLoader] )
  • trunk/src/libs/xpcom18a4/python/server/module.py

    r59795 r59798  
    3939from xpcom import nsError
    4040
    41 import factory
     41from . import factory
    4242
    4343import types
     
    6666        # void function.
    6767        fname = os.path.basename(location.path)
    68         for klass in self.components.values():
     68        for klass in list(self.components.values()):
    6969            reg_contractid = klass._reg_contractid_
    70             print "Registering '%s' (%s)" % (reg_contractid, fname)
     70            print("Registering '%s' (%s)" % (reg_contractid, fname))
    7171            reg_desc = getattr(klass, "_reg_desc_", reg_contractid)
    7272            compMgr = compMgr.queryInterface(components.interfaces.nsIComponentRegistrar)
     
    8585    def unregisterSelf(self, compMgr, location, loaderStr):
    8686        # void function.
    87         for klass in self.components.values():
     87        for klass in list(self.components.values()):
    8888            ok = 1
    8989            try:
     
    9999                    ok = 0
    100100            if ok:
    101                 print "Successfully unregistered", klass.__name__
     101                print("Successfully unregistered", klass.__name__)
    102102            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)")
    104104       
    105105    def canUnload(self, compMgr):
  • trunk/src/libs/xpcom18a4/python/server/policy.py

    r59795 r59798  
    4343import types
    4444import logging
     45import sys
    4546
    4647
     
    6162_supports_primitives_map_ = {} # Filled on first use.
    6263
    63 _interface_sequence_types_ = types.TupleType, types.ListType
    64 _string_types_ = types.StringType, types.UnicodeType
     64_interface_sequence_types_ = tuple, list
     65if sys.version_info[0] <= 2:
     66    _string_types_ = str, unicode
     67else:
     68    _string_types_ = bytes, str
    6569XPTI_GetInterfaceInfoManager = _xpcom.XPTI_GetInterfaceInfoManager
    6670
     
    142146        self._iid_ = iid
    143147        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,))
    145149        # This is really only a check for the user
    146150        if __debug__:
     
    286290            if logger.isEnabledFor(logging.DEBUG):
    287291                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])
    289293                except:
    290294                    logger.debug("'%s' raised COM Exception %s",
     
    294298        # As above, trick the logging module to handle Python 2.3
    295299        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])
    297301        except:
    298302            logger.exception("Unhandled exception calling '%s'", func_name)
     
    331335_supports_primitives_data_ = [
    332336    ("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),
    336340    ("nsISupportsPRUint32", "__int__", int),
    337341    ("nsISupportsPRInt32", "__int__", int),
  • trunk/src/libs/xpcom18a4/python/src/PyXPCOM.h

    r59795 r59798  
    133133# endif
    134134
     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
     146typedef struct PyMethodChain
     147{
     148    PyMethodDef *methods;
     149    struct PyMethodChain *link;
     150} PyMethodChain;
     151# endif
     152
    135153#endif /* VBOX_PYXPCOM */
    136154
     
    268286        static int Py_setattr(PyObject *op, char *name, PyObject *v);
    269287        static int Py_cmp(PyObject *ob1, PyObject *ob2);
     288        static PyObject *Py_richcmp(PyObject *ob1, PyObject *ob2, int op);
    270289        static long Py_hash(PyObject *self);
    271290};
     
    419438        /* Python support */
    420439        static PyObject *PyTypeMethod_getattr(PyObject *self, char *name);
     440#if PY_MAJOR_VERSION <= 2
    421441        static int PyTypeMethod_compare(PyObject *self, PyObject *ob);
     442#endif
     443        static PyObject *PyTypeMethod_richcompare(PyObject *self, PyObject *ob, int op);
    422444        static PyObject *PyTypeMethod_repr(PyObject *self);
    423445        static long PyTypeMethod_hash(PyObject *self);
  • trunk/src/libs/xpcom18a4/python/test/test_test_component.py

    r59795 r59798  
    253253    test_attribute(c, "iid_value", component_iid, new_iid)
    254254    test_attribute(c, "iid_value", component_iid, str(new_iid), new_iid)
    255     test_attribute(c, "iid_value", component_iid, xpcom._xpcom.IID(new_iid))
     255    test_attribute(c, "iid_value", component_iid, xpcom._xpcom.ID(new_iid))
    256256
    257257    test_attribute_failure(c, "no_attribute", "boo", AttributeError)
  • trunk/src/libs/xpcom18a4/python/vboxxpcom.py

    r59795 r59798  
    11"""
    2 Copyright (C) 2008-2012 Oracle Corporation
     2Copyright (C) 2008-2016 Oracle Corporation
    33
    44This file is part of VirtualBox Open Source Edition (OSE), as
     
    4747        _oVBoxPythonMod =  __import__(m)
    4848        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))
    5151    #except:
    5252    #    pass
  • trunk/src/libs/xpcom18a4/python/xpt.py

    r59795 r59798  
    7272import xpcom._xpcom
    7373
    74 from xpcom_consts import *
     74from .xpcom_consts import *
    7575
    7676class Interface:
     
    100100            if xpcom.verbose:
    101101                # 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")
    103103            return Interface(xpcom._xpcom.IID_nsISupports)
    104104
    105105    def Describe_Python(self):
    106106        method_reprs = []
    107         methods = filter(lambda m: not m.IsNotXPCOM(), self.methods)
     107        methods = [m for m in self.methods if not m.IsNotXPCOM()]
    108108        for m in methods:
    109109            method_reprs.append(m.Describe_Python())
     
    130130        s = s + '         Scriptable: ' + word + '\n'
    131131        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()]
    133133        if len(methods):
    134134            for m in methods:
     
    153153        except xpcom.Exception:
    154154            if xpcom.verbose:
    155                 print "** GetMethodCount failed?? - assuming no methods"
     155                print("** GetMethodCount failed?? - assuming no methods")
    156156            self.items = []
    157157    def __len__(self):
     
    252252
    253253        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)), ', ')
    255255        result_type = TypeDescriber(self.result_desc[0], None)
    256256        return_desc = result_type.Describe()
     
    329329        except xpcom.Exception:
    330330            if xpcom.verbose:
    331                 print "** GetConstantCount failed?? - assuming no constants"
     331                print("** GetConstantCount failed?? - assuming no constants")
    332332            self.items = []
    333333    def __len__(self):
     
    452452        describer_name = describer_name + "_" + mode.capitalize()
    453453    describer = getattr(interface, describer_name)
    454     print describer()
     454    print(describer())
    455455
    456456if __name__=='__main__':
    457457    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")
    461461        sys.argv.append('nsIInterfaceInfo')
    462462        sys.argv.append('-xptinfo')
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette