Commits

Marc Abramowitz committed 230265e

Create six.moves.urllib.response namespace

Comments (0)

Files changed (2)

 sys.modules[__name__ + ".moves.urllib.request"] = Module_six_moves_urllib_request("six.moves.urllib.request")
 
 
+class Module_six_moves_urllib_response(types.ModuleType):
+    """Lazy loading of moved objects in six.moves.urllib_response"""
+
+
+_urllib_response_moved_attributes = [
+    MovedAttribute("addbase", "urllib", "urllib.response"),
+    MovedAttribute("addclosehook", "urllib", "urllib.response"),
+    MovedAttribute("addinfo", "urllib", "urllib.response"),
+    MovedAttribute("addinfourl", "urllib", "urllib.response"),
+]
+for attr in _urllib_response_moved_attributes:
+    setattr(Module_six_moves_urllib_response, attr.name, attr)
+del attr
+
+sys.modules[__name__ + ".moves.urllib_response"] = Module_six_moves_urllib_response("six.moves.urllib_response")
+sys.modules[__name__ + ".moves.urllib.response"] = Module_six_moves_urllib_response("six.moves.urllib.response")
+
+
 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"]
+    response = sys.modules[__name__ + ".moves.urllib_response"]
 
 
 sys.modules[__name__ + ".moves.urllib"] = Module_six_moves_urllib("six.moves.urllib")

test_urllib_dot_response.py

+from six import PY3
+
+
+def test_import_urllib():
+    import six.moves.urllib
+
+
+def test_import_urllib_dot_response():
+    import six.moves.urllib.response
+
+
+def test_urllib_dot_response_addbase():
+    import six.moves.urllib.response
+
+    if PY3:
+        from urllib.response import addbase
+    else:
+        from urllib import addbase
+
+    assert six.moves.urllib.response.addbase == addbase
+
+
+def test_urllib_dot_response_addclosehook():
+    import six.moves.urllib.response
+
+    if PY3:
+        from urllib.response import addclosehook
+    else:
+        from urllib import addclosehook
+
+    assert six.moves.urllib.response.addclosehook == addclosehook
+
+
+def test_urllib_dot_response_addinfo():
+    import six.moves.urllib.response
+
+    if PY3:
+        from urllib.response import addinfo
+    else:
+        from urllib import addinfo
+
+    assert six.moves.urllib.response.addinfo == addinfo
+
+
+def test_urllib_dot_response_addinfourl():
+    import six.moves.urllib.response
+
+    if PY3:
+        from urllib.response import addinfourl
+    else:
+        from urllib import addinfourl
+
+    assert six.moves.urllib.response.addinfourl == addinfourl