VirtualBox

Changeset 59769 in vbox for trunk/src/VBox/Main/glue


Ignore:
Timestamp:
Feb 22, 2016 12:14:21 PM (9 years ago)
Author:
vboxsync
Message:

PyXPCOM: port to make it compatible with Python 3 (minimum supported version is 2.6 like for all other Python files now)
Frontends/VBoxShell, Installer/common/vboxapisetup.py, Main/glue/vboxapi.py, Main/webservice/websrv-python.xsl: make it compatible with Python 3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/vboxapi.py

    r59353 r59769  
    77__copyright__ = \
    88    """
    9     Copyright (C) 2009-2015 Oracle Corporation
     9    Copyright (C) 2009-2016 Oracle Corporation
    1010
    1111    This file is part of VirtualBox Open Source Edition (OSE), as
     
    3232    xrange = range
    3333    long = int
    34     import builtins
    35     print_ = getattr(builtins, 'print', None)
    36 elif sys.version_info >= (2, 6):
    37     import __builtin__
    38     print_ = getattr(__builtin__, 'print', None)
    39 else:
    40     def print_(*args, **kwargs):
    41         """The new-style print function for Python 2.4 and 2.5."""
    42         fp = kwargs.pop("file", sys.stdout)
    43         if fp is None:
    44             return
    45 
    46         def write(data):
    47             if not isinstance(data, basestring):
    48                 data = str(data)
    49             # If the file has an encoding, encode unicode with it.
    50             if isinstance(fp, file) and isinstance(data, unicode) and fp.encoding is not None:
    51                 errors = getattr(fp, "errors", None)
    52                 if errors is None:
    53                     errors = "strict"
    54                 data = data.encode(fp.encoding, errors)
    55             fp.write(data)
    56 
    57         want_unicode = False
    58         sep = kwargs.pop("sep", None)
    59         if sep is not None:
    60             if isinstance(sep, unicode):
    61                 want_unicode = True
    62             elif not isinstance(sep, str):
    63                 raise TypeError("sep must be None or a string")
    64         end = kwargs.pop("end", None)
    65         if end is not None:
    66             if isinstance(end, unicode):
    67                 want_unicode = True
    68             elif not isinstance(end, str):
    69                 raise TypeError("end must be None or a string")
    70         if kwargs:
    71             raise TypeError("invalid keyword arguments to print()")
    72         if not want_unicode:
    73             for arg in args:
    74                 if isinstance(arg, unicode):
    75                     want_unicode = True
    76                     break
    77         if want_unicode:
    78             newline = unicode("\n")
    79             space = unicode(" ")
    80         else:
    81             newline = "\n"
    82             space = " "
    83         if sep is None:
    84             sep = space
    85         if end is None:
    86             end = newline
    87         for i, arg in enumerate(args):
    88             if i:
    89                 write(sep)
    90             write(arg)
    91         write(end)
    9234
    9335#
     
    225167    # Try case-insensitivity workaround for class attributes (COM methods).
    226168    sAttrLower = sAttr.lower()
    227     for k in self.__class__.__dict__.keys():
     169    for k in list(self.__class__.__dict__.keys()):
    228170        if k.lower() == sAttrLower:
    229171            setattr(self.__class__, sAttr, self.__class__.__dict__[k])
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