Back to index

python3.2  3.2.2
Public Member Functions
test.test_urllib.URLopener_Tests Class Reference

List of all members.

Public Member Functions

def test_quoted_open

Detailed Description

Testcase to test the open method of URLopener class.

Definition at line 1061 of file test_urllib.py.


Member Function Documentation

Definition at line 1064 of file test_urllib.py.

01064 
01065     def test_quoted_open(self):
01066         class DummyURLopener(urllib.request.URLopener):
01067             def open_spam(self, url):
01068                 return url
01069 
01070         self.assertEqual(DummyURLopener().open(
01071             'spam://example/ /'),'//example/%20/')
01072 
01073         # test the safe characters are not quoted by urlopen
01074         self.assertEqual(DummyURLopener().open(
01075             "spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/"),
01076             "//c:|windows%/:=&?~#+!$,;'@()*[]|/path/")
01077 
01078 # Just commented them out.
01079 # Can't really tell why keep failing in windows and sparc.
01080 # Everywhere else they work ok, but on those machines, sometimes
01081 # fail in one of the tests, sometimes in other. I have a linux, and
01082 # the tests go ok.
01083 # If anybody has one of the problematic enviroments, please help!
01084 # .   Facundo
01085 #
01086 # def server(evt):
01087 #     import socket, time
01088 #     serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
01089 #     serv.settimeout(3)
01090 #     serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
01091 #     serv.bind(("", 9093))
01092 #     serv.listen(5)
01093 #     try:
01094 #         conn, addr = serv.accept()
01095 #         conn.send("1 Hola mundo\n")
01096 #         cantdata = 0
01097 #         while cantdata < 13:
01098 #             data = conn.recv(13-cantdata)
01099 #             cantdata += len(data)
01100 #             time.sleep(.3)
01101 #         conn.send("2 No more lines\n")
01102 #         conn.close()
01103 #     except socket.timeout:
01104 #         pass
01105 #     finally:
01106 #         serv.close()
01107 #         evt.set()
01108 #
01109 # class FTPWrapperTests(unittest.TestCase):
01110 #
01111 #     def setUp(self):
01112 #         import ftplib, time, threading
01113 #         ftplib.FTP.port = 9093
01114 #         self.evt = threading.Event()
01115 #         threading.Thread(target=server, args=(self.evt,)).start()
01116 #         time.sleep(.1)
01117 #
01118 #     def tearDown(self):
01119 #         self.evt.wait()
01120 #
01121 #     def testBasic(self):
01122 #         # connects
01123 #         ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [])
01124 #         ftp.close()
01125 #
01126 #     def testTimeoutNone(self):
01127 #         # global default timeout is ignored
01128 #         import socket
01129 #         self.assertTrue(socket.getdefaulttimeout() is None)
01130 #         socket.setdefaulttimeout(30)
01131 #         try:
01132 #             ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [])
01133 #         finally:
01134 #             socket.setdefaulttimeout(None)
01135 #         self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
01136 #         ftp.close()
01137 #
01138 #     def testTimeoutDefault(self):
01139 #         # global default timeout is used
01140 #         import socket
01141 #         self.assertTrue(socket.getdefaulttimeout() is None)
01142 #         socket.setdefaulttimeout(30)
01143 #         try:
01144 #             ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [])
01145 #         finally:
01146 #             socket.setdefaulttimeout(None)
01147 #         self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
01148 #         ftp.close()
01149 #
01150 #     def testTimeoutValue(self):
01151 #         ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [],
01152 #                                 timeout=30)
01153 #         self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
01154 #         ftp.close()
01155 
01156 

Here is the call graph for this function:


The documentation for this class was generated from the following file: