Commits

Marc Abramowitz  committed b9805f7

Create six.moves.urllib.robotparser namespace

  • Participants
  • Parent commits 230265e

Comments (0)

Files changed (2)

 sys.modules[__name__ + ".moves.urllib.response"] = Module_six_moves_urllib_response("six.moves.urllib.response")
 
 
+class Module_six_moves_urllib_robotparser(types.ModuleType):
+    """Lazy loading of moved objects in six.moves.urllib_robotparser"""
+
+
+_urllib_robotparser_moved_attributes = [
+    MovedAttribute("RobotFileParser", "robotparser", "urllib.robotparser"),
+]
+for attr in _urllib_robotparser_moved_attributes:
+    setattr(Module_six_moves_urllib_robotparser, attr.name, attr)
+del attr
+
+sys.modules[__name__ + ".moves.urllib_robotparser"] = Module_six_moves_urllib_robotparser("six.moves.urllib_robotparser")
+sys.modules[__name__ + ".moves.urllib.robotparser"] = Module_six_moves_urllib_robotparser("six.moves.urllib.robotparser")
+
+
 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"]
+    robotparser = sys.modules[__name__ + ".moves.urllib_robotparser"]
 
 
 sys.modules[__name__ + ".moves.urllib"] = Module_six_moves_urllib("six.moves.urllib")

File test_urllib_dot_robotparser.py

+from six import PY3
+
+
+def test_import_urllib():
+    import six.moves.urllib
+
+
+def test_import_urllib_dot_robotparser():
+    import six.moves.urllib.robotparser
+
+
+def test_urllib_dot_robotparser_RobotFileParser():
+    import six.moves.urllib.robotparser
+
+    if PY3:
+        from urllib.robotparser import RobotFileParser
+    else:
+        from robotparser import RobotFileParser
+
+    assert six.moves.urllib.robotparser.RobotFileParser == RobotFileParser