Ejemplo n.º 1
0
 def urlopen(self, *args, **kwargs):
     resource = args[0]
     with support.transient_internet(resource):
         r = urllib_request.urlopen(*args, **kwargs)
         try:
             yield r
         finally:
             r.close()
Ejemplo n.º 2
0
 def urlretrieve(self, *args, **kwargs):
     resource = args[0]
     with support.transient_internet(resource):
         file_location, info = urllib_request.urlretrieve(*args, **kwargs)
         try:
             yield file_location, info
         finally:
             support.unlink(file_location)
Ejemplo n.º 3
0
 def test_getcode(self):
     # test getcode() with the fancy opener to get 404 error codes
     URL = "http://www.python.org/XXXinvalidXXX"
     with support.transient_internet(URL):
         open_url = urllib_request.FancyURLopener().open(URL)
         try:
             code = open_url.getcode()
         finally:
             open_url.close()
         self.assertEqual(code, 404)
Ejemplo n.º 4
0
 def testURLread(self):
     with support.transient_internet("www.python.org"):
         f = urllib_request.urlopen("http://www.python.org/")
         x = f.read()