VirtualBox

Changeset 59795 in vbox for trunk/src/libs/xpcom18a4/python


Ignore:
Timestamp:
Feb 24, 2016 9:13:27 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
105674
Message:

temporarily back out the recent Python 3 changes (r105649, r105645, r105644, r105643, r105641)

Location:
trunk/src/libs/xpcom18a4/python
Files:
30 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/python/Makefile.kmk

    r59769 r59795  
    55
    66#
    7 # Copyright (C) 2009-2016 Oracle Corporation
     7# Copyright (C) 2009-2015 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[26|27|31|32|33|34|35|DEF]_[INC|LIB] variables
    30 # which get picked up below.
     29# VBOX_PYTHON[25|26|27|DEF]_[INC|LIB] variables which get picked up below.
    3130#
    3231ifeq ($(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
    3337 if  !defined(VBOX_WITHOUT_VBOXPYTHON_FOR_OSX_10_6) \
    3438  && (   !defined(VBOX_OSE) \
     
    4549  VBOX_PYTHON27_LIB_X86 = $(VBOX_PYTHON27_LIB)
    4650 endif
    47  # No Python 3.x yet as part of OSX versions including El Capitan, 10.11.
    4851
    4952else
     
    112115
    113116
     117ifdef VBOX_PYTHON23_INC
     118#
     119# Python 2.3 version
     120#
     121DLLS += VBoxPython2_3
     122VBoxPython2_3_EXTENDS    = VBoxPythonBase
     123VBoxPython2_3_EXTENDS_BY = appending
     124VBoxPython2_3_TEMPLATE   = XPCOM$(if-expr "$(KBUILD_TARGET)" == "darwin",OSX104,)
     125VBoxPython2_3_INCS       = $(VBOX_PYTHON23_INC)
     126VBoxPython2_3_LIBS       = $(VBOX_PYTHON23_LIB)
     127
     128 ifdef VBOX_WITH_32_ON_64_MAIN_API
     129DLLS += VBoxPython2_3_x86
     130VBoxPython2_3_x86_EXTENDS    = VBoxPythonBase_x86
     131VBoxPython2_3_x86_EXTENDS_BY = appending
     132VBoxPython2_3_x86_TEMPLATE   = XPCOM$(if-expr "$(KBUILD_TARGET)" == "darwin",OSX104,-x86)
     133VBoxPython2_3_x86_INCS       = $(VBOX_PYTHON23_INC)
     134VBoxPython2_3_x86_LIBS       = $(VBOX_PYTHON23_LIB_X86)
     135 endif
     136endif
     137
     138ifdef VBOX_PYTHON24_INC
     139#
     140# Python 2.4 version
     141#
     142DLLS += VBoxPython2_4
     143VBoxPython2_4_EXTENDS    = VBoxPythonBase
     144VBoxPython2_4_EXTENDS_BY = appending
     145VBoxPython2_4_INCS       = $(VBOX_PYTHON24_INC)
     146VBoxPython2_4_LIBS       = $(VBOX_PYTHON24_LIB)
     147
     148 ifdef VBOX_WITH_32_ON_64_MAIN_API
     149DLLS += VBoxPython2_4_x86
     150VBoxPython2_4_x86_EXTENDS    = VBoxPythonBase_x86
     151VBoxPython2_4_x86_EXTENDS_BY = appending
     152VBoxPython2_4_x86_INCS       = $(VBOX_PYTHON24_INC)
     153VBoxPython2_4_x86_LIBS       = $(VBOX_PYTHON24_LIB_X86)
     154 endif
     155endif
     156
     157ifdef VBOX_PYTHON25_INC
     158#
     159# Python 2.5 version
     160#
     161DLLS += VBoxPython2_5
     162VBoxPython2_5_EXTENDS    = VBoxPythonBase
     163VBoxPython2_5_EXTENDS_BY = appending
     164VBoxPython2_5_INCS       = $(VBOX_PYTHON25_INC)
     165VBoxPython2_5_LIBS       = $(VBOX_PYTHON25_LIB)
     166
     167 ifdef VBOX_WITH_32_ON_64_MAIN_API
     168DLLS += VBoxPython2_5_x86
     169VBoxPython2_5_x86_EXTENDS    = VBoxPythonBase_x86
     170VBoxPython2_5_x86_EXTENDS_BY = appending
     171VBoxPython2_5_x86_INCS       = $(VBOX_PYTHON25_INC)
     172VBoxPython2_5_x86_LIBS       = $(VBOX_PYTHON25_LIB_X86)
     173 endif
     174endif
     175
    114176ifdef VBOX_PYTHON26_INC
    115177#
     
    151213VBoxPython2_7_x86_INCS       = $(VBOX_PYTHON27_INC)
    152214VBoxPython2_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)
    258215 endif
    259216endif
  • trunk/src/libs/xpcom18a4/python/__init__.py

    r59769 r59795  
    3838
    3939# The XPCOM (Cross Platform COM) package.
    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
     40import exceptions
    4741
    4842# A global "verbose" flag - currently used by the
     
    5448# The standard XPCOM exception object.
    5549# Instances of this class are raised by the XPCOM extension module.
    56 class Exception(XPCOMBaseException):
     50class Exception(exceptions.Exception):
    5751    def __init__(self, errno, message = None):
    5852        assert int(errno) == errno, "The errno param must be an integer"
    5953        self.errno = errno
    6054        self.msg = message
    61         XPCOMBaseException.__init__(self, errno)
     55        exceptions.Exception.__init__(self, errno)
    6256    def __str__(self):
    6357        if not hr_map:
    64             from . import nsError
    65             for name, val in list(nsError.__dict__.items()):
     58            import nsError
     59            for name, val in nsError.__dict__.items():
    6660                if type(val)==type(0):
    6761                    hr_map[val] = name
     
    8680    def __init__(self, errno=None, *args, **kw):
    8781        if errno is None:
    88             from . import nsError
     82            import nsError
    8983            errno = nsError.NS_ERROR_FAILURE
    9084        Exception.__init__(self, errno, *args, **kw)
     
    10498        pass
    10599    def write(self, msg):
    106         import xpcom._xpcom as _xpcom
     100        import _xpcom
    107101        _xpcom.LogConsoleMessage(msg)
    108102    def close(self):
     
    110104
    111105def setupLogging():
    112     import os
    113     if sys.version_info[0] <= 2:
    114         import threading, thread
     106    import sys, os, threading, thread
    115107    hdlr = logging.StreamHandler(ConsoleServiceStream())
    116108    fmt = logging.Formatter(logging.BASIC_FORMAT)
     
    121113    # Later versions of logging use an RLock, so we detect an "old" style
    122114    # handler and update its lock
    123     if sys.version_info[0] <= 2:
    124         if type(hdlr.lock) == thread.LockType:
    125             hdlr.lock = threading.RLock()
     115    if type(hdlr.lock) == thread.LockType:
     116        hdlr.lock = threading.RLock()
    126117
    127118    logger.addHandler(hdlr)
     
    135126            # open without buffering so never pending output
    136127            stream = open(filename, "wU", 0)
    137         except IOError as why:
    138             print("pyxpcom failed to open log file '%s': %s"  % (filename, why), file=sys.stderr)
     128        except IOError, why:
     129            print >> sys.stderr, "pyxpcom failed to open log file '%s': %s" \
     130                                 % (filename, why)
    139131            # stream remains default
    140132
    141133    hdlr = logging.StreamHandler(stream)
    142134    # see above - fix a deadlock problem on this handler too.
    143     if sys.version_info[0] <= 2:
    144         if type(hdlr.lock) == thread.LockType:
    145             hdlr.lock = threading.RLock()
     135    if type(hdlr.lock) == thread.LockType:
     136        hdlr.lock = threading.RLock()
    146137
    147138    fmt = logging.Formatter(logging.BASIC_FORMAT)
  • trunk/src/libs/xpcom18a4/python/client/__init__.py

    r59769 r59795  
    3737
    3838import os
    39 from types import MethodType
     39import new
    4040import logging
    4141from xpcom import xpt, COMException, nsError, logger
     
    126126    # Exec the code object
    127127    tempNameSpace = {}
    128     exec(codeObject, globals(), tempNameSpace)
     128    exec codeObject in globals(), tempNameSpace
    129129    ret = tempNameSpace[name]
    130     if iid not in interface_method_cache:
     130    if not interface_method_cache.has_key(iid):
    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 = list([(x.param_flags,) + xpt.MakeReprForInvoke(x) for x in m.params])
     155                    param_flags = map(lambda x: (x.param_flags,) + xpt.MakeReprForInvoke(x), m.params)
    156156                    setters[m.name] = m.method_index, param_flags
    157157                elif flags & XPT_MD_GETTER:
    158                     param_flags = list([(x.param_flags,) + xpt.MakeReprForInvoke(x) for x in m.params])
     158                    param_flags = map(lambda x: (x.param_flags,) + xpt.MakeReprForInvoke(x), 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 nominated_iid not in self.__dict__['_interface_infos_']:
     283                    if not self.__dict__['_interface_infos_'].has_key(nominated_iid):
    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 list(contractid_info.items()):
     292                for key, val in 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 iid not in iis, "Already remembered this interface!"
     302        assert not iis.has_key(iid), "Already remembered this interface!"
    303303        try:
    304304            method_infos, getters, setters, constants = BuildInterfaceInfo(iid)
    305         except COMException as why:
     305        except COMException, 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 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
     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
    320320
    321321    def QueryInterface(self, iid):
    322         if iid in self._interfaces_:
    323             assert iid_name in self._interface_names_, "_interfaces_ has the key, but _interface_names_ does not!"
     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!"
    324324            return self
    325325        # Haven't seen this before - do a real QI.
    326         if iid not in self._interface_infos_:
     326        if not self._interface_infos_.has_key(iid):
    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 list(self.__dict__['_interfaces_'].values()):
     377        for interface in 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 = list(self.__dict__['_interface_names_'].keys())
     412        iface_names = 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_'] = list(constants.keys())
     438        self.__dict__['_constant_names_'] = 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 MethodType(unbound_method, self)
     451            return new.instancemethod(unbound_method, self, self.__class__)
    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 MethodType(unbound_method, self)
    470 
    471         raise AttributeError("XPCOM component '%s' has no attribute '%s'" % (self._object_name_, attr))
     469            return new.instancemethod(unbound_method, self, self.__class__)
     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 attr in self.__dict__ and attr not in self.__dict__['_constant_names_']:
     476        if self.__dict__.has_key(attr) 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 as details:
     529        except COMException, details:
    530530            if details.errno != nsError.NS_ERROR_NULL_POINTER:
    531531                raise
  • trunk/src/libs/xpcom18a4/python/components.py

    r59769 r59795  
    3737
    3838# This module provides the JavaScript "components" interface
    39 from . import xpt
    40 import xpcom
    41 import xpcom._xpcom as _xpcom
     39import xpt
     40import xpcom, _xpcom
    4241import xpcom.client
    4342import xpcom.server
    44 
    45 StringTypes = [bytes, str]
     43import types
     44
     45StringTypes = [types.StringType, types.UnicodeType]
    4646
    4747def _get_good_iid(iid):
     
    7979        if self._dict_data is None:
    8080            self._dict_data = self._build_dict()
    81         return list(self._dict_data.keys())
     81        return self._dict_data.keys()
    8282    def items(self):
    8383        if self._dict_data is None:
    8484            self._dict_data = self._build_dict()
    85         return list(self._dict_data.items())
     85        return self._dict_data.items()
    8686    def values(self):
    8787        if self._dict_data is None:
    8888            self._dict_data = self._build_dict()
    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)
     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)
    9494
    9595    def __len__(self):
     
    9999
    100100    def __getattr__(self, attr):
    101         if self._dict_data is not None and attr in self._dict_data:
     101        if self._dict_data is not None and self._dict_data.has_key(attr):
    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 item in self._dict_data:
     105        if self._dict_data is not None and self._dict_data.has_key(item):
    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
    126122    def __hash__(self):
    127123        return hash(self._iidobj_)
     
    129125        return str(self._iidobj_)
    130126    def __getitem__(self, item):
    131         raise TypeError("components.interface objects are not subscriptable")
     127        raise TypeError, "components.interface objects are not subscriptable"
    132128    def __setitem__(self, item, value):
    133         raise TypeError("components.interface objects are not subscriptable")
     129        raise TypeError, "components.interface objects are not subscriptable"
    134130    def __setattr__(self, attr, value):
    135         raise AttributeError("Can not set attributes on components.Interface objects")
     131        raise AttributeError, "Can not set attributes on components.Interface objects"
    136132    def __getattr__(self, attr):
    137133        # Support constants as attributes.
     
    143139                c[c_ob.name] = c_ob.value
    144140            _constants_by_iid_map[self._iidobj_] = c
    145         if attr in c:
     141        if c.has_key(attr):
    146142            return c[attr]
    147         raise AttributeError("'%s' interfaces do not define a constant '%s'" % (self.name, attr))
     143        raise AttributeError, "'%s' interfaces do not define a constant '%s'" % (self.name, attr)
    148144
    149145
     
    152148        try:
    153149            item = interfaceInfoManager.GetInfoForName(name)
    154         except xpcom.COMException as why:
     150        except xpcom.COMException, why:
    155151            # Present a better exception message, and give a more useful error code.
    156             from . import nsError
     152            import nsError
    157153            raise xpcom.COMException(nsError.NS_ERROR_NO_INTERFACE, "The interface '%s' does not exist" % (name,))
    158154        return _Interface(item.GetName(), item.GetIID())
     
    184180            self.clsid = rc
    185181            return rc
    186         raise AttributeError("%s class has no attribute '%s'" % (self.contractid, attr))
     182        raise AttributeError, "%s class has no attribute '%s'" % (self.contractid, attr)
    187183    def createInstance(self, iid = None):
    188184        import xpcom.client
    189185        try:
    190186            return xpcom.client.Component(self.contractid, _get_good_iid(iid))
    191         except xpcom.COMException as details:
    192             from . import nsError
     187        except xpcom.COMException, details:
     188            import nsError
    193189            # Handle "no such component" in a cleaner way for the user.
    194190            if details.errno == nsError.NS_ERROR_FACTORY_NOT_REGISTERED:
     
    223219
    224220# The ID function
    225 ID = _xpcom.ID
     221ID = _xpcom.IID
    226222
    227223# A helper to cleanup our namespace as xpcom shuts down.
  • trunk/src/libs/xpcom18a4/python/file.py

    r59769 r59795  
    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

    r59772 r59795  
    22
    33"""
    4 Copyright (C) 2009-2016 Oracle Corporation
     4Copyright (C) 2009-2013 Oracle Corporation
    55
    66This file is part of VirtualBox Open Source Edition (OSE), as
     
    1414
    1515import os,sys
    16 from distutils.version import StrictVersion
    1716
    18 versions = ["2.6", "2.7", "3.1", "3.2", "3.3", "3.4", "3.5"]
     17versions = ["2.3", "2.4", "2.5", "2.6", "2.7",]
    1918prefixes = ["/usr", "/usr/local", "/opt", "/opt/local"]
    2019known = {}
     
    4241
    4342def print_vars(vers, known, sep, bitness_magic):
    44     print("VBOX_PYTHON%s_INC=%s%s" %(vers, known[0], sep))
     43    print "VBOX_PYTHON%s_INC=%s%s" %(vers, known[0], sep)
    4544    if bitness_magic > 0:
    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))
     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)
    4847    else:
    49         print("VBOX_PYTHON%s_LIB=%s%s" %(vers, known[1], sep))
     48        print "VBOX_PYTHON%s_LIB=%s%s" %(vers, known[1], sep)
    5049
    5150
     
    9291
    9392    for v in versions:
    94         if StrictVersion(v) < StrictVersion('2.6'):
    95             continue
    9693        for p in prefixes:
    9794            c = checkPair(p, v, dllpre, dllsuff, bitness_magic)
     
    9996                known[v] = c
    10097                break
    101     keys = list(known.keys())
     98    keys = known.keys()
    10299    # we want default to be the lowest versioned Python
    103100    keys.sort()
  • trunk/src/libs/xpcom18a4/python/primitives.py

    r59769 r59795  
    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

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

    r59769 r59795  
    3838import xpcom
    3939from xpcom import components, logger
    40 from . import module
    41 import glob
    42 import os
     40
     41import module
     42
     43import glob, os, types
     44
    4345from xpcom.client import Component
    4446
     
    5557    # For now, just run over all classes looking for likely candidates.
    5658    comps = []
    57     for name, object in list(py_module.__dict__.items()):
     59    for name, object in py_module.__dict__.items():
    5860        try:
    59             if (type(object) == type or issubclass(object, object)) and \
     61            if (type(object) == types.ClassType or issubclass(object, object)) and \
    6062               _has_good_attr(object, "_com_interfaces_") and \
    6163               _has_good_attr(object, "_reg_clsid_") and \
     
    146148                    self.autoRegisterComponent(when, entry)
    147149                # Handle some common user errors
    148                 except xpcom.COMException as details:
     150                except xpcom.COMException, details:
    149151                    from xpcom import nsError
    150152                    # If the interface name does not exist, suppress the traceback
     
    154156                    else:
    155157                        logger.exception("Registration of '%s' failed!", entry.leafName)
    156                 except SyntaxError as details:
     158                except SyntaxError, details:
    157159                    # Syntax error in source file - no useful traceback here either.
    158160                    logger.error("Registration of '%s' failed\n %s",
     
    224226
    225227def MakePythonComponentLoaderModule(serviceManager, nsIFile):
    226     from . import module
     228    import module
    227229    return module.Module( [PythonComponentLoader] )
  • trunk/src/libs/xpcom18a4/python/server/module.py

    r59769 r59795  
    3939from xpcom import nsError
    4040
    41 from . import factory
     41import factory
    4242
    4343import types
     
    6666        # void function.
    6767        fname = os.path.basename(location.path)
    68         for klass in list(self.components.values()):
     68        for klass in 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 list(self.components.values()):
     87        for klass in 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

    r59769 r59795  
    4343import types
    4444import logging
    45 import sys
    4645
    4746
     
    6261_supports_primitives_map_ = {} # Filled on first use.
    6362
    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
     63_interface_sequence_types_ = types.TupleType, types.ListType
     64_string_types_ = types.StringType, types.UnicodeType
    6965XPTI_GetInterfaceInfoManager = _xpcom.XPTI_GetInterfaceInfoManager
    7066
     
    146142        self._iid_ = iid
    147143        if ni is None:
    148             raise ValueError("The object '%r' can not be used as a COM object" % (instance,))
     144            raise ValueError, "The object '%r' can not be used as a COM object" % (instance,)
    149145        # This is really only a check for the user
    150146        if __debug__:
     
    290286            if logger.isEnabledFor(logging.DEBUG):
    291287                try:
    292                     raise exc_info[0](exc_info[1]).with_traceback(exc_info[2])
     288                    raise exc_info[0], exc_info[1], exc_info[2]
    293289                except:
    294290                    logger.debug("'%s' raised COM Exception %s",
     
    298294        # As above, trick the logging module to handle Python 2.3
    299295        try:
    300             raise exc_info[0](exc_info[1]).with_traceback(exc_info[2])
     296            raise exc_info[0], exc_info[1], exc_info[2]
    301297        except:
    302298            logger.exception("Unhandled exception calling '%s'", func_name)
     
    335331_supports_primitives_data_ = [
    336332    ("nsISupportsCString", "__str__", str),
    337     ("nsISupportsString", "__unicode__", str),
    338     ("nsISupportsPRUint64", "__long__", int),
    339     ("nsISupportsPRInt64", "__long__", int),
     333    ("nsISupportsString", "__unicode__", unicode),
     334    ("nsISupportsPRUint64", "__long__", long),
     335    ("nsISupportsPRInt64", "__long__", long),
    340336    ("nsISupportsPRUint32", "__int__", int),
    341337    ("nsISupportsPRInt32", "__int__", int),
  • trunk/src/libs/xpcom18a4/python/src/ErrorUtils.cpp

    r59769 r59795  
    111111        c += "('%s', ";
    112112        // Pull a trick to ensure a valid string - use Python repr!
    113 #if PY_MAJOR_VERSION <= 2
    114113        PyObject *obMessage = PyString_FromString(pszMessageText);
    115 #else
    116         PyObject *obMessage = PyUnicode_FromString(pszMessageText);
    117 #endif
    118114        if (obMessage) {
    119115                PyObject *repr = PyObject_Repr(obMessage);
    120116                if (repr) {
    121 #if PY_MAJOR_VERSION <= 2
    122117                        c += PyString_AsString(repr);
    123 #else
    124                         c += PyUnicode_AsUTF8(repr);
    125 #endif
    126118                        Py_DECREF(repr);
    127119                }
     
    201193        PyObject *temp = PyObject_Str(exc_typ);
    202194        if (temp) {
    203 #if PY_MAJOR_VERSION <= 2
    204195                streamout += PyString_AsString(temp);
    205 #else
    206                 streamout += PyUnicode_AsUTF8(temp);
    207 #endif
    208196                Py_DECREF(temp);
    209197        } else
     
    213201                temp = PyObject_Str(exc_val);
    214202                if (temp) {
    215 #if PY_MAJOR_VERSION <= 2
    216203                        streamout += PyString_AsString(temp);
    217 #else
    218                         streamout += PyUnicode_AsUTF8(temp);
    219 #endif
    220204                        Py_DECREF(temp);
    221205                } else
     
    371355        PyObject *obResult = NULL;
    372356
    373 #if PY_MAJOR_VERSION <= 2
    374357        /* Import the modules we need - cStringIO and traceback */
    375358        modStringIO = PyImport_ImportModule("cStringIO");
     
    387370        if (obStringIO==NULL)
    388371                TRACEBACK_FETCH_ERROR("cStringIO.StringIO() failed\n");
    389 #else
    390         /* Import the modules we need - io and traceback */
    391         modStringIO = PyImport_ImportModule("io");
    392         if (modStringIO==NULL)
    393                 TRACEBACK_FETCH_ERROR("cant import io\n");
    394 
    395         modTB = PyImport_ImportModule("traceback");
    396         if (modTB==NULL)
    397                 TRACEBACK_FETCH_ERROR("cant import traceback\n");
    398         /* Construct a StringIO object */
    399         obFuncStringIO = PyObject_GetAttrString(modStringIO, "StringIO");
    400         if (obFuncStringIO==NULL)
    401                 TRACEBACK_FETCH_ERROR("cant find io.StringIO\n");
    402         obStringIO = PyObject_CallObject(obFuncStringIO, NULL);
    403         if (obStringIO==NULL)
    404                 TRACEBACK_FETCH_ERROR("io.StringIO() failed\n");
    405 #endif
    406372        /* Get the traceback.print_exception function, and call it. */
    407373        obFuncTB = PyObject_GetAttrString(modTB, "print_tb");
     
    430396
    431397        /* And it should be a string all ready to go - duplicate it. */
    432 #if PY_MAJOR_VERSION <= 2
    433398        if (!PyString_Check(obResult))
    434 #else
    435         if (!PyUnicode_Check(obResult))
    436 #endif
    437399                        TRACEBACK_FETCH_ERROR("getvalue() did not return a string\n");
    438400
    439401        { // a temp scope so I can use temp locals.
    440 #if PY_MAJOR_VERSION <= 2
    441402        char *tempResult = PyString_AsString(obResult);
    442 #else
    443         char *tempResult = PyUnicode_AsUTF8(obResult);
    444 #endif
    445403        result = (char *)PyMem_Malloc(strlen(tempResult)+1);
    446404        if (result==NULL)
  • trunk/src/libs/xpcom18a4/python/src/PyGBase.cpp

    r59769 r59795  
    6767PRBool CheckDefaultGateway(PyObject *real_inst, REFNSIID iid, nsISupports **ret_gateway);
    6868
    69 /*static*/ nsresult
     69/*static*/ nsresult 
    7070PyG_Base::CreateNew(PyObject *pPyInstance, const nsIID &iid, void **ppResult)
    7171{
     
    115115        }
    116116        else
    117 #if PY_MAJOR_VERSION <= 2
    118117                szRepr = PyString_AsString(r);
    119 #else
    120                 szRepr = PyUnicode_AsUTF8(r);
    121 #endif
    122118        if (szRepr==NULL) szRepr = "";
    123119        int reprOffset = *szRepr=='<' ? 1 : 0;
     
    189185        if (iid.Equals(NS_GET_IID(nsISupportsWeakReference)))
    190186                return (nsISupportsWeakReference *)this;
    191         if (iid.Equals(NS_GET_IID(nsIInternalPython)))
     187        if (iid.Equals(NS_GET_IID(nsIInternalPython))) 
    192188                return (nsISupports *)(nsIInternalPython *)this;
    193189        return NULL;
     
    196192// Call back into Python, passing a Python instance, and get back
    197193// an interface object that wraps the instance.
    198 /*static*/ PRBool
     194/*static*/ PRBool 
    199195PyG_Base::AutoWrapPythonInstance(PyObject *ob, const nsIID &iid, nsISupports **ppret)
    200196{
     
    249245// the object to actually use as the gateway parameter for this interface.
    250246// For example, it is expected that the policy will wrap the interface
    251 // object in one of the xpcom.client.Interface objects, allowing
     247// object in one of the xpcom.client.Interface objects, allowing 
    252248// natural usage of the interface from Python clients.
    253249// Note that piid will usually be NULL - this is because the runtime
     
    260256// so at least the user can simply QI the object.
    261257PyObject *
    262 PyG_Base::MakeInterfaceParam(nsISupports *pis,
    263                              const nsIID *piid,
     258PyG_Base::MakeInterfaceParam(nsISupports *pis, 
     259                             const nsIID *piid, 
    264260                             int methodIndex /* = -1 */,
    265                              const XPTParamDescriptor *d /* = NULL */,
     261                             const XPTParamDescriptor *d /* = NULL */, 
    266262                             int paramIndex /* = -1 */)
    267263{
     
    306302                goto done;
    307303
    308         result = PyObject_CallMethod(m_pPyObject,
     304        result = PyObject_CallMethod(m_pPyObject, 
    309305                                       (char*)"_MakeInterfaceParam_",
    310306                                       (char*)"OOiOi",
     
    355351                return NS_OK;
    356352        }
    357         // If we have a "base object", then we need to delegate _every_ remaining
     353        // If we have a "base object", then we need to delegate _every_ remaining 
    358354        // QI to it.
    359355        if (m_pBaseObject != NULL)
     
    378374
    379375                PyObject *result = PyObject_CallMethod(m_pPyObject, (char*)"_QueryInterface_",
    380                                                                     (char*)"OO",
     376                                                                    (char*)"OO", 
    381377                                                                    this_interface_ob, ob);
    382378                Py_DECREF(ob);
     
    466462        if (PyErr_Occurred()) {
    467463                // The error handling - fairly involved, but worth it as
    468                 // good error reporting is critical for users to know WTF
     464                // good error reporting is critical for users to know WTF 
    469465                // is going on - especially with TypeErrors etc in their
    470466                // return values (ie, after the Python code has successfully
    471467                // exited, but we encountered errors unpacking their
    472                 // result values for the COM caller - there is literally no
     468                // result values for the COM caller - there is literally no 
    473469                // way to catch these exceptions from Python code, as their
    474470                // is no Python function directly on the call-stack)
     
    485481                PyErr_Fetch(&exc_typ, &exc_val, &exc_tb);
    486482
    487                 PyObject *err_result = PyObject_CallMethod(m_pPyObject,
     483                PyObject *err_result = PyObject_CallMethod(m_pPyObject, 
    488484                                               (char*)"_GatewayException_",
    489485                                               (char*)"z(OOO)",
     
    645641                ob_ret = PyObject_GetAttrString(real_ob, (char *)szPropertyName);
    646642                if (ob_ret==NULL) {
    647                         PyErr_Format(PyExc_AttributeError,
    648                                      "The object does not have a 'get_%s' function, or a '%s attribute.",
     643                        PyErr_Format(PyExc_AttributeError, 
     644                                     "The object does not have a 'get_%s' function, or a '%s attribute.", 
    649645                                     szPropertyName, szPropertyName);
    650646                } else {
     
    699695                        ret = NS_OK;
    700696                else {
    701                         PyErr_Format(PyExc_AttributeError,
    702                                      "The object does not have a 'set_%s' function, or a '%s attribute.",
     697                        PyErr_Format(PyExc_AttributeError, 
     698                                     "The object does not have a 'set_%s' function, or a '%s attribute.", 
    703699                                     szPropertyName, szPropertyName);
    704700                }
     
    741737  first thing we do is see if it has been auto-wrapped before.
    742738
    743   If not, we create a new wrapper, then make a COM weak reference
     739  If not, we create a new wrapper, then make a COM weak reference 
    744740  to that wrapper, and store it directly back into the instance
    745741  we are auto-wrapping!  The use of a weak-reference prevents
     
    765761                PRBool ok = PR_TRUE;
    766762                nsCOMPtr<nsIWeakReference> pWeakRef;
    767                 ok = NS_SUCCEEDED(Py_nsISupports::InterfaceFromPyObject(ob_existing_weak,
    768                                                        NS_GET_IID(nsIWeakReference),
     763                ok = NS_SUCCEEDED(Py_nsISupports::InterfaceFromPyObject(ob_existing_weak, 
     764                                                       NS_GET_IID(nsIWeakReference), 
    769765                                                       getter_AddRefs(pWeakRef),
    770766                                                       PR_FALSE));
     
    795791                PRBool ok = PR_TRUE;
    796792                nsCOMPtr<nsIWeakReference> pWeakRef;
    797                 ok = NS_SUCCEEDED(Py_nsISupports::InterfaceFromPyObject(ob_existing_weak,
    798                                                        NS_GET_IID(nsIWeakReference),
    799                                                        getter_AddRefs(pWeakRef),
     793                ok = NS_SUCCEEDED(Py_nsISupports::InterfaceFromPyObject(ob_existing_weak, 
     794                                                       NS_GET_IID(nsIWeakReference), 
     795                                                       getter_AddRefs(pWeakRef), 
    800796                                                       PR_FALSE));
    801797                Py_DECREF(ob_existing_weak);
     
    831827                        swr->GetWeakReference( getter_AddRefs(pWeakReference) );
    832828                        if (pWeakReference) {
    833                                 PyObject *ob_new_weak = Py_nsISupports::PyObjectFromInterface(pWeakReference,
     829                                PyObject *ob_new_weak = Py_nsISupports::PyObjectFromInterface(pWeakReference, 
    834830                                                                                   NS_GET_IID(nsIWeakReference),
    835831                                                                                   PR_FALSE ); /* bMakeNicePyObject */
  • trunk/src/libs/xpcom18a4/python/src/PyIClassInfo.cpp

    r59769 r59795  
    107107{
    108108        if (v)
    109 #if PY_MAJOR_VERSION <= 2
    110109                return PyString_FromString(v);
    111 #else
    112                 return PyUnicode_FromString(v);
    113 #endif
    114110        Py_INCREF(Py_None);
    115111        return Py_None;
     
    171167}
    172168
    173 struct PyMethodDef
     169struct PyMethodDef 
    174170PyMethods_IClassInfo[] =
    175171{
  • trunk/src/libs/xpcom18a4/python/src/PyIComponentManagerObsolete.cpp

    r59769 r59795  
    133133                return PyXPCOM_BuildPyException(r);
    134134
    135 #if PY_MAJOR_VERSION <= 2
    136135        PyObject *ob_pid = PyString_FromString(ret_pid);
    137136        PyObject *ob_class = PyString_FromString(ret_class);
    138 #else
    139         PyObject *ob_pid = PyUnicode_FromString(ret_pid);
    140         PyObject *ob_class = PyUnicode_FromString(ret_class);
    141 #endif
    142137        PyObject *ret = Py_BuildValue("OO", ob_pid, ob_class);
    143138        nsMemory::Free(ret_pid);
     
    188183}
    189184
    190 struct PyMethodDef
     185struct PyMethodDef 
    191186PyMethods_IComponentManagerObsolete[] =
    192187{
  • trunk/src/libs/xpcom18a4/python/src/PyIID.cpp

    r59769 r59795  
    6060        PyObject *obBuf;
    6161        if ( PyArg_ParseTuple(args, "O", &obBuf)) {
    62 #if PY_MAJOR_VERSION <= 2
    6362                if (PyBuffer_Check(obBuf)) {
    6463                        PyBufferProcs *pb = NULL;
     
    6665                        void *buf = NULL;
    6766                        int size = (*pb->bf_getreadbuffer)(obBuf, 0, &buf);
    68 #else
    69                 if (PyObject_CheckBuffer(obBuf)) {
    70                         void *buf = NULL;
    71             Py_buffer view;
    72             if (PyObject_GetBuffer(obBuf, &view, PyBUF_CONTIG_RO) != 0)
    73             {
    74                 PyErr_Format(PyExc_ValueError, "Could not get contiguous buffer from object");
    75                 return NULL;
    76             }
    77             Py_ssize_t size = view.len;
    78             buf = view.buf;
    79 #endif
    8067                        if (size != sizeof(nsIID) || buf==NULL) {
    81 #if PY_MAJOR_VERSION >= 3
    82                 PyBuffer_Release(&view);
    83 #endif
    8468#ifdef VBOX
    85                 PyErr_Format(PyExc_ValueError, "A buffer object to be converted to an IID must be exactly %d bytes long", (int)sizeof(nsIID));
     69                                PyErr_Format(PyExc_ValueError, "A buffer object to be converted to an IID must be exactly %d bytes long", (int)sizeof(nsIID));
    8670#else
    8771                                PyErr_Format(PyExc_ValueError, "A buffer object to be converted to an IID must be exactly %d bytes long", sizeof(nsIID));
     
    10185                                ptr += sizeof(PRUint8);
    10286                        }
    103 #if PY_MAJOR_VERSION >= 3
    104             PyBuffer_Release(&view);
    105 #endif
    10687                        return new Py_nsIID(iid);
    10788                }
     
    126107                return PR_FALSE;
    127108        }
    128 #if PY_MAJOR_VERSION <= 2
    129109        if (PyString_Check(ob)) {
    130110                ok = iid.Parse(PyString_AsString(ob));
    131 #else
    132         if (PyUnicode_Check(ob)) {
    133                 ok = iid.Parse(PyUnicode_AsUTF8(ob));
    134 #endif
    135111                if (!ok) {
    136112                        PyXPCOM_BuildPyException(NS_ERROR_ILLEGAL_VALUE);
     
    168144PyTypeObject Py_nsIID::type =
    169145{
    170         PyVarObject_HEAD_INIT(&PyType_Type, 0)
     146        PyObject_HEAD_INIT(&PyType_Type)
     147        0,
    171148        "IID",
    172149        sizeof(Py_nsIID),
     
    176153        PyTypeMethod_getattr,                           /* tp_getattr */
    177154        0,                                              /* tp_setattr */
    178 #if PY_MAJOR_VERSION <= 2
    179155        PyTypeMethod_compare,                           /* tp_compare */
    180 #else
    181         0,                                              /* reserved */
    182 #endif
    183156        PyTypeMethod_repr,                              /* tp_repr */
    184157        0,                                              /* tp_as_number */
     
    188161        0,                                              /* tp_call */
    189162        PyTypeMethod_str,                               /* tp_str */
    190         0,                                              /* tp_getattro */
    191         0,                                              /* tp_setattro */
    192         0,                                              /* tp_as_buffer */
    193         0,                                              /* tp_flags */
    194         0,                                              /* tp_doc */
    195         0,                                              /* tp_traverse */
    196         0,                                              /* tp_clear */
    197         PyTypeMethod_richcompare,                       /* tp_richcompare */
    198         0,                                              /* tp_weaklistoffset */
    199         0,                                              /* tp_iter */
    200         0,                                              /* tp_iternext */
    201         0,                                              /* tp_methods */
    202         0,                                              /* tp_members */
    203         0,                                              /* tp_getset */
    204         0,                                              /* tp_base */
    205163};
    206164
     
    226184                PyObject *ret;
    227185                if (iid_repr != nsnull) {
    228 #if PY_MAJOR_VERSION <= 2
    229186                        ret = PyString_FromString(iid_repr);
    230 #else
    231                         ret = PyUnicode_FromString(iid_repr);
    232 #endif
    233187                        nsMemory::Free(iid_repr);
    234188                } else
    235 #if PY_MAJOR_VERSION <= 2
    236189                        ret = PyString_FromString("<cant get IID info!>");
    237 #else
    238                         ret = PyUnicode_FromString("<cant get IID info!>");
    239 #endif
    240190                return ret;
    241191        }
     
    243193}
    244194
    245 #if PY_MAJOR_VERSION <= 2
    246195/* static */ int
    247196Py_nsIID::PyTypeMethod_compare(PyObject *self, PyObject *other)
     
    252201        return rc == 0 ? 0 : (rc < 0 ? -1 : 1);
    253202}
    254 #endif
    255 
    256 /* static */ PyObject *
    257 Py_nsIID::PyTypeMethod_richcompare(PyObject *self, PyObject *other, int op)
    258 {
    259     PyObject *result = NULL;
    260         Py_nsIID *s_iid = (Py_nsIID *)self;
    261         Py_nsIID *o_iid = (Py_nsIID *)other;
    262         int rc = memcmp(&s_iid->m_iid, &o_iid->m_iid, sizeof(s_iid->m_iid));
    263     switch (op)
    264     {
    265         case Py_LT:
    266             result = rc < 0 ? Py_True : Py_False;
    267             break;
    268         case Py_LE:
    269             result = rc <= 0 ? Py_True : Py_False;
    270             break;
    271         case Py_EQ:
    272             result = rc == 0 ? Py_True : Py_False;
    273             break;
    274         case Py_NE:
    275             result = rc != 0 ? Py_True : Py_False;
    276             break;
    277         case Py_GT:
    278             result = rc > 0 ? Py_True : Py_False;
    279             break;
    280         case Py_GE:
    281             result = rc >= 0 ? Py_True : Py_False;
    282             break;
    283     }
    284     Py_XINCREF(result);
    285     return result;
    286 }
    287203
    288204/* static */ PyObject *
     
    293209        char *sziid = s_iid->m_iid.ToString();
    294210#ifdef VBOX
    295         snprintf(buf, sizeof(buf), "_xpcom.ID('%s')", sziid);
     211        snprintf(buf, sizeof(buf), "_xpcom.IID('%s')", sziid);
    296212#else
    297213        sprintf(buf, "_xpcom.IID('%s')", sziid);
    298214#endif
    299215        nsMemory::Free(sziid);
    300 #if PY_MAJOR_VERSION <= 2
    301216        return PyString_FromString(buf);
    302 #else
    303         return PyUnicode_FromString(buf);
    304 #endif
    305217}
    306218
     
    310222        Py_nsIID *s_iid = (Py_nsIID *)self;
    311223        char *sziid = s_iid->m_iid.ToString();
    312 #if PY_MAJOR_VERSION <= 2
    313224        PyObject *ret = PyString_FromString(sziid);
    314 #else
    315         PyObject *ret = PyUnicode_FromString(sziid);
    316 #endif
    317225        nsMemory::Free(sziid);
    318226        return ret;
  • trunk/src/libs/xpcom18a4/python/src/PyIInputStream.cpp

    r59769 r59795  
    109109        }
    110110        if (n==0) { // mozilla will assert if we alloc zero bytes.
    111 #if PY_MAJOR_VERSION <= 2
    112111                return PyBuffer_New(0);
    113 #else
    114                 return PyBytes_FromString("");
    115 #endif
    116112        }
    117113        char *buf = (char *)nsMemory::Alloc(n);
     
    127123        PyObject *rc = NULL;
    128124        if ( NS_SUCCEEDED(r) ) {
    129 #if PY_MAJOR_VERSION <= 2
    130125                rc = PyBuffer_New(nread);
    131126                if (rc != NULL) {
     
    151146                        memcpy(ob_buf, buf, nread);
    152147                }
    153 #else
    154         rc = PyBytes_FromStringAndSize(buf, nread);
    155 #endif
    156148        } else
    157149                PyXPCOM_BuildPyException(r);
  • trunk/src/libs/xpcom18a4/python/src/PyIInterfaceInfo.cpp

    r59769 r59795  
    7575        if ( NS_FAILED(r) )
    7676                return PyXPCOM_BuildPyException(r);
    77 #if PY_MAJOR_VERSION <= 2
    7877        PyObject *ret = PyString_FromString(name);
    79 #else
    80         PyObject *ret = PyUnicode_FromString(name);
    81 #endif
    8278        nsMemory::Free(name);
    8379        return ret;
     
    397393}
    398394
    399 struct PyMethodDef
     395struct PyMethodDef 
    400396PyMethods_IInterfaceInfo[] =
    401397{
  • trunk/src/libs/xpcom18a4/python/src/PyIInterfaceInfoManager.cpp

    r59769 r59795  
    135135                return PyXPCOM_BuildPyException(r);
    136136
    137 #if PY_MAJOR_VERSION <= 2
    138137        PyObject *ret = PyString_FromString(ret_name);
    139 #else
    140         PyObject *ret = PyUnicode_FromString(ret_name);
    141 #endif
    142138        nsMemory::Free(ret_name);
    143139        return ret;
     
    190186// void autoRegisterInterfaces();
    191187
    192 PyMethodDef
     188PyMethodDef 
    193189PyMethods_IInterfaceInfoManager[] =
    194190{
  • trunk/src/libs/xpcom18a4/python/src/PyISupports.cpp

    r59769 r59795  
    218218        }
    219219        PyXPCOM_TypeObject *this_type = (PyXPCOM_TypeObject *)ob_type;
    220 #if PY_MAJOR_VERSION <= 2
    221220        return Py_FindMethodInChain(&this_type->chain, this, (char *)name);
    222 #else
    223     PyMethodChain *chain = &this_type->chain;
    224     if (name[0] == '_' && name[1] == '_')
    225     {
    226         if (!strcmp(name, "__doc__"))
    227         {
    228             const char *doc = ob_type->tp_doc;
    229             if (doc)
    230 #if PY_MAJOR_VERSION <= 2
    231                 return PyString_FromString(doc);
    232 #else
    233                 return PyUnicode_FromString(doc);
    234 #endif
    235         }
    236     }
    237     while (chain)
    238     {
    239         PyMethodDef *ml = chain->methods;
    240         for (; ml->ml_name; ml++)
    241         {
    242             if (!strcmp(name, ml->ml_name))
    243                 return PyCFunction_New(ml, this);
    244         }
    245         chain = chain->link;
    246     }
    247     PyErr_SetString(PyExc_AttributeError, name);
    248     return NULL;
    249 #endif
    250221}
    251222
  • trunk/src/libs/xpcom18a4/python/src/PyIVariant.cpp

    r59769 r59795  
    6262}
    6363static PyObject *MyChar( char c) {
    64 #if PY_MAJOR_VERSION <= 2
    6564        return PyString_FromStringAndSize(&c, 1);
    66 #else
    67         return PyUnicode_FromStringAndSize(&c, 1);
    68 #endif
    6965}
    7066static PyObject *MyUChar( PRUnichar c) {
     
    127123GET_SIMPLE(nsIID, GetAsID, Py_nsIID::PyObjectFromIID)
    128124
    129 #if PY_MAJOR_VERSION <= 2
    130125GET_ALLOCATED(char *, GetAsString, PyString_FromString, nsMemory::Free)
    131 #else
    132 GET_ALLOCATED(char *, GetAsString, PyUnicode_FromString, nsMemory::Free)
    133 #endif
    134126GET_ALLOCATED(PRUnichar *, GetAsWString, MyUnicode, nsMemory::Free)
    135 #if PY_MAJOR_VERSION <= 2
    136127GET_ALLOCATED_SIZE(char *, GetAsStringWithSize, PyString_FromStringAndSize, nsMemory::Free)
    137 #else
    138 GET_ALLOCATED_SIZE(char *, GetAsStringWithSize, PyUnicode_FromStringAndSize, nsMemory::Free)
    139 #endif
    140128GET_ALLOCATED_SIZE(PRUnichar *, GetAsWStringWithSize, PyObject_FromNSString, nsMemory::Free)
    141129
     
    178166}
    179167
    180 struct PyMethodDef
     168struct PyMethodDef 
    181169PyMethods_IVariant[] =
    182170{
  • trunk/src/libs/xpcom18a4/python/src/PyXPCOM.h

    r59769 r59795  
    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
    146 typedef struct PyMethodChain
    147 {
    148     PyMethodDef *methods;
    149     struct PyMethodChain *link;
    150 } PyMethodChain;
    151 # endif
    152 
    153135#endif /* VBOX_PYXPCOM */
    154136
     
    286268        static int Py_setattr(PyObject *op, char *name, PyObject *v);
    287269        static int Py_cmp(PyObject *ob1, PyObject *ob2);
    288         static PyObject *Py_richcmp(PyObject *ob1, PyObject *ob2, int op);
    289270        static long Py_hash(PyObject *self);
    290271};
     
    438419        /* Python support */
    439420        static PyObject *PyTypeMethod_getattr(PyObject *self, char *name);
    440 #if PY_MAJOR_VERSION <= 2
    441421        static int PyTypeMethod_compare(PyObject *self, PyObject *ob);
    442 #endif
    443         static PyObject *PyTypeMethod_richcompare(PyObject *self, PyObject *ob, int op);
    444422        static PyObject *PyTypeMethod_repr(PyObject *self);
    445423        static long PyTypeMethod_hash(PyObject *self);
  • trunk/src/libs/xpcom18a4/python/src/Pyxpt_info.cpp

    r59769 r59795  
    5555        }
    5656    // build an object using the same format as a TypeDescriptor.
    57         return Py_BuildValue("bzzz",
     57        return Py_BuildValue("bzzz", 
    5858                d->flags,
    5959                NULL, NULL, NULL);
     
    6666                return Py_None;
    6767        }
    68         return Py_BuildValue("bbbh",
     68        return Py_BuildValue("bbbh", 
    6969                d->prefix.flags,
    7070                d->argnum,
     
    150150                        break;
    151151                case TD_CHAR:
    152 #if PY_MAJOR_VERSION <= 2
    153152                        v = PyString_FromStringAndSize(&c->value.ch, 1);
    154 #else
    155                         v = PyUnicode_FromStringAndSize(&c->value.ch, 1);
    156 #endif
    157153                        break;
    158154                case TD_WCHAR:
    159155                        v = PyObject_FromNSString((PRUnichar *)&c->value.wch, 1);
    160156                        break;
    161         //    TD_VOID              = 13,
     157        //    TD_VOID              = 13, 
    162158                case TD_PNSIID:
    163159                        v = Py_nsIID::PyObjectFromIID(*c->value.iid);
     
    165161        //    TD_DOMSTRING         = 15,
    166162                case TD_PSTRING:
    167 #if PY_MAJOR_VERSION <= 2
    168163                        v = PyString_FromString(c->value.str);
    169 #else
    170                         v = PyUnicode_FromString(c->value.str);
    171 #endif
    172164                        break;
    173165                case TD_PWSTRING:
     
    183175        //    TD_ASTRING           = 25
    184176                default:
    185 #if PY_MAJOR_VERSION <= 2
    186177                        v = PyString_FromString("Unknown type code!!");
    187 #else
    188                         v = PyUnicode_FromString("Unknown type code!!");
    189 #endif
    190178                        break;
    191179
  • trunk/src/libs/xpcom18a4/python/src/TypeObject.cpp

    r59769 r59795  
    5353
    5454static PyTypeObject PyInterfaceType_Type = {
    55         PyVarObject_HEAD_INIT(&PyType_Type, 0)
     55        PyObject_HEAD_INIT(&PyType_Type)
     56        0,                      /* Number of items for varobject */
    5657        "interface-type",                       /* Name of this type */
    5758        sizeof(PyTypeObject),   /* Basic object size */
     
    7980PyXPCOM_TypeObject::IsType(PyTypeObject *t)
    8081{
    81 #if PY_MAJOR_VERSION <= 2
    8282        return t->ob_type == &PyInterfaceType_Type;
    83 #else
    84         return Py_TYPE(t) == &PyInterfaceType_Type;
    85 #endif
    8683}
    8784
     
    125122}
    126123
    127 /*static*/PyObject *
    128 PyXPCOM_TypeObject::Py_richcmp(PyObject *self, PyObject *other, int op)
    129 {
    130     PyObject *result = NULL;
    131     int rc = Py_cmp(self, other);
    132     switch (op)
    133     {
    134         case Py_LT:
    135             result = rc < 0 ? Py_True : Py_False;
    136             break;
    137         case Py_LE:
    138             result = rc <= 0 ? Py_True : Py_False;
    139             break;
    140         case Py_EQ:
    141             result = rc == 0 ? Py_True : Py_False;
    142             break;
    143         case Py_NE:
    144             result = rc != 0 ? Py_True : Py_False;
    145             break;
    146         case Py_GT:
    147             result = rc > 0 ? Py_True : Py_False;
    148             break;
    149         case Py_GE:
    150             result = rc >= 0 ? Py_True : Py_False;
    151             break;
    152     }
    153     Py_XINCREF(result);
    154     return result;
    155 }
    156 
    157124// @pymethod int|Py_nsISupports|__hash__|Implement a hash-code for the XPCOM object using XPCOM identity rules.
    158125/*static*/long PyXPCOM_TypeObject::Py_hash(PyObject *self)
     
    185152        char buf[512];
    186153#ifdef VBOX
    187         snprintf(buf, sizeof(buf), "<XPCOM object (%s) at %p/%p>",
     154        snprintf(buf, sizeof(buf), "<XPCOM object (%s) at 0x%p/0x%p>",
    188155                iid_repr, (void *)self, (void *)pis->m_obj.get());
    189156#else
     
    192159#endif
    193160        nsMemory::Free(iid_repr);
    194 #if PY_MAJOR_VERSION <= 2
    195161        return PyString_FromString(buf);
    196 #else
    197         return PyUnicode_FromString(buf);
    198 #endif
    199162}
    200163
     
    210173        if (NS_SUCCEEDED(rv))
    211174                rv = ss->ToString(&val);
    212         } // end-scope
     175        } // end-scope 
    213176        Py_END_ALLOW_THREADS;
    214177        PyObject *ret;
     
    216179                ret = Py_repr(self);
    217180        else
    218 #if PY_MAJOR_VERSION <= 2
    219181                ret = PyString_FromString(val);
    220 #else
    221                 ret = PyUnicode_FromString(val);
    222 #endif
    223182        if (val) nsMemory::Free(val);
    224183        return ret;
     
    234193{
    235194        static const PyTypeObject type_template = {
    236                 PyVarObject_HEAD_INIT(&PyInterfaceType_Type, 0)
     195                PyObject_HEAD_INIT(&PyInterfaceType_Type)
     196                0,                                           /*ob_size*/
    237197                "XPCOMTypeTemplate",                         /*tp_name*/
    238                 sizeof(Py_nsISupports),                      /*tp_basicsize*/
     198                sizeof(Py_nsISupports),                 /*tp_basicsize*/
    239199                0,                                           /*tp_itemsize*/
    240200                Py_dealloc,                                  /* tp_dealloc */
     
    242202                Py_getattr,                                  /* tp_getattr */
    243203                Py_setattr,                                  /* tp_setattr */
    244 #if PY_MAJOR_VERSION <= 2
    245204                Py_cmp,                                      /* tp_compare */
    246 #else
    247                 0,                                           /* reserved */
    248 #endif
    249205                Py_repr,                                     /* tp_repr */
    250                 0,                                           /* tp_as_number*/
     206                0,                                           /* tp_as_number*/
    251207                0,                                           /* tp_as_sequence */
    252208                0,                                           /* tp_as_mapping */
     
    255211                Py_str,                                      /* tp_str */
    256212                0,                                           /* tp_getattro */
    257                 0,                                           /* tp_setattro */
     213                0,                                           /*tp_setattro */
    258214                0,                                           /* tp_as_buffer */
    259215                0,                                           /* tp_flags */
     
    261217                0,                                           /* tp_traverse */
    262218                0,                                           /* tp_clear */
    263                 Py_richcmp,                                  /* tp_richcompare */
     219                0,                                           /* tp_richcompare */
    264220                0,                                           /* tp_weaklistoffset */
    265221                0,                                           /* tp_iter */
  • trunk/src/libs/xpcom18a4/python/src/VariantUtils.cpp

    r59769 r59795  
    8484        PRUint32 size;
    8585        PyObject *s;
    86         void *src;
    8786        PRUnichar *dest;
    8887
     
    9089        if (!s)
    9190                return -1;
    92         // Drop the UTF-16 byte order mark at the beginning of
    93         // the string.  (See the docs on PyUnicode_AsUTF16String.)
    94         // Some Mozilla libraries don't like the mark.
    95 #if PY_MAJOR_VERSION <= 2
    9691        size = (PyString_GET_SIZE(s) - 2) / sizeof(PRUnichar);
    97         src = PyString_AS_STRING(s) + 2;
    98 #else
    99     if (!PyBytes_Check(obj))
    100     {
    101         PyErr_SetString(PyExc_TypeError, "internal error in PyXPCOM, parameter must be a bytes object");
    102         return -1;
    103     }
    104     size = (PyBytes_GET_SIZE(obj) - 2) / sizeof(PRUnichar);
    105     src = PyBytes_AS_STRING(obj) + 2;
    106 #endif
    10792        dest = (PRUnichar *)nsMemory::Alloc(sizeof(PRUnichar) * (size + 1));
    10893        if (!dest) {
     
    11196                return -1;
    11297        }
    113         memcpy(dest, src, sizeof(PRUnichar) * size);
     98        // Drop the UTF-16 byte order mark at the beginning of
     99        // the string.  (See the docs on PyUnicode_AsUTF16String.)
     100        // Some Mozilla libraries don't like the mark.
     101        memcpy(dest, PyString_AS_STRING(s) + 2, sizeof(PRUnichar) * size);
    114102        Py_DECREF(s);
    115103        dest[size] = 0;
     
    128116        } else {
    129117                if (bAssumeUTF8) {
    130                         const nsPromiseFlatCString& temp = PromiseFlatCString(s);
    131                         ret = PyUnicode_DecodeUTF8(temp.get(), temp.Length(), NULL);
     118                        const nsPromiseFlatCString& temp = PromiseFlatCString(s);
     119                        ret = PyUnicode_DecodeUTF8(temp.get(), temp.Length(), NULL);
    132120                } else {
    133 #if PY_MAJOR_VERSION <= 2
    134121                        ret = PyString_FromStringAndSize(NULL, s.Length());
    135 #else
    136                         ret = PyUnicode_FromStringAndSize(NULL, s.Length());
    137 #endif
    138122                        if (!ret)
    139123                                return NULL;
    140124                        // Need "CopyAsciiTo"!?
    141125                        nsACString::const_iterator fromBegin, fromEnd;
    142 #if PY_MAJOR_VERSION <= 2
    143                         char* dest = (char *)PyString_AS_STRING(ret);
    144 #else
    145                         char* dest = (char *)PyUnicode_AsUTF8(ret);
    146 #endif
     126                        char* dest = PyString_AS_STRING(ret);
    147127                        copy_string(s.BeginReading(fromBegin), s.EndReading(fromEnd), dest);
    148128                }
     
    179159        PyObject *val_use = NULL;
    180160        PRBool ok = PR_TRUE;
    181 #if PY_MAJOR_VERSION <= 2
    182161        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    183162                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    186165        if (ok && (val_use = PyUnicode_FromObject(val))==NULL)
    187166                ok = PR_FALSE;
    188 #else
    189     if (!PyUnicode_Check(val)) {
    190         PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    191         ok = PR_FALSE;
    192     }
    193     val_use = val;
    194     Py_INCREF(val_use);
    195 #endif
    196167        if (ok) {
    197168                if (PyUnicode_GET_SIZE(val_use) == 0) {
     
    382353        // If it is NOT a string, we just fall through and allow the standard
    383354        // sequence unpack code process it (just slower!)
    384 #if PY_MAJOR_VERSION <= 2
    385355        if ( array_type == nsXPTType::T_U8 &&
    386356                (PyString_Check(sequence_ob) || PyUnicode_Check(sequence_ob))) {
    387 #else
    388         if ( array_type == nsXPTType::T_U8 && PyUnicode_Check(sequence_ob)) {
    389 #endif
    390357
    391358                PRBool release_seq;
    392359                if (PyUnicode_Check(sequence_ob)) {
    393360                        release_seq = PR_TRUE;
    394 #if PY_MAJOR_VERSION <= 2
    395361                        sequence_ob = PyObject_Str(sequence_ob);
    396 #else
    397                         sequence_ob = PyUnicode_AsUTF8String(sequence_ob);
    398 #endif
    399362                } else
    400363                        release_seq = PR_FALSE;
    401364                if (!sequence_ob) // presumably a memory error, or Unicode encoding error.
    402365                        return PR_FALSE;
    403 #if PY_MAJOR_VERSION <= 2
    404366                memcpy(pthis, PyString_AS_STRING(sequence_ob), sequence_size);
    405 #else
    406                 memcpy(pthis, PyUnicode_AsUTF8(sequence_ob), sequence_size);
    407 #endif
    408367                if (release_seq)
    409368                {
     
    464423                                break;
    465424                          case nsXPTType::T_CHAR:
    466 #if PY_MAJOR_VERSION <= 2
    467425                                if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    468426                                        PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    474432                                NS_ABORT_IF_FALSE(PyString_Check(val_use), "PyObject_Str didnt return a string object!");
    475433                                FILL_SIMPLE_POINTER( char, *PyString_AS_STRING(val_use) );
    476 #else
    477                                 if (!PyUnicode_Check(val)) {
    478                                         PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    479                                         BREAK_FALSE;
    480                                 }
    481                                 FILL_SIMPLE_POINTER( char, *PyUnicode_AsUTF8(val) );
    482 #endif
    483434                                break;
    484435
    485436                          case nsXPTType::T_WCHAR:
    486 #if PY_MAJOR_VERSION <= 2
    487437                                if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    488438                                        PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
    489439                                        BREAK_FALSE;
    490440                                }
    491 #else
    492                                 if (!PyUnicode_Check(val)) {
    493                                         PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    494                                         BREAK_FALSE;
    495                                 }
    496 #endif
    497441                                if ((val_use = PyUnicode_FromObject(val)) == NULL)
    498442                                        BREAK_FALSE;
     
    530474                                if (val == Py_None)
    531475                                        break; // Remains NULL.
    532 #if PY_MAJOR_VERSION <= 2
    533476                                if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    534477                                        PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    542485                                const char *sz = PyString_AS_STRING(val_use);
    543486                                int nch = PyString_GET_SIZE(val_use);
    544 #else
    545                                 if (!PyUnicode_Check(val)) {
    546                                         PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    547                                         BREAK_FALSE;
    548                                 }
    549                                 if ((val_use = PyUnicode_AsUTF8String(val))==NULL)
    550                                         BREAK_FALSE;
    551 
    552                                 const char *sz = PyBytes_AS_STRING(val_use);
    553                                 int nch = PyBytes_GET_SIZE(val_use);
    554 #endif
    555487
    556488                                *pp = (char *)nsMemory::Alloc(nch+1);
     
    570502                                if (val == Py_None)
    571503                                        break; // Remains NULL.
    572 #if PY_MAJOR_VERSION <= 2
    573504                                if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    574505                                        PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    578509                                        BREAK_FALSE;
    579510                                NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!");
    580 #else
    581                                 if (!PyUnicode_Check(val)) {
    582                                         PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    583                                         BREAK_FALSE;
    584                                 }
    585                                 val_use = val;
    586                 Py_INCREF(val_use);
    587 #endif
    588511                                if (PyUnicode_AsPRUnichar(val_use, pp, NULL) < 0)
    589512                                        BREAK_FALSE;
     
    626549        }
    627550        if (array_type == nsXPTType::T_U8)
    628 #if PY_MAJOR_VERSION <= 2
    629551                return PyString_FromStringAndSize( (char *)array_ptr, sequence_size );
    630 #else
    631                 return PyUnicode_FromStringAndSize( (char *)array_ptr, sequence_size );
    632 #endif
    633552
    634553        PRUint32 array_element_size = GetArrayElementSize(array_type);
     
    680599                                        val = Py_None;
    681600                                } else
    682 #if PY_MAJOR_VERSION <= 2
    683601                                        val = PyString_FromString(*pp);
    684 #else
    685                                         val = PyUnicode_FromString(*pp);
    686 #endif
    687602                                break;
    688603                                }
     
    717632                                sprintf(buf, "Unknown XPCOM array type flags (0x%x)", array_type);
    718633                                PyXPCOM_LogWarning("%s - returning a string object with this message!\n", buf);
    719 #if PY_MAJOR_VERSION <= 2
    720634                                val = PyString_FromString(buf);
    721 #else
    722                                 val = PyUnicode_FromString(buf);
    723 #endif
    724635                                break;
    725636                                }
     
    759670        if (PyFloat_Check(ob))
    760671                return nsIDataType::VTYPE_DOUBLE;
    761 #if PY_MAJOR_VERSION <= 2
    762672        if (PyString_Check(ob))
    763673                return nsIDataType::VTYPE_STRING_SIZE_IS;
    764 #endif
    765674        if (PyUnicode_Check(ob))
    766675                return nsIDataType::VTYPE_WSTRING_SIZE_IS;
     
    817726                        break;
    818727                case nsIDataType::VTYPE_STRING_SIZE_IS:
    819 #if PY_MAJOR_VERSION <= 2
    820728                        nr = v->SetAsStringWithSize(PyString_Size(ob), PyString_AsString(ob));
    821 #else
    822             Py_ssize_t cb;
    823             const char *psz;
    824             psz = PyUnicode_AsUTF8AndSize(ob, &cb);
    825                         nr = v->SetAsStringWithSize(cb, psz);
    826 #endif
    827729                        break;
    828730                case nsIDataType::VTYPE_WSTRING_SIZE_IS:
     
    13941296                        break;
    13951297                  case nsXPTType::T_CHAR:{
    1396 #if PY_MAJOR_VERSION <= 2
    13971298                        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    13981299                                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    14091310
    14101311                        ns_v.val.c = *PyString_AS_STRING(val_use);
    1411 #else
    1412                         if (!PyUnicode_Check(val)) {
    1413                                 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    1414                                 BREAK_FALSE;
    1415                         }
    1416                         if (PyUnicode_GET_SIZE(val) != 1) {
    1417                                 PyErr_SetString(PyExc_ValueError, "Must specify a one character string for a character");
    1418                                 BREAK_FALSE;
    1419                         }
    1420 
    1421                         ns_v.val.c = *PyUnicode_AS_UNICODE(val_use);
    1422 #endif
    14231312                        break;
    14241313                        }
    14251314
    14261315                  case nsXPTType::T_WCHAR: {
    1427 #if PY_MAJOR_VERSION <= 2
    14281316                        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    14291317                                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
    14301318                                BREAK_FALSE;
    14311319                        }
    1432 #else
    1433                         if (!PyUnicode_Check(val)) {
    1434                                 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    1435                                 BREAK_FALSE;
    1436                         }
    1437 #endif
    14381320                        if ((val_use = PyUnicode_FromObject(val))==NULL)
    14391321                                BREAK_FALSE;
    1440                         // Sanity check should PyUnicode_FromObject() ever loosen its semantics wrt Unicode!
     1322                        // Sanity check should PyObject_Str() ever loosen its semantics wrt Unicode!
    14411323                        NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a unicode object!");
    1442                         if (PyUnicode_GET_SIZE(val_use) != 1) {
     1324                        if (PyUnicode_GetSize(val_use) != 1) {
    14431325                                PyErr_SetString(PyExc_ValueError, "Must specify a one character string for a character");
    14441326                                BREAK_FALSE;
     
    14781360                                ns_v.val.p = new nsCString();
    14791361                        } else {
    1480 #if PY_MAJOR_VERSION <= 2
     1362                                // strings are assumed to already be UTF8 encoded.
    14811363                                if (PyString_Check(val)) {
    1482                     // strings are assumed to already be UTF8 encoded.
    14831364                                        val_use = val;
    14841365                                        Py_INCREF(val);
    1485                                 }
    1486                 else
    1487 #endif
    1488                 if (PyUnicode_Check(val)) {
    1489                     // Unicode objects are encoded by us.
     1366                                // Unicode objects are encoded by us.
     1367                                } else if (PyUnicode_Check(val)) {
    14901368                                        if (bIsUTF8)
    14911369                                                val_use = PyUnicode_AsUTF8String(val);
    14921370                                        else
    1493 #if PY_MAJOR_VERSION <= 2
    14941371                                                val_use = PyObject_Str(val);
    1495 #else
    1496                                                 val_use = PyUnicode_AsUTF8String(val);
    1497 #endif
    14981372                                } else {
    1499 #if PY_MAJOR_VERSION <= 2
    15001373                                        PyErr_SetString(PyExc_TypeError, "UTF8 parameters must be string or Unicode objects");
    1501 #else
    1502                                         PyErr_SetString(PyExc_TypeError, "UTF8 parameters must be unicode objects");
    1503 #endif
    15041374                                        BREAK_FALSE;
    15051375                                }
    15061376                                if (!val_use)
    15071377                                        BREAK_FALSE;
    1508 #if PY_MAJOR_VERSION <= 2
    15091378                                ns_v.val.p = new nsCString(PyString_AS_STRING(val_use),
    15101379                                                           PyString_GET_SIZE(val_use));
    1511 #else
    1512                                 ns_v.val.p = new nsCString(PyBytes_AS_STRING(val_use),
    1513                                                            PyBytes_GET_SIZE(val_use));
    1514 #endif
    15151380                        }
    15161381
     
    15281393                                break;
    15291394                        }
    1530 #if PY_MAJOR_VERSION <= 2
    15311395                        // If an "in" char *, and we have a PyString, then pass the
    15321396                        // pointer (hoping everyone else plays by the rules too.
    15331397                        if (!XPT_PD_IS_OUT(td.param_flags) && PyString_Check(val)) {
    1534                                 ns_v.val.p = (void *)PyString_AS_STRING(val);
     1398                                ns_v.val.p = PyString_AS_STRING(val);
    15351399                                break;
    15361400                        }
     
    15481412                        MAKE_VALUE_BUFFER(cb_this_buffer_pointer);
    15491413                        memcpy(this_buffer_pointer, PyString_AS_STRING(val_use), cb_this_buffer_pointer);
    1550 #else
    1551 
    1552                         if (!PyUnicode_Check(val)) {
    1553                                 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    1554                                 BREAK_FALSE;
    1555                         }
    1556                         if ((val_use = PyUnicode_AsUTF8String(val))==NULL)
    1557                                 BREAK_FALSE;
    1558 
    1559                         cb_this_buffer_pointer = PyBytes_GET_SIZE(val_use)+1;
    1560                         MAKE_VALUE_BUFFER(cb_this_buffer_pointer);
    1561                         memcpy(this_buffer_pointer, PyBytes_AS_STRING(val_use), cb_this_buffer_pointer);
    1562 #endif
    15631414                        ns_v.val.p = this_buffer_pointer;
    15641415                        break;
     
    15701421                                break;
    15711422                        }
    1572 #if PY_MAJOR_VERSION <= 2
    15731423                        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    15741424                                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    15781428                                BREAK_FALSE;
    15791429                        NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!");
    1580 #else
    1581                         if (!PyUnicode_Check(val)) {
    1582                                 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    1583                                 BREAK_FALSE;
    1584                         }
    1585             val_use = val;
    1586             Py_INCREF(val_use);
    1587 #endif
    15881430                        PRUnichar *sv;
    15891431                        PRUint32 nch;
     
    16421484                                break;
    16431485                        }
    1644 #if PY_MAJOR_VERSION <= 2
    16451486                        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    16461487                                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    16551496                        MAKE_VALUE_BUFFER(cb_this_buffer_pointer);
    16561497                        memcpy(this_buffer_pointer, PyString_AS_STRING(val_use), cb_this_buffer_pointer);
    1657 #else
    1658                         if (!PyUnicode_Check(val)) {
    1659                                 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    1660                                 BREAK_FALSE;
    1661                         }
    1662                         if ((val_use = PyUnicode_AsUTF8String(val))==NULL)
    1663                                 BREAK_FALSE;
    1664 
    1665                         cb_this_buffer_pointer = PyBytes_GET_SIZE(val_use);
    1666                         MAKE_VALUE_BUFFER(cb_this_buffer_pointer);
    1667                         memcpy(this_buffer_pointer, PyBytes_AS_STRING(val_use), cb_this_buffer_pointer);
    1668 #endif
    16691498                        ns_v.val.p = this_buffer_pointer;
    16701499                        rc = SetSizeIs(value_index, PR_TRUE, cb_this_buffer_pointer);
     
    16771506                                break;
    16781507                        }
    1679 #if PY_MAJOR_VERSION <= 2
    16801508                        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    16811509                                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    16861514                        // Sanity check should PyObject_Str() ever loosen its semantics wrt Unicode!
    16871515                        NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyObject_Unicode didnt return a unicode object!");
    1688 #else
    1689                         if (!PyUnicode_Check(val)) {
    1690                                 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    1691                                 BREAK_FALSE;
    1692                         }
    1693             val_use = val;
    1694             Py_INCREF(val_use);
    1695 #endif
    16961516                        PRUnichar *sv;
    16971517                        PRUint32 nch;
     
    18991719                break;
    19001720          case nsXPTType::T_CHAR:
    1901 #if PY_MAJOR_VERSION <= 2
    19021721                ret = PyString_FromStringAndSize( ((char *)ns_v.ptr), 1 );
    1903 #else
    1904                 ret = PyUnicode_FromStringAndSize( ((char *)ns_v.ptr), 1 );
    1905 #endif
    19061722                break;
    19071723
     
    19311747                        Py_INCREF(Py_None);
    19321748                } else
    1933 #if PY_MAJOR_VERSION <= 2
    19341749                        ret = PyString_FromString( *((char **)ns_v.ptr) );
    1935 #else
    1936                         ret = PyUnicode_FromString( *((char **)ns_v.ptr) );
    1937 #endif
    19381750                break;
    19391751
     
    20161828                } else {
    20171829                        PRUint32 string_size = GetSizeIs(index, PR_TRUE);
    2018 #if PY_MAJOR_VERSION <= 2
    20191830                        ret = PyString_FromStringAndSize( *((char **)ns_v.ptr), string_size );
    2020 #else
    2021                         ret = PyUnicode_FromStringAndSize( *((char **)ns_v.ptr), string_size );
    2022 #endif
    20231831                }
    20241832                break;
     
    22752083          case nsXPTType::T_CHAR: {
    22762084                char temp = DEREF_IN_OR_OUT(ns_v.val.c, char);
    2277 #if PY_MAJOR_VERSION <= 2
    22782085                ret = PyString_FromStringAndSize(&temp, 1);
    2279 #else
    2280                 ret = PyUnicode_FromStringAndSize(&temp, 1);
    2281 #endif
    22822086                break;
    22832087                }
     
    23122116                        Py_INCREF(Py_None);
    23132117                } else
    2314 #if PY_MAJOR_VERSION <= 2
    23152118                        ret = PyString_FromString(t);
    2316 #else
    2317                         ret = PyUnicode_FromString(t);
    2318 #endif
    23192119                break;
    23202120                }
     
    23782178                        Py_INCREF(Py_None);
    23792179                } else
    2380 #if PY_MAJOR_VERSION <= 2
    23812180                        ret = PyString_FromStringAndSize(t, string_size);
    2382 #else
    2383                         ret = PyUnicode_FromStringAndSize(t, string_size);
    2384 #endif
    23852181                break;
    23862182                }
     
    24032199                sprintf(buf, "Unknown XPCOM type flags (0x%x)", td.type_flags);
    24042200                PyXPCOM_LogWarning("%s - returning a string object with this message!\n", buf);
    2405 #if PY_MAJOR_VERSION <= 2
    24062201                ret = PyString_FromString(buf);
    2407 #else
    2408                 ret = PyUnicode_FromString(buf);
    2409 #endif
    24102202                break;
    24112203                }
     
    25482340                break;
    25492341          case nsXPTType::T_CHAR:
    2550 #if PY_MAJOR_VERSION <= 2
    25512342                if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    25522343                        PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    25582349                NS_ABORT_IF_FALSE(PyString_Check(val_use), "PyObject_Str didnt return a string object!");
    25592350                FILL_SIMPLE_POINTER( char, *PyString_AS_STRING(val_use) );
    2560 #else
    2561                 if (!PyUnicode_Check(val)) {
    2562                         PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    2563                         BREAK_FALSE;
    2564                 }
    2565                 FILL_SIMPLE_POINTER( char, *PyUnicode_AS_UNICODE(val) );
    2566 #endif
    25672351                break;
    25682352
    25692353          case nsXPTType::T_WCHAR:
    2570 #if PY_MAJOR_VERSION <= 2
    25712354                if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    25722355                        PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
    25732356                        BREAK_FALSE;
    25742357                }
    2575 #else
    2576                 if (!PyUnicode_Check(val)) {
    2577                         PyErr_SetString(PyExc_TypeError, "This parameter must be a Unicode object");
    2578                         BREAK_FALSE;
    2579                 }
    2580 #endif
    25812358                if ((val_use = PyUnicode_FromObject(val))==NULL)
    25822359                        BREAK_FALSE;
     
    26182395                        NS_ABORT_IF_FALSE(0, "dont handle None here yet");
    26192396                } else {
    2620 #if PY_MAJOR_VERSION <= 2
    26212397                        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    26222398                                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    26262402                        NS_ABORT_IF_FALSE(PyString_Check(val_use), "PyObject_Str didnt return a string object!");
    26272403                        const char *sz = PyString_AS_STRING(val_use);
    2628                         ws->Assign(sz, PyString_GET_SIZE(val_use));
    2629 #else
    2630                         if (!PyUnicode_Check(val)) {
    2631                                 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    2632                                 BREAK_FALSE;
    2633                         }
    2634                         val_use = PyUnicode_AsUTF8String(val);
    2635                         const char *sz = PyBytes_AS_STRING(val_use);
    2636                         ws->Assign(sz, PyBytes_GET_SIZE(val_use));
    2637 #endif
     2404                        ws->Assign(sz, PyString_Size(val_use));
    26382405                }
    26392406                break;
     
    26452412                        NS_ABORT_IF_FALSE(0, "dont handle None here yet");
    26462413                } else {
    2647 #if PY_MAJOR_VERSION <= 2
    26482414                        if (PyString_Check(val)) {
    26492415                                val_use = val;
    26502416                                Py_INCREF(val);
    2651                         }
    2652             else
    2653 #endif
    2654             if (PyUnicode_Check(val)) {
     2417                        } else if (PyUnicode_Check(val)) {
    26552418                                val_use = PyUnicode_AsUTF8String(val);
    26562419                        } else {
    2657 #if PY_MAJOR_VERSION <= 2
    26582420                                PyErr_SetString(PyExc_TypeError, "UTF8 parameters must be string or Unicode objects");
    2659 #else
    2660                                 PyErr_SetString(PyExc_TypeError, "UTF8 parameters must be unicode objects");
    2661 #endif
    2662                                 BREAK_FALSE;
    2663                         }
    2664 #if PY_MAJOR_VERSION <= 2
     2421                                BREAK_FALSE;
     2422                        }
    26652423                        NS_ABORT_IF_FALSE(PyString_Check(val_use), "must have a string object!");
    26662424                        const char *sz = PyString_AS_STRING(val_use);
    2667                         ws->Assign(sz, PyString_GET_SIZE(val_use));
    2668 #else
    2669                         NS_ABORT_IF_FALSE(PyBytes_Check(val_use), "must have a bytes object!");
    2670                         const char *sz = PyBytes_AS_STRING(val_use);
    2671                         ws->Assign(sz, PyBytes_GET_SIZE(val_use));
    2672 #endif
     2425                        ws->Assign(sz, PyString_Size(val_use));
    26732426                }
    26742427                break;
     
    26842437                if (val == Py_None)
    26852438                        break; // Remains NULL.
    2686 #if PY_MAJOR_VERSION <= 2
    26872439                if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    26882440                        PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    26962448                const char *sz = PyString_AS_STRING(val_use);
    26972449                int nch = PyString_GET_SIZE(val_use);
    2698 #else
    2699                 if (!PyUnicode_Check(val)) {
    2700                         PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    2701                         BREAK_FALSE;
    2702                 }
    2703                 if ((val_use = PyUnicode_AsUTF8String(val))==NULL)
    2704                         BREAK_FALSE;
    2705 
    2706                 const char *sz = PyBytes_AS_STRING(val_use);
    2707                 int nch = PyBytes_GET_SIZE(val_use);
    2708 #endif
    27092450
    27102451                *pp = (char *)nsMemory::Alloc(nch+1);
     
    27242465                if (val == Py_None)
    27252466                        break; // Remains NULL.
    2726 #if PY_MAJOR_VERSION <= 2
    27272467                if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    27282468                        PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    27312471                val_use = PyUnicode_FromObject(val);
    27322472                NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!");
    2733 #else
    2734                 if (!PyUnicode_Check(val)) {
    2735                         PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    2736                         BREAK_FALSE;
    2737                 }
    2738         val_use = val;
    2739         Py_INCREF(val_use);
    2740 #endif
    27412473                if (PyUnicode_AsPRUnichar(val_use, pp, NULL) < 0)
    27422474                        BREAK_FALSE;
     
    27932525                PRUint32 nch = 0;
    27942526                if (val != Py_None) {
    2795 #if PY_MAJOR_VERSION <= 2
    27962527                        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    27972528                                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    28052536                        sz = PyString_AS_STRING(val_use);
    28062537                        nch = PyString_GET_SIZE(val_use);
    2807 #else
    2808                         if (!PyUnicode_Check(val)) {
    2809                                 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    2810                                 BREAK_FALSE;
    2811                         }
    2812                         if ((val_use = PyUnicode_AsUTF8String(val))==NULL)
    2813                                 BREAK_FALSE;
    2814 
    2815                         sz = PyBytes_AS_STRING(val_use);
    2816                         nch = PyBytes_GET_SIZE(val_use);
    2817 #endif
    28182538                }
    28192539                PRBool bBackFill = PR_FALSE;
     
    28622582
    28632583                if (val != Py_None) {
    2864 #if PY_MAJOR_VERSION <= 2
    28652584                        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    28662585                                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    28692588                        val_use = PyUnicode_FromObject(val);
    28702589                        NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!");
    2871 #else
    2872                         if (!PyUnicode_Check(val)) {
    2873                                 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
    2874                                 BREAK_FALSE;
    2875                         }
    2876             val_use = val;
    2877             Py_INCREF(val_use);
    2878 #endif
    28792590                        if (PyUnicode_AsPRUnichar(val_use, &sz, &nch) < 0)
    28802591                                BREAK_FALSE;
     
    30392750                // But the retval is often the last param described in the info.
    30402751                if (!PySequence_Check(user_result) ||
    3041 #if PY_MAJOR_VERSION <= 2
    30422752                     PyString_Check(user_result) ||
    3043 #else
    3044                      PyBytes_Check(user_result) ||
    3045 #endif
    30462753                     PyUnicode_Check(user_result)) {
    30472754                        PyErr_SetString(PyExc_TypeError, "This function has multiple results, but a sequence was not given to fill them");
  • trunk/src/libs/xpcom18a4/python/src/dllmain.cpp

    r59769 r59795  
    196196        CEnterLeaveXPCOMFramework _celf;
    197197        PRInt32 cnt = PR_AtomicIncrement(&g_cLockCount);
    198         if (cnt==1) { // First call
     198        if (cnt==1) { // First call 
    199199                if (!Py_IsInitialized()) {
    200200                        Py_Initialize();
     
    204204                        if (PySys_GetObject((char*)"argv")==NULL) {
    205205                                PyObject *path = PyList_New(0);
    206 #if PY_MAJOR_VERSION <= 2
    207206                                PyObject *str = PyString_FromString("");
    208 #else
    209                                 PyObject *str = PyUnicode_FromString("");
    210 #endif
    211207                                PyList_Append(path, str);
    212208                                PySys_SetObject((char*)"argv", path);
     
    250246        PR_DestroyLock(g_lockMain);
    251247#ifndef PYXPCOM_USE_PYGILSTATE
    252         // I can't locate a way to kill this -
     248        // I can't locate a way to kill this - 
    253249        // should I pass a dtor to PR_NewThreadPrivateIndex??
    254250        // TlsFree(tlsIndex);
     
    334330                bHaveInitXPCOM = PR_TRUE;
    335331                // Register our custom interfaces.
    336 
     332       
    337333                Py_nsISupports::InitType();
    338334                Py_nsIComponentManager::InitType();
     
    346342                // for backward compatibility:
    347343                Py_nsIComponentManagerObsolete::InitType();
    348 
     344               
    349345        }
    350346        return rc;
  • trunk/src/libs/xpcom18a4/python/src/module/_xpcom.cpp

    r59769 r59795  
    8484# endif
    8585# ifdef VBOX_PYXPCOM_VERSIONED
    86 #  if   PY_VERSION_HEX >= 0x03080000 && PY_VERSION_HEX < 0x03090000
    87 #   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_8")
    88 #   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_8)
    89 
    90 #  elif PY_VERSION_HEX >= 0x03070000 && PY_VERSION_HEX < 0x03080000
    91 #   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_7")
    92 #   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_7)
    93 
    94 #  elif PY_VERSION_HEX >= 0x03060000 && PY_VERSION_HEX < 0x03070000
    95 #   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_6")
    96 #   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_6)
    97 
    98 #  elif PY_VERSION_HEX >= 0x03050000 && PY_VERSION_HEX < 0x03060000
    99 #   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_5")
    100 #   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_5)
    101 
    102 #  elif PY_VERSION_HEX >= 0x03040000 && PY_VERSION_HEX < 0x03050000
    103 #   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_4")
    104 #   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_4)
    105 
    106 #  elif PY_VERSION_HEX >= 0x03030000 && PY_VERSION_HEX < 0x03040000
    107 #   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_3")
    108 #   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_3)
    109 
    110 #  elif PY_VERSION_HEX >= 0x03020000 && PY_VERSION_HEX < 0x03030000
    111 #   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_2")
    112 #   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_2)
    113 
    114 #  elif PY_VERSION_HEX >= 0x03010000 && PY_VERSION_HEX < 0x03020000
    115 #   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython3_1")
    116 #   define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_1)
    117 
    118 #  elif PY_VERSION_HEX >= 0x02080000 && PY_VERSION_HEX < 0x02090000
     86#  if   PY_VERSION_HEX >= 0x02080000
    11987#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython2_8")
    12088#   define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_8)
    12189
    122 #  elif PY_VERSION_HEX >= 0x02070000 && PY_VERSION_HEX < 0x02080000
     90#  elif PY_VERSION_HEX >= 0x02070000
    12391#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython2_7")
    12492#   define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_7)
    12593
    126 #  elif PY_VERSION_HEX >= 0x02060000 && PY_VERSION_HEX < 0x02070000
     94#  elif PY_VERSION_HEX >= 0x02060000
    12795#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython2_6")
    12896#   define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_6)
     97
     98#  elif PY_VERSION_HEX >= 0x02050000
     99#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython2_5")
     100#   define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_5)
     101
     102#  elif PY_VERSION_HEX >= 0x02040000
     103#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython2_4")
     104#   define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_4)
     105
     106#  elif PY_VERSION_HEX >= 0x02030000
     107#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython2_3")
     108#   define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_3)
    129109#  else
    130 #   error "Fix module versioning. This Python version is not recognized."
     110#   error "Fix module versioning."
    131111#  endif
    132112# else
    133113#  define MODULE_NAME     MANGLE_MODULE_NAME("VBoxPython")
    134 #  if PY_MAJOR_VERSION <= 2
    135 #   define initVBoxPython  MANGLE_MODULE_INIT(initVBoxPython)
    136 #  else
    137 #   define initVBoxPython  MANGLE_MODULE_INIT(PyInit_VBoxPython)
    138 #  endif
     114#  define initVBoxPython  MANGLE_MODULE_INIT(initVBoxPython)
    139115# endif
    140116#else
     
    145121// interface support!
    146122
    147 #ifndef VBOX
    148123/* deprecated, included for backward compatibility */
    149124static PyObject *
     
    168143        return Py_nsISupports::PyObjectFromInterface(ocm, NS_GET_IID(nsIComponentManagerObsolete), PR_FALSE);
    169144}
    170 #endif
    171145
    172146static PyObject *
     
    221195}
    222196
    223 #ifndef VBOX
    224197/* deprecated, included for backward compatibility */
    225198static PyObject *
     
    231204        return PyXPCOMMethod_GetComponentManager(self, args);
    232205}
    233 #endif
    234206
    235207static PyObject *
     
    528500        if (!PyArg_ParseTuple(args, "i", &bufSize))
    529501                return NULL;
    530 #if PY_MAJOR_VERSION <= 2
    531502        return PyBuffer_New(bufSize);
    532 #else
    533     return PyBytes_FromStringAndSize(NULL, bufSize);
    534 #endif
    535503}
    536504
     
    703671        {"GetComponentManager", PyXPCOMMethod_GetComponentManager, 1},
    704672        {"GetComponentRegistrar", PyXPCOMMethod_GetComponentRegistrar, 1},
    705 #ifndef VBOX
    706673        {"NS_GetGlobalComponentManager", PyXPCOMMethod_NS_GetGlobalComponentManager, 1}, // deprecated
    707 #endif
    708674        {"XPTI_GetInterfaceInfoManager", PyXPCOMMethod_XPTI_GetInterfaceInfoManager, 1},
    709675        {"XPTC_InvokeByIndex", PyXPCOMMethod_XPTC_InvokeByIndex, 1},
    710676        {"GetServiceManager", PyXPCOMMethod_GetServiceManager, 1},
    711 #ifndef VBOX
    712677        {"GetGlobalServiceManager", PyXPCOMMethod_GetGlobalServiceManager, 1}, // deprecated
    713678        {"IID", PyXPCOMMethod_IID, 1}, // IID is wrong - deprecated - not just IID, but CID, etc.
    714 #endif
    715679        {"ID", PyXPCOMMethod_IID, 1}, // This is the official name.
    716680        {"NS_ShutdownXPCOM", PyXPCOMMethod_NS_ShutdownXPCOM, 1},
     
    727691        {"GetVariantValue", PyXPCOMMethod_GetVariantValue, 1},
    728692#ifdef VBOX
    729     {"WaitForEvents", PyXPCOMMethod_WaitForEvents, 1},
    730     {"InterruptWait", PyXPCOMMethod_InterruptWait, 1},
    731     {"DeinitCOM",     PyXPCOMMethod_DeinitCOM, 1},
    732     {"AttachThread",  PyXPCOMMethod_AttachThread, 1},
    733     {"DetachThread",  PyXPCOMMethod_DetachThread, 1},
     693        {"WaitForEvents", PyXPCOMMethod_WaitForEvents, 1},
     694        {"InterruptWait", PyXPCOMMethod_InterruptWait, 1},
     695        {"DeinitCOM",     PyXPCOMMethod_DeinitCOM, 1},
     696        {"AttachThread",  PyXPCOMMethod_AttachThread, 1},
     697        {"DetachThread",  PyXPCOMMethod_DetachThread, 1},
    734698#endif
    735699#ifdef VBOX_DEBUG_LIFETIMES
     
    741705};
    742706
    743 #if PY_MAJOR_VERSION >= 3
    744 static struct PyModuleDef xpcom_module =
    745 {
    746     PyModuleDef_HEAD_INIT,
    747     MODULE_NAME,    /* name of module */
    748     NULL,           /* module documentation */
    749     -1,             /* size of per-interpreter state or -1 if using globals */
    750     xpcom_methods
    751 };
    752 #endif
    753 
    754 
    755707#define REGISTER_IID(t) { \
    756708        PyObject *iid_ob = Py_nsIID::PyObjectFromIID(NS_GET_IID(t)); \
     
    769721// The module init code.
    770722//
    771 #if PY_MAJOR_VERSION <= 2
    772723extern "C" NS_EXPORT
    773724void
    774 #else
    775 PyObject *
    776 #endif
    777725init_xpcom() {
    778726        PyObject *oModule;
     
    780728        // ensure the framework has valid state to work with.
    781729        if (!PyXPCOM_Globals_Ensure())
    782 #if PY_MAJOR_VERSION <= 2
    783730                return;
    784 #else
    785                 return NULL;
    786 #endif
    787731
    788732        // Must force Python to start using thread locks
     
    790734
    791735        // Create the module and add the functions
    792 #if PY_MAJOR_VERSION <= 2
    793736        oModule = Py_InitModule(MODULE_NAME, xpcom_methods);
    794 #else
    795         oModule = PyModule_Create(&xpcom_module);
    796 #endif
    797737
    798738        PyObject *dict = PyModule_GetDict(oModule);
     
    801741        {
    802742                PyErr_SetString(PyExc_MemoryError, "can't define error");
    803 #if PY_MAJOR_VERSION <= 2
    804743                return;
    805 #else
    806                 return NULL;
    807 #endif
    808744        }
    809745        PyDict_SetItemString(dict, "IIDType", (PyObject *)&Py_nsIID::type);
     
    848784    PyDict_SetItemString(dict, "NS_DEBUG", ob);
    849785    Py_DECREF(ob);
    850 #if PY_MAJOR_VERSION >= 3
    851     return oModule;
    852 #endif
    853786}
    854787
     
    862795#include <iprt/stream.h>
    863796
    864 #if PY_MAJOR_VERSION <= 2
    865797extern "C" NS_EXPORT
    866798void
    867 #else
    868 /** @todo r=klaus this is hacky, but as Python3 doesn't deal with ELF
    869  * visibility, assuming that all globals are visible (which is ugly and not
    870  * true in our case). */
    871 #undef PyMODINIT_FUNC
    872 #define PyMODINIT_FUNC extern "C" NS_EXPORT PyObject*
    873 PyMODINIT_FUNC
    874 #endif
    875799initVBoxPython() { /* NOTE! This name is redefined at the top of the file! */
    876800  static bool s_vboxInited = false;
     
    895819    rc = com::Initialize();
    896820
    897 #if PY_MAJOR_VERSION <= 2
    898821    init_xpcom();
    899 #else
    900     return init_xpcom();
    901 #endif
    902822  }
    903 #if PY_MAJOR_VERSION >= 3
    904   return NULL;
    905 #endif
    906823}
    907824
  • trunk/src/libs/xpcom18a4/python/test/test_test_component.py

    r59769 r59795  
    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.ID(new_iid))
     255    test_attribute(c, "iid_value", component_iid, xpcom._xpcom.IID(new_iid))
    256256
    257257    test_attribute_failure(c, "no_attribute", "boo", AttributeError)
  • trunk/src/libs/xpcom18a4/python/vboxxpcom.py

    r59769 r59795  
    11"""
    2 Copyright (C) 2008-2016 Oracle Corporation
     2Copyright (C) 2008-2012 Oracle Corporation
    33
    44This file is part of VirtualBox Open Source Edition (OSE), as
     
    4747        _oVBoxPythonMod =  __import__(m)
    4848        break
    49     except Exception as x:
    50         print('m=%s x=%s' % (m, x))
     49    except Exception, x:
     50        print 'm=%s x=%s' % (m, x);
    5151    #except:
    5252    #    pass
  • trunk/src/libs/xpcom18a4/python/xpt.py

    r59769 r59795  
    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 = [m for m in self.methods if not m.IsNotXPCOM()]
     107        methods = filter(lambda m: not m.IsNotXPCOM(), self.methods)
    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 = [m for m in self.methods if not m.IsNotXPCOM()]
     132        methods = filter(lambda m: not m.IsNotXPCOM(), self.methods)
    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(list(map(desc, self.params)), ', ')
     254        method_desc = string.join(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')
Note: See TracChangeset for help on using the changeset viewer.

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