Пример #1
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)
Пример #2
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()
Пример #3
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()
Пример #4
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)
Пример #5
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)
Пример #6
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)
Пример #7
0
 def testURLread(self):
     with support.transient_internet("www.python.org"):
         f = urllib_request.urlopen("http://www.python.org/")
         x = f.read()
Пример #8
0
 def testURLread(self):
     with support.transient_internet("www.python.org"):
         f = urllib_request.urlopen("http://www.python.org/")
         x = f.read()