Commits

Marc Abramowitz  committed dda786f

Create six.moves.urllib.request namespace

  • Participants
  • Parent commits cc2a923

Comments (0)

Files changed (2)

 sys.modules[__name__ + ".moves.urllib.error"] = Module_six_moves_urllib_error("six.moves.urllib.error")
 
 
+class Module_six_moves_urllib_request(types.ModuleType):
+    """Lazy loading of moved objects in six.moves.urllib_request"""
+
+
+_urllib_request_moved_attributes = [
+    MovedAttribute("urlopen", "urllib2", "urllib.request"),
+    MovedAttribute("install_opener", "urllib2", "urllib.request"),
+    MovedAttribute("build_opener", "urllib2", "urllib.request"),
+    MovedAttribute("pathname2url", "urllib", "urllib.request"),
+    MovedAttribute("url2pathname", "urllib", "urllib.request"),
+    MovedAttribute("getproxies", "urllib", "urllib.request"),
+    MovedAttribute("Request", "urllib2", "urllib.request"),
+    MovedAttribute("OpenerDirector", "urllib2", "urllib.request"),
+    MovedAttribute("HTTPDefaultErrorHandler", "urllib2", "urllib.request"),
+    MovedAttribute("HTTPRedirectHandler", "urllib2", "urllib.request"),
+    MovedAttribute("HTTPCookieProcessor", "urllib2", "urllib.request"),
+    MovedAttribute("ProxyHandler", "urllib2", "urllib.request"),
+    MovedAttribute("BaseHandler", "urllib2", "urllib.request"),
+    MovedAttribute("HTTPPasswordMgr", "urllib2", "urllib.request"),
+    MovedAttribute("HTTPPasswordMgrWithDefaultRealm", "urllib2", "urllib.request"),
+    MovedAttribute("AbstractBasicAuthHandler", "urllib2", "urllib.request"),
+    MovedAttribute("HTTPBasicAuthHandler", "urllib2", "urllib.request"),
+    MovedAttribute("ProxyBasicAuthHandler", "urllib2", "urllib.request"),
+    MovedAttribute("AbstractDigestAuthHandler", "urllib2", "urllib.request"),
+    MovedAttribute("HTTPDigestAuthHandler", "urllib2", "urllib.request"),
+    MovedAttribute("ProxyDigestAuthHandler", "urllib2", "urllib.request"),
+    MovedAttribute("HTTPHandler", "urllib2", "urllib.request"),
+    MovedAttribute("HTTPSHandler", "urllib2", "urllib.request"),
+    MovedAttribute("FileHandler", "urllib2", "urllib.request"),
+    MovedAttribute("FTPHandler", "urllib2", "urllib.request"),
+    MovedAttribute("CacheFTPHandler", "urllib2", "urllib.request"),
+    MovedAttribute("UnknownHandler", "urllib2", "urllib.request"),
+    MovedAttribute("HTTPErrorProcessor", "urllib2", "urllib.request"),
+    MovedAttribute("urlretrieve", "urllib", "urllib.request"),
+    MovedAttribute("urlcleanup", "urllib", "urllib.request"),
+    MovedAttribute("URLopener", "urllib", "urllib.request"),
+    MovedAttribute("FancyURLopener", "urllib", "urllib.request"),
+]
+for attr in _urllib_request_moved_attributes:
+    setattr(Module_six_moves_urllib_request, attr.name, attr)
+del attr
+
+sys.modules[__name__ + ".moves.urllib_request"] = Module_six_moves_urllib_request("six.moves.urllib_request")
+sys.modules[__name__ + ".moves.urllib.request"] = Module_six_moves_urllib_request("six.moves.urllib.request")
+
+
 class Module_six_moves_urllib(types.ModuleType):
     """Create a six.moves.urllib namespace that resembles the Python 3 namespace"""
     parse = sys.modules[__name__ + ".moves.urllib_parse"]
     error = sys.modules[__name__ + ".moves.urllib_error"]
+    request = sys.modules[__name__ + ".moves.urllib_request"]
 
 
 sys.modules[__name__ + ".moves.urllib"] = Module_six_moves_urllib("six.moves.urllib")

