VirtualBox

Ignore:
Timestamp:
Jun 20, 2018 4:39:17 PM (6 years ago)
Author:
vboxsync
Message:

webutils.py: Changed downloadFile() to use urllib2 on python 2.x so we use an interface similar to the 3.x one.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/common/webutils.py

    r72633 r72635  
    3838    from urllib2        import quote        as urllib_quote;        # pylint: disable=import-error,no-name-in-module
    3939    from urllib         import urlencode    as urllib_urlencode;    # pylint: disable=import-error,no-name-in-module
    40     from urllib         import urlopen      as urllib_urlopen;      # pylint: disable=import-error,no-name-in-module
     40    from urllib2        import ProxyHandler as urllib_ProxyHandler; # pylint: disable=import-error,no-name-in-module
     41    from urllib2        import build_opener as urllib_build_opener; # pylint: disable=import-error,no-name-in-module
    4142else:
    4243    from urllib.parse   import quote        as urllib_quote;        # pylint: disable=import-error,no-name-in-module
    4344    from urllib.parse   import urlencode    as urllib_urlencode;    # pylint: disable=import-error,no-name-in-module
    44     from urllib.request import urlopen      as urllib_urlopen;      # pylint: disable=import-error,no-name-in-module
    45     import urllib.request;                                          # pylint: disable=import-error,no-name-in-module
     45    from urllib.request import ProxyHandler as urllib_ProxyHandler; # pylint: disable=import-error,no-name-in-module
     46    from urllib.request import build_opener as urllib_build_opener; # pylint: disable=import-error,no-name-in-module
    4647
    4748# Validation Kit imports.
     
    160161            ## @todo We get 404.html content instead of exceptions here, which is confusing and should be addressed.
    161162            if not fNoProxies:
    162                 oSrc = urllib_urlopen(sUrlFile);
    163             elif sys.version_info[0] < 3:
    164                 oSrc = urllib_urlopen(sUrlFile, proxies = dict());
     163                oOpener = urllib_build_opener();
    165164            else:
    166                 oProxyHandler = urllib.request.ProxyHandler(proxies = dict()); # pylint: disable=no-member
    167                 oOpener = urllib.request.build_opener(oProxyHandler)           # pylint: disable=no-member
    168                 oSrc = oOpener.open(sUrlFile);
     165                oOpener = urllib_build_opener(urllib_ProxyHandler(proxies = dict()));
     166            oSrc = oOpener.open(sUrlFile);
    169167            oDst = utils.openNoInherit(sDstFile, 'wb');
    170168            oDst.write(oSrc.read());
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