File test_urllib_dot_request.py

+from six import PY3
+
+
+def test_import_urllib():
+    import six.moves.urllib
+
+
+def test_import_urllib_dot_request():
+    import six.moves.urllib.request
+
+
+def test_urllib_dot_request_urlopen():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import urlopen
+    else:
+        from urllib2 import urlopen
+
+    assert six.moves.urllib.request.urlopen == urlopen
+
+
+def test_urllib_dot_request_install_opener():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import install_opener
+    else:
+        from urllib2 import install_opener
+
+    assert six.moves.urllib.request.install_opener == install_opener
+
+
+def test_urllib_dot_request_build_opener():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import build_opener
+    else:
+        from urllib2 import build_opener
+
+    assert six.moves.urllib.request.build_opener == build_opener
+
+
+def test_urllib_dot_request_pathname2url():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import pathname2url
+    else:
+        from urllib import pathname2url
+
+    assert six.moves.urllib.request.pathname2url == pathname2url
+
+
+def test_urllib_dot_request_url2pathname():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import url2pathname
+    else:
+        from urllib import url2pathname
+
+    assert six.moves.urllib.request.url2pathname == url2pathname
+
+
+def test_urllib_dot_request_getproxies():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import getproxies
+    else:
+        from urllib import getproxies
+
+    assert six.moves.urllib.request.getproxies == getproxies
+
+
+def test_urllib_dot_request_Request():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import Request
+    else:
+        from urllib2 import Request
+
+    assert six.moves.urllib.request.Request == Request
+
+
+def test_urllib_dot_request_OpenerDirector():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import OpenerDirector
+    else:
+        from urllib2 import OpenerDirector
+
+    assert six.moves.urllib.request.OpenerDirector == OpenerDirector
+
+
+def test_urllib_dot_request_BaseHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import BaseHandler
+    else:
+        from urllib2 import BaseHandler
+
+    assert six.moves.urllib.request.BaseHandler == BaseHandler
+
+
+def test_urllib_dot_request_HTTPDefaultErrorHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import HTTPDefaultErrorHandler
+    else:
+        from urllib2 import HTTPDefaultErrorHandler
+
+    assert six.moves.urllib.request.HTTPDefaultErrorHandler == HTTPDefaultErrorHandler
+
+
+def test_urllib_dot_request_HTTPRedirectHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import HTTPRedirectHandler
+    else:
+        from urllib2 import HTTPRedirectHandler
+
+    assert six.moves.urllib.request.HTTPRedirectHandler == HTTPRedirectHandler
+
+
+def test_urllib_dot_request_HTTPCookieProcessor():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import HTTPCookieProcessor
+    else:
+        from urllib2 import HTTPCookieProcessor
+
+    assert six.moves.urllib.request.HTTPCookieProcessor == HTTPCookieProcessor
+
+
+def test_urllib_dot_request_ProxyHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import ProxyHandler
+    else:
+        from urllib2 import ProxyHandler
+
+    assert six.moves.urllib.request.ProxyHandler == ProxyHandler
+
+
+def test_urllib_dot_request_HTTPPasswordMgr():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import HTTPPasswordMgr
+    else:
+        from urllib2 import HTTPPasswordMgr
+
+    assert six.moves.urllib.request.HTTPPasswordMgr == HTTPPasswordMgr
+
+
+def test_urllib_dot_request_HTTPPasswordMgrWithDefaultRealm():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import HTTPPasswordMgrWithDefaultRealm
+    else:
+        from urllib2 import HTTPPasswordMgrWithDefaultRealm
+
+    assert six.moves.urllib.request.HTTPPasswordMgrWithDefaultRealm == HTTPPasswordMgrWithDefaultRealm
+
+
+def test_urllib_dot_request_AbstractBasicAuthHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import AbstractBasicAuthHandler
+    else:
+        from urllib2 import AbstractBasicAuthHandler
+
+    assert six.moves.urllib.request.AbstractBasicAuthHandler == AbstractBasicAuthHandler
+
+
+def test_urllib_dot_request_HTTPBasicAuthHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import HTTPBasicAuthHandler
+    else:
+        from urllib2 import HTTPBasicAuthHandler
+
+    assert six.moves.urllib.request.HTTPBasicAuthHandler == HTTPBasicAuthHandler
+
+
+def test_urllib_dot_request_ProxyBasicAuthHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import ProxyBasicAuthHandler
+    else:
+        from urllib2 import ProxyBasicAuthHandler
+
+    assert six.moves.urllib.request.ProxyBasicAuthHandler == ProxyBasicAuthHandler
+
+
+def test_urllib_dot_request_AbstractDigestAuthHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import AbstractDigestAuthHandler
+    else:
+        from urllib2 import AbstractDigestAuthHandler
+
+    assert six.moves.urllib.request.AbstractDigestAuthHandler == AbstractDigestAuthHandler
+
+
+def test_urllib_dot_request_HTTPDigestAuthHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import HTTPDigestAuthHandler
+    else:
+        from urllib2 import HTTPDigestAuthHandler
+
+    assert six.moves.urllib.request.HTTPDigestAuthHandler == HTTPDigestAuthHandler
+
+
+def test_urllib_dot_request_ProxyDigestAuthHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import ProxyDigestAuthHandler
+    else:
+        from urllib2 import ProxyDigestAuthHandler
+
+    assert six.moves.urllib.request.ProxyDigestAuthHandler == ProxyDigestAuthHandler
+
+
+def test_urllib_dot_request_HTTPHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import HTTPHandler
+    else:
+        from urllib2 import HTTPHandler
+
+    assert six.moves.urllib.request.HTTPHandler == HTTPHandler
+
+
+def test_urllib_dot_request_HTTPSHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import HTTPSHandler
+    else:
+        from urllib2 import HTTPSHandler
+
+    assert six.moves.urllib.request.HTTPSHandler == HTTPSHandler
+
+
+def test_urllib_dot_request_HTTPSHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import HTTPSHandler
+    else:
+        from urllib2 import HTTPSHandler
+
+    assert six.moves.urllib.request.HTTPSHandler == HTTPSHandler
+
+
+def test_urllib_dot_request_FileHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import FileHandler
+    else:
+        from urllib2 import FileHandler
+
+    assert six.moves.urllib.request.FileHandler == FileHandler
+
+
+def test_urllib_dot_request_FTPHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import FTPHandler
+    else:
+        from urllib2 import FTPHandler
+
+    assert six.moves.urllib.request.FTPHandler == FTPHandler
+
+
+def test_urllib_dot_request_CacheFTPHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import CacheFTPHandler
+    else:
+        from urllib2 import CacheFTPHandler
+
+    assert six.moves.urllib.request.CacheFTPHandler == CacheFTPHandler
+
+
+def test_urllib_dot_request_UnknownHandler():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import UnknownHandler
+    else:
+        from urllib2 import UnknownHandler
+
+    assert six.moves.urllib.request.UnknownHandler == UnknownHandler
+
+
+def test_urllib_dot_request_HTTPErrorProcessor():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import HTTPErrorProcessor
+    else:
+        from urllib2 import HTTPErrorProcessor
+
+    assert six.moves.urllib.request.HTTPErrorProcessor == HTTPErrorProcessor
+
+
+def test_urllib_dot_request_urlretrieve():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import urlretrieve
+    else:
+        from urllib import urlretrieve
+
+    assert six.moves.urllib.request.urlretrieve == urlretrieve
+
+
+def test_urllib_dot_request_urlcleanup():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import urlcleanup
+    else:
+        from urllib import urlcleanup
+
+    assert six.moves.urllib.request.urlcleanup == urlcleanup
+
+
+def test_urllib_dot_request_URLopener():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import URLopener
+    else:
+        from urllib import URLopener
+
+    assert six.moves.urllib.request.URLopener == URLopener
+
+
+def test_urllib_dot_request_FancyURLopener():
+    import six.moves.urllib.request
+
+    if PY3:
+        from urllib.request import FancyURLopener
+    else:
+        from urllib import FancyURLopener
+
+    assert six.moves.urllib.request.FancyURLopener == FancyURLopener