blob: 5ebcfcb939d6b8ebb8c647a980fc04b7013dd2cd [file] [log] [blame]
Jeremy Hylton636950f2009-03-28 04:34:21 +00001import errno
Jeremy Hylton7c1692d2009-03-27 21:31:03 +00002from http import client
Jeremy Hylton8fff7922007-08-03 20:56:14 +00003import io
Antoine Pitrou803e6d62010-10-13 10:36:15 +00004import os
Antoine Pitrouead1d622009-09-29 18:44:53 +00005import array
Guido van Rossumd8faa362007-04-27 19:54:29 +00006import socket
Jeremy Hylton121d34a2003-07-08 12:36:58 +00007
Gregory P. Smithb4066372010-01-03 03:28:29 +00008import unittest
9TestCase = unittest.TestCase
Jeremy Hylton2c178252004-08-07 16:28:14 +000010
Benjamin Petersonee8712c2008-05-20 21:35:26 +000011from test import support
Jeremy Hylton79fa2b62001-04-13 14:57:44 +000012
Antoine Pitrou803e6d62010-10-13 10:36:15 +000013here = os.path.dirname(__file__)
14# Self-signed cert file for 'localhost'
15CERT_localhost = os.path.join(here, 'keycert.pem')
16# Self-signed cert file for 'fakehostname'
17CERT_fakehostname = os.path.join(here, 'keycert2.pem')
18# Root cert file (CA) for svn.python.org's cert
19CACERT_svn_python_org = os.path.join(here, 'https_svn_python_org_root.pem')
20
Benjamin Petersonee8712c2008-05-20 21:35:26 +000021HOST = support.HOST
Christian Heimes5e696852008-04-09 08:37:03 +000022
Jeremy Hylton79fa2b62001-04-13 14:57:44 +000023class FakeSocket:
Jeremy Hylton8fff7922007-08-03 20:56:14 +000024 def __init__(self, text, fileclass=io.BytesIO):
25 if isinstance(text, str):
Guido van Rossum39478e82007-08-27 17:23:59 +000026 text = text.encode("ascii")
Jeremy Hylton79fa2b62001-04-13 14:57:44 +000027 self.text = text
Jeremy Hylton121d34a2003-07-08 12:36:58 +000028 self.fileclass = fileclass
Martin v. Löwisdd5a8602007-06-30 09:22:09 +000029 self.data = b''
Jeremy Hylton79fa2b62001-04-13 14:57:44 +000030
Jeremy Hylton2c178252004-08-07 16:28:14 +000031 def sendall(self, data):
Thomas Wouters89f507f2006-12-13 04:49:30 +000032 self.data += data
Jeremy Hylton2c178252004-08-07 16:28:14 +000033
Jeremy Hylton79fa2b62001-04-13 14:57:44 +000034 def makefile(self, mode, bufsize=None):
35 if mode != 'r' and mode != 'rb':
Jeremy Hylton7c1692d2009-03-27 21:31:03 +000036 raise client.UnimplementedFileMode()
Jeremy Hylton121d34a2003-07-08 12:36:58 +000037 return self.fileclass(self.text)
38
Jeremy Hylton636950f2009-03-28 04:34:21 +000039class EPipeSocket(FakeSocket):
40
41 def __init__(self, text, pipe_trigger):
42 # When sendall() is called with pipe_trigger, raise EPIPE.
43 FakeSocket.__init__(self, text)
44 self.pipe_trigger = pipe_trigger
45
46 def sendall(self, data):
47 if self.pipe_trigger in data:
48 raise socket.error(errno.EPIPE, "gotcha")
49 self.data += data
50
51 def close(self):
52 pass
53
Jeremy Hylton8fff7922007-08-03 20:56:14 +000054class NoEOFStringIO(io.BytesIO):
Jeremy Hylton121d34a2003-07-08 12:36:58 +000055 """Like StringIO, but raises AssertionError on EOF.
56
Jeremy Hylton7c1692d2009-03-27 21:31:03 +000057 This is used below to test that http.client doesn't try to read
Jeremy Hylton121d34a2003-07-08 12:36:58 +000058 more from the underlying file than it should.
59 """
60 def read(self, n=-1):
Jeremy Hylton8fff7922007-08-03 20:56:14 +000061 data = io.BytesIO.read(self, n)
Jeremy Hyltonda3f2282007-08-29 17:26:34 +000062 if data == b'':
Jeremy Hylton121d34a2003-07-08 12:36:58 +000063 raise AssertionError('caller tried to read past EOF')
64 return data
65
66 def readline(self, length=None):
Jeremy Hylton8fff7922007-08-03 20:56:14 +000067 data = io.BytesIO.readline(self, length)
Jeremy Hyltonda3f2282007-08-29 17:26:34 +000068 if data == b'':
Jeremy Hylton121d34a2003-07-08 12:36:58 +000069 raise AssertionError('caller tried to read past EOF')
70 return data
Jeremy Hylton79fa2b62001-04-13 14:57:44 +000071
Jeremy Hylton2c178252004-08-07 16:28:14 +000072class HeaderTests(TestCase):
73 def test_auto_headers(self):
74 # Some headers are added automatically, but should not be added by
75 # .request() if they are explicitly set.
76
Jeremy Hylton2c178252004-08-07 16:28:14 +000077 class HeaderCountingBuffer(list):
78 def __init__(self):
79 self.count = {}
80 def append(self, item):
Guido van Rossum022c4742007-08-29 02:00:20 +000081 kv = item.split(b':')
Jeremy Hylton2c178252004-08-07 16:28:14 +000082 if len(kv) > 1:
83 # item is a 'Key: Value' header string
Martin v. Löwisdd5a8602007-06-30 09:22:09 +000084 lcKey = kv[0].decode('ascii').lower()
Jeremy Hylton2c178252004-08-07 16:28:14 +000085 self.count.setdefault(lcKey, 0)
86 self.count[lcKey] += 1
87 list.append(self, item)
88
89 for explicit_header in True, False:
90 for header in 'Content-length', 'Host', 'Accept-encoding':
Jeremy Hylton7c1692d2009-03-27 21:31:03 +000091 conn = client.HTTPConnection('example.com')
Jeremy Hylton2c178252004-08-07 16:28:14 +000092 conn.sock = FakeSocket('blahblahblah')
93 conn._buffer = HeaderCountingBuffer()
94
95 body = 'spamspamspam'
96 headers = {}
97 if explicit_header:
98 headers[header] = str(len(body))
99 conn.request('POST', '/', body, headers)
100 self.assertEqual(conn._buffer.count[header.lower()], 1)
101
Senthil Kumaran5fa4a892012-05-19 16:58:09 +0800102 def test_content_length_0(self):
103
104 class ContentLengthChecker(list):
105 def __init__(self):
106 list.__init__(self)
107 self.content_length = None
108 def append(self, item):
109 kv = item.split(b':', 1)
110 if len(kv) > 1 and kv[0].lower() == b'content-length':
111 self.content_length = kv[1].strip()
112 list.append(self, item)
113
114 # POST with empty body
115 conn = client.HTTPConnection('example.com')
116 conn.sock = FakeSocket(None)
117 conn._buffer = ContentLengthChecker()
118 conn.request('POST', '/', '')
119 self.assertEqual(conn._buffer.content_length, b'0',
120 'Header Content-Length not set')
121
122 # PUT request with empty body
123 conn = client.HTTPConnection('example.com')
124 conn.sock = FakeSocket(None)
125 conn._buffer = ContentLengthChecker()
126 conn.request('PUT', '/', '')
127 self.assertEqual(conn._buffer.content_length, b'0',
128 'Header Content-Length not set')
129
Senthil Kumaran58d5dbf2010-10-03 18:22:42 +0000130 def test_putheader(self):
131 conn = client.HTTPConnection('example.com')
132 conn.sock = FakeSocket(None)
133 conn.putrequest('GET','/')
134 conn.putheader('Content-length', 42)
Senthil Kumaran58d5dbf2010-10-03 18:22:42 +0000135 self.assertTrue(b'Content-length: 42' in conn._buffer)
136
Senthil Kumaran74ebd9e2010-11-13 12:27:49 +0000137 def test_ipv6host_header(self):
138 # Default host header on IPv6 transaction should wrapped by [] if
139 # its actual IPv6 address
140 expected = b'GET /foo HTTP/1.1\r\nHost: [2001::]:81\r\n' \
141 b'Accept-Encoding: identity\r\n\r\n'
142 conn = client.HTTPConnection('[2001::]:81')
143 sock = FakeSocket('')
144 conn.sock = sock
145 conn.request('GET', '/foo')
146 self.assertTrue(sock.data.startswith(expected))
147
148 expected = b'GET /foo HTTP/1.1\r\nHost: [2001:102A::]\r\n' \
149 b'Accept-Encoding: identity\r\n\r\n'
150 conn = client.HTTPConnection('[2001:102A::]')
151 sock = FakeSocket('')
152 conn.sock = sock
153 conn.request('GET', '/foo')
154 self.assertTrue(sock.data.startswith(expected))
155
Senthil Kumaran58d5dbf2010-10-03 18:22:42 +0000156
Thomas Wouters89f507f2006-12-13 04:49:30 +0000157class BasicTest(TestCase):
158 def test_status_lines(self):
159 # Test HTTP status lines
Jeremy Hylton79fa2b62001-04-13 14:57:44 +0000160
Thomas Wouters89f507f2006-12-13 04:49:30 +0000161 body = "HTTP/1.1 200 Ok\r\n\r\nText"
162 sock = FakeSocket(body)
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000163 resp = client.HTTPResponse(sock)
Jeremy Hyltonba603192003-01-23 18:02:20 +0000164 resp.begin()
Jeremy Hylton8fff7922007-08-03 20:56:14 +0000165 self.assertEqual(resp.read(), b"Text")
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000166 self.assertTrue(resp.isclosed())
Jeremy Hyltonba603192003-01-23 18:02:20 +0000167
Thomas Wouters89f507f2006-12-13 04:49:30 +0000168 body = "HTTP/1.1 400.100 Not Ok\r\n\r\nText"
169 sock = FakeSocket(body)
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000170 resp = client.HTTPResponse(sock)
171 self.assertRaises(client.BadStatusLine, resp.begin)
Jeremy Hyltonba603192003-01-23 18:02:20 +0000172
Benjamin Peterson11dbfd42010-03-21 22:50:04 +0000173 def test_bad_status_repr(self):
174 exc = client.BadStatusLine('')
Ezio Melottib3aedd42010-11-20 19:04:17 +0000175 self.assertEqual(repr(exc), '''BadStatusLine("\'\'",)''')
Benjamin Peterson11dbfd42010-03-21 22:50:04 +0000176
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000177 def test_partial_reads(self):
Antoine Pitrou084daa22012-12-15 19:11:54 +0100178 # if we have a length, the system knows when to close itself
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000179 # same behaviour than when we read the whole thing with read()
180 body = "HTTP/1.1 200 Ok\r\nContent-Length: 4\r\n\r\nText"
181 sock = FakeSocket(body)
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000182 resp = client.HTTPResponse(sock)
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000183 resp.begin()
184 self.assertEqual(resp.read(2), b'Te')
185 self.assertFalse(resp.isclosed())
186 self.assertEqual(resp.read(2), b'xt')
187 self.assertTrue(resp.isclosed())
188
Antoine Pitrou38d96432011-12-06 22:33:57 +0100189 def test_partial_readintos(self):
Antoine Pitroud20e7742012-12-15 19:22:30 +0100190 # if we have a length, the system knows when to close itself
Antoine Pitrou38d96432011-12-06 22:33:57 +0100191 # same behaviour than when we read the whole thing with read()
192 body = "HTTP/1.1 200 Ok\r\nContent-Length: 4\r\n\r\nText"
193 sock = FakeSocket(body)
194 resp = client.HTTPResponse(sock)
195 resp.begin()
196 b = bytearray(2)
197 n = resp.readinto(b)
198 self.assertEqual(n, 2)
199 self.assertEqual(bytes(b), b'Te')
200 self.assertFalse(resp.isclosed())
201 n = resp.readinto(b)
202 self.assertEqual(n, 2)
203 self.assertEqual(bytes(b), b'xt')
204 self.assertTrue(resp.isclosed())
205
Antoine Pitrou084daa22012-12-15 19:11:54 +0100206 def test_partial_reads_no_content_length(self):
207 # when no length is present, the socket should be gracefully closed when
208 # all data was read
209 body = "HTTP/1.1 200 Ok\r\n\r\nText"
210 sock = FakeSocket(body)
211 resp = client.HTTPResponse(sock)
212 resp.begin()
213 self.assertEqual(resp.read(2), b'Te')
214 self.assertFalse(resp.isclosed())
215 self.assertEqual(resp.read(2), b'xt')
216 self.assertEqual(resp.read(1), b'')
217 self.assertTrue(resp.isclosed())
218
Antoine Pitroud20e7742012-12-15 19:22:30 +0100219 def test_partial_readintos_no_content_length(self):
220 # when no length is present, the socket should be gracefully closed when
221 # all data was read
222 body = "HTTP/1.1 200 Ok\r\n\r\nText"
223 sock = FakeSocket(body)
224 resp = client.HTTPResponse(sock)
225 resp.begin()
226 b = bytearray(2)
227 n = resp.readinto(b)
228 self.assertEqual(n, 2)
229 self.assertEqual(bytes(b), b'Te')
230 self.assertFalse(resp.isclosed())
231 n = resp.readinto(b)
232 self.assertEqual(n, 2)
233 self.assertEqual(bytes(b), b'xt')
234 n = resp.readinto(b)
235 self.assertEqual(n, 0)
236 self.assertTrue(resp.isclosed())
237
Thomas Wouters89f507f2006-12-13 04:49:30 +0000238 def test_host_port(self):
239 # Check invalid host_port
Jeremy Hyltonba603192003-01-23 18:02:20 +0000240
Łukasz Langaa5a9a9c2011-10-18 21:17:39 +0200241 for hp in ("www.python.org:abc", "user:password@www.python.org"):
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000242 self.assertRaises(client.InvalidURL, client.HTTPConnection, hp)
Thomas Wouters89f507f2006-12-13 04:49:30 +0000243
Jeremy Hylton3a38c912007-08-14 17:08:07 +0000244 for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000",
245 "fe80::207:e9ff:fe9b", 8000),
Thomas Wouters89f507f2006-12-13 04:49:30 +0000246 ("www.python.org:80", "www.python.org", 80),
Łukasz Langaa5a9a9c2011-10-18 21:17:39 +0200247 ("www.python.org:", "www.python.org", 80),
Thomas Wouters89f507f2006-12-13 04:49:30 +0000248 ("www.python.org", "www.python.org", 80),
Łukasz Langaa5a9a9c2011-10-18 21:17:39 +0200249 ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 80),
250 ("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b", 80)):
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000251 c = client.HTTPConnection(hp)
Jeremy Hylton3a38c912007-08-14 17:08:07 +0000252 self.assertEqual(h, c.host)
253 self.assertEqual(p, c.port)
Skip Montanaro10e6e0e2004-09-14 16:32:02 +0000254
Thomas Wouters89f507f2006-12-13 04:49:30 +0000255 def test_response_headers(self):
256 # test response with multiple message headers with the same field name.
257 text = ('HTTP/1.1 200 OK\r\n'
Jeremy Hylton3a38c912007-08-14 17:08:07 +0000258 'Set-Cookie: Customer="WILE_E_COYOTE"; '
259 'Version="1"; Path="/acme"\r\n'
Thomas Wouters89f507f2006-12-13 04:49:30 +0000260 'Set-Cookie: Part_Number="Rocket_Launcher_0001"; Version="1";'
261 ' Path="/acme"\r\n'
262 '\r\n'
263 'No body\r\n')
264 hdr = ('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"'
265 ', '
266 'Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme"')
267 s = FakeSocket(text)
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000268 r = client.HTTPResponse(s)
Thomas Wouters89f507f2006-12-13 04:49:30 +0000269 r.begin()
270 cookies = r.getheader("Set-Cookie")
Jeremy Hylton3a38c912007-08-14 17:08:07 +0000271 self.assertEqual(cookies, hdr)
Jeremy Hyltonba603192003-01-23 18:02:20 +0000272
Thomas Wouters89f507f2006-12-13 04:49:30 +0000273 def test_read_head(self):
274 # Test that the library doesn't attempt to read any data
275 # from a HEAD request. (Tickles SF bug #622042.)
276 sock = FakeSocket(
277 'HTTP/1.1 200 OK\r\n'
278 'Content-Length: 14432\r\n'
279 '\r\n',
280 NoEOFStringIO)
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000281 resp = client.HTTPResponse(sock, method="HEAD")
Thomas Wouters89f507f2006-12-13 04:49:30 +0000282 resp.begin()
Guido van Rossuma00f1232007-09-12 19:43:09 +0000283 if resp.read():
Thomas Wouters89f507f2006-12-13 04:49:30 +0000284 self.fail("Did not expect response from HEAD request")
Jeremy Hyltonc1b2cb92003-05-05 16:13:58 +0000285
Antoine Pitrou38d96432011-12-06 22:33:57 +0100286 def test_readinto_head(self):
287 # Test that the library doesn't attempt to read any data
288 # from a HEAD request. (Tickles SF bug #622042.)
289 sock = FakeSocket(
290 'HTTP/1.1 200 OK\r\n'
291 'Content-Length: 14432\r\n'
292 '\r\n',
293 NoEOFStringIO)
294 resp = client.HTTPResponse(sock, method="HEAD")
295 resp.begin()
296 b = bytearray(5)
297 if resp.readinto(b) != 0:
298 self.fail("Did not expect response from HEAD request")
299 self.assertEqual(bytes(b), b'\x00'*5)
300
Thomas Wouters89f507f2006-12-13 04:49:30 +0000301 def test_send_file(self):
Guido van Rossum022c4742007-08-29 02:00:20 +0000302 expected = (b'GET /foo HTTP/1.1\r\nHost: example.com\r\n'
303 b'Accept-Encoding: identity\r\nContent-Length:')
Thomas Wouters89f507f2006-12-13 04:49:30 +0000304
Brett Cannon77b7de62010-10-29 23:31:11 +0000305 with open(__file__, 'rb') as body:
306 conn = client.HTTPConnection('example.com')
307 sock = FakeSocket(body)
308 conn.sock = sock
309 conn.request('GET', '/foo', body)
310 self.assertTrue(sock.data.startswith(expected), '%r != %r' %
311 (sock.data[:len(expected)], expected))
Jeremy Hylton2c178252004-08-07 16:28:14 +0000312
Antoine Pitrouead1d622009-09-29 18:44:53 +0000313 def test_send(self):
314 expected = b'this is a test this is only a test'
315 conn = client.HTTPConnection('example.com')
316 sock = FakeSocket(None)
317 conn.sock = sock
318 conn.send(expected)
Ezio Melottib3aedd42010-11-20 19:04:17 +0000319 self.assertEqual(expected, sock.data)
Antoine Pitrouead1d622009-09-29 18:44:53 +0000320 sock.data = b''
321 conn.send(array.array('b', expected))
Ezio Melottib3aedd42010-11-20 19:04:17 +0000322 self.assertEqual(expected, sock.data)
Antoine Pitrouead1d622009-09-29 18:44:53 +0000323 sock.data = b''
324 conn.send(io.BytesIO(expected))
Ezio Melottib3aedd42010-11-20 19:04:17 +0000325 self.assertEqual(expected, sock.data)
Antoine Pitrouead1d622009-09-29 18:44:53 +0000326
Senthil Kumaran7bc0d872010-12-19 10:49:52 +0000327 def test_send_iter(self):
328 expected = b'GET /foo HTTP/1.1\r\nHost: example.com\r\n' \
329 b'Accept-Encoding: identity\r\nContent-Length: 11\r\n' \
330 b'\r\nonetwothree'
331
332 def body():
333 yield b"one"
334 yield b"two"
335 yield b"three"
336
337 conn = client.HTTPConnection('example.com')
338 sock = FakeSocket("")
339 conn.sock = sock
340 conn.request('GET', '/foo', body(), {'Content-Length': '11'})
Victor Stinner04ba9662011-01-04 00:04:46 +0000341 self.assertEqual(sock.data, expected)
Senthil Kumaran7bc0d872010-12-19 10:49:52 +0000342
Senthil Kumaraneb71ad42011-08-02 18:33:41 +0800343 def test_send_type_error(self):
344 # See: Issue #12676
345 conn = client.HTTPConnection('example.com')
346 conn.sock = FakeSocket('')
347 with self.assertRaises(TypeError):
348 conn.request('POST', 'test', conn)
349
Christian Heimesa612dc02008-02-24 13:08:18 +0000350 def test_chunked(self):
351 chunked_start = (
352 'HTTP/1.1 200 OK\r\n'
353 'Transfer-Encoding: chunked\r\n\r\n'
354 'a\r\n'
355 'hello worl\r\n'
Antoine Pitrouf7e78182012-01-04 18:57:22 +0100356 '3\r\n'
357 'd! \r\n'
358 '8\r\n'
359 'and now \r\n'
360 '22\r\n'
361 'for something completely different\r\n'
Christian Heimesa612dc02008-02-24 13:08:18 +0000362 )
Antoine Pitrouf7e78182012-01-04 18:57:22 +0100363 expected = b'hello world! and now for something completely different'
Christian Heimesa612dc02008-02-24 13:08:18 +0000364 sock = FakeSocket(chunked_start + '0\r\n')
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000365 resp = client.HTTPResponse(sock, method="GET")
Christian Heimesa612dc02008-02-24 13:08:18 +0000366 resp.begin()
Antoine Pitrouf7e78182012-01-04 18:57:22 +0100367 self.assertEqual(resp.read(), expected)
Christian Heimesa612dc02008-02-24 13:08:18 +0000368 resp.close()
369
Antoine Pitrouf7e78182012-01-04 18:57:22 +0100370 # Various read sizes
371 for n in range(1, 12):
372 sock = FakeSocket(chunked_start + '0\r\n')
373 resp = client.HTTPResponse(sock, method="GET")
374 resp.begin()
375 self.assertEqual(resp.read(n) + resp.read(n) + resp.read(), expected)
376 resp.close()
377
Christian Heimesa612dc02008-02-24 13:08:18 +0000378 for x in ('', 'foo\r\n'):
379 sock = FakeSocket(chunked_start + x)
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000380 resp = client.HTTPResponse(sock, method="GET")
Christian Heimesa612dc02008-02-24 13:08:18 +0000381 resp.begin()
382 try:
383 resp.read()
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000384 except client.IncompleteRead as i:
Antoine Pitrouf7e78182012-01-04 18:57:22 +0100385 self.assertEqual(i.partial, expected)
386 expected_message = 'IncompleteRead(%d bytes read)' % len(expected)
387 self.assertEqual(repr(i), expected_message)
388 self.assertEqual(str(i), expected_message)
Christian Heimesa612dc02008-02-24 13:08:18 +0000389 else:
390 self.fail('IncompleteRead expected')
391 finally:
392 resp.close()
393
Antoine Pitrou38d96432011-12-06 22:33:57 +0100394 def test_readinto_chunked(self):
395 chunked_start = (
396 'HTTP/1.1 200 OK\r\n'
397 'Transfer-Encoding: chunked\r\n\r\n'
398 'a\r\n'
399 'hello worl\r\n'
Antoine Pitrouf7e78182012-01-04 18:57:22 +0100400 '3\r\n'
401 'd! \r\n'
402 '8\r\n'
403 'and now \r\n'
404 '22\r\n'
405 'for something completely different\r\n'
Antoine Pitrou38d96432011-12-06 22:33:57 +0100406 )
Antoine Pitrouf7e78182012-01-04 18:57:22 +0100407 expected = b'hello world! and now for something completely different'
408 nexpected = len(expected)
409 b = bytearray(128)
410
Antoine Pitrou38d96432011-12-06 22:33:57 +0100411 sock = FakeSocket(chunked_start + '0\r\n')
412 resp = client.HTTPResponse(sock, method="GET")
413 resp.begin()
Antoine Pitrou38d96432011-12-06 22:33:57 +0100414 n = resp.readinto(b)
Antoine Pitrouf7e78182012-01-04 18:57:22 +0100415 self.assertEqual(b[:nexpected], expected)
416 self.assertEqual(n, nexpected)
Antoine Pitrou38d96432011-12-06 22:33:57 +0100417 resp.close()
418
Antoine Pitrouf7e78182012-01-04 18:57:22 +0100419 # Various read sizes
420 for n in range(1, 12):
421 sock = FakeSocket(chunked_start + '0\r\n')
422 resp = client.HTTPResponse(sock, method="GET")
423 resp.begin()
424 m = memoryview(b)
425 i = resp.readinto(m[0:n])
426 i += resp.readinto(m[i:n + i])
427 i += resp.readinto(m[i:])
428 self.assertEqual(b[:nexpected], expected)
429 self.assertEqual(i, nexpected)
430 resp.close()
431
Antoine Pitrou38d96432011-12-06 22:33:57 +0100432 for x in ('', 'foo\r\n'):
433 sock = FakeSocket(chunked_start + x)
434 resp = client.HTTPResponse(sock, method="GET")
435 resp.begin()
436 try:
Antoine Pitrou38d96432011-12-06 22:33:57 +0100437 n = resp.readinto(b)
438 except client.IncompleteRead as i:
Antoine Pitrouf7e78182012-01-04 18:57:22 +0100439 self.assertEqual(i.partial, expected)
440 expected_message = 'IncompleteRead(%d bytes read)' % len(expected)
441 self.assertEqual(repr(i), expected_message)
442 self.assertEqual(str(i), expected_message)
Antoine Pitrou38d96432011-12-06 22:33:57 +0100443 else:
444 self.fail('IncompleteRead expected')
445 finally:
446 resp.close()
447
Senthil Kumaran71fb6c82010-04-28 17:39:48 +0000448 def test_chunked_head(self):
449 chunked_start = (
450 'HTTP/1.1 200 OK\r\n'
451 'Transfer-Encoding: chunked\r\n\r\n'
452 'a\r\n'
453 'hello world\r\n'
454 '1\r\n'
455 'd\r\n'
456 )
457 sock = FakeSocket(chunked_start + '0\r\n')
458 resp = client.HTTPResponse(sock, method="HEAD")
459 resp.begin()
Ezio Melottib3aedd42010-11-20 19:04:17 +0000460 self.assertEqual(resp.read(), b'')
461 self.assertEqual(resp.status, 200)
462 self.assertEqual(resp.reason, 'OK')
Senthil Kumaran0b998832010-06-04 17:27:11 +0000463 self.assertTrue(resp.isclosed())
Senthil Kumaran71fb6c82010-04-28 17:39:48 +0000464
Antoine Pitrou38d96432011-12-06 22:33:57 +0100465 def test_readinto_chunked_head(self):
466 chunked_start = (
467 'HTTP/1.1 200 OK\r\n'
468 'Transfer-Encoding: chunked\r\n\r\n'
469 'a\r\n'
470 'hello world\r\n'
471 '1\r\n'
472 'd\r\n'
473 )
474 sock = FakeSocket(chunked_start + '0\r\n')
475 resp = client.HTTPResponse(sock, method="HEAD")
476 resp.begin()
477 b = bytearray(5)
478 n = resp.readinto(b)
479 self.assertEqual(n, 0)
480 self.assertEqual(bytes(b), b'\x00'*5)
481 self.assertEqual(resp.status, 200)
482 self.assertEqual(resp.reason, 'OK')
483 self.assertTrue(resp.isclosed())
484
Christian Heimesa612dc02008-02-24 13:08:18 +0000485 def test_negative_content_length(self):
Jeremy Hylton82066952008-12-15 03:08:30 +0000486 sock = FakeSocket(
487 'HTTP/1.1 200 OK\r\nContent-Length: -1\r\n\r\nHello\r\n')
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000488 resp = client.HTTPResponse(sock, method="GET")
Christian Heimesa612dc02008-02-24 13:08:18 +0000489 resp.begin()
Ezio Melottib3aedd42010-11-20 19:04:17 +0000490 self.assertEqual(resp.read(), b'Hello\r\n')
Christian Heimesa612dc02008-02-24 13:08:18 +0000491 resp.close()
492
Benjamin Peterson6accb982009-03-02 22:50:25 +0000493 def test_incomplete_read(self):
494 sock = FakeSocket('HTTP/1.1 200 OK\r\nContent-Length: 10\r\n\r\nHello\r\n')
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000495 resp = client.HTTPResponse(sock, method="GET")
Benjamin Peterson6accb982009-03-02 22:50:25 +0000496 resp.begin()
497 try:
498 resp.read()
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000499 except client.IncompleteRead as i:
Ezio Melottib3aedd42010-11-20 19:04:17 +0000500 self.assertEqual(i.partial, b'Hello\r\n')
Benjamin Peterson6accb982009-03-02 22:50:25 +0000501 self.assertEqual(repr(i),
502 "IncompleteRead(7 bytes read, 3 more expected)")
503 self.assertEqual(str(i),
504 "IncompleteRead(7 bytes read, 3 more expected)")
505 else:
506 self.fail('IncompleteRead expected')
507 finally:
508 resp.close()
509
Jeremy Hylton636950f2009-03-28 04:34:21 +0000510 def test_epipe(self):
511 sock = EPipeSocket(
512 "HTTP/1.0 401 Authorization Required\r\n"
513 "Content-type: text/html\r\n"
514 "WWW-Authenticate: Basic realm=\"example\"\r\n",
515 b"Content-Length")
516 conn = client.HTTPConnection("example.com")
517 conn.sock = sock
518 self.assertRaises(socket.error,
519 lambda: conn.request("PUT", "/url", "body"))
520 resp = conn.getresponse()
521 self.assertEqual(401, resp.status)
522 self.assertEqual("Basic realm=\"example\"",
523 resp.getheader("www-authenticate"))
Christian Heimesa612dc02008-02-24 13:08:18 +0000524
Senthil Kumaran5466bf12010-12-18 16:55:23 +0000525 # Test lines overflowing the max line size (_MAXLINE in http.client)
526
527 def test_overflowing_status_line(self):
528 body = "HTTP/1.1 200 Ok" + "k" * 65536 + "\r\n"
529 resp = client.HTTPResponse(FakeSocket(body))
530 self.assertRaises((client.LineTooLong, client.BadStatusLine), resp.begin)
531
532 def test_overflowing_header_line(self):
533 body = (
534 'HTTP/1.1 200 OK\r\n'
535 'X-Foo: bar' + 'r' * 65536 + '\r\n\r\n'
536 )
537 resp = client.HTTPResponse(FakeSocket(body))
538 self.assertRaises(client.LineTooLong, resp.begin)
539
540 def test_overflowing_chunked_line(self):
541 body = (
542 'HTTP/1.1 200 OK\r\n'
543 'Transfer-Encoding: chunked\r\n\r\n'
544 + '0' * 65536 + 'a\r\n'
545 'hello world\r\n'
546 '0\r\n'
547 )
548 resp = client.HTTPResponse(FakeSocket(body))
549 resp.begin()
550 self.assertRaises(client.LineTooLong, resp.read)
551
Senthil Kumaran9c29f862012-04-29 10:20:46 +0800552 def test_early_eof(self):
553 # Test httpresponse with no \r\n termination,
554 body = "HTTP/1.1 200 Ok"
555 sock = FakeSocket(body)
556 resp = client.HTTPResponse(sock)
557 resp.begin()
558 self.assertEqual(resp.read(), b'')
559 self.assertTrue(resp.isclosed())
560
Georg Brandl4cbd1e32006-02-17 22:01:08 +0000561class OfflineTest(TestCase):
562 def test_responses(self):
Ezio Melottib3aedd42010-11-20 19:04:17 +0000563 self.assertEqual(client.responses[client.NOT_FOUND], "Not Found")
Georg Brandl4cbd1e32006-02-17 22:01:08 +0000564
Gregory P. Smithb4066372010-01-03 03:28:29 +0000565
566class SourceAddressTest(TestCase):
567 def setUp(self):
568 self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
569 self.port = support.bind_port(self.serv)
570 self.source_port = support.find_unused_port()
571 self.serv.listen(5)
572 self.conn = None
573
574 def tearDown(self):
575 if self.conn:
576 self.conn.close()
577 self.conn = None
578 self.serv.close()
579 self.serv = None
580
581 def testHTTPConnectionSourceAddress(self):
582 self.conn = client.HTTPConnection(HOST, self.port,
583 source_address=('', self.source_port))
584 self.conn.connect()
585 self.assertEqual(self.conn.sock.getsockname()[1], self.source_port)
586
587 @unittest.skipIf(not hasattr(client, 'HTTPSConnection'),
588 'http.client.HTTPSConnection not defined')
589 def testHTTPSConnectionSourceAddress(self):
590 self.conn = client.HTTPSConnection(HOST, self.port,
591 source_address=('', self.source_port))
592 # We don't test anything here other the constructor not barfing as
593 # this code doesn't deal with setting up an active running SSL server
594 # for an ssl_wrapped connect() to actually return from.
595
596
Guido van Rossumd8faa362007-04-27 19:54:29 +0000597class TimeoutTest(TestCase):
Christian Heimes5e696852008-04-09 08:37:03 +0000598 PORT = None
Guido van Rossumd8faa362007-04-27 19:54:29 +0000599
600 def setUp(self):
601 self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000602 TimeoutTest.PORT = support.bind_port(self.serv)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000603 self.serv.listen(5)
604
605 def tearDown(self):
606 self.serv.close()
607 self.serv = None
608
609 def testTimeoutAttribute(self):
Jeremy Hylton3a38c912007-08-14 17:08:07 +0000610 # This will prove that the timeout gets through HTTPConnection
611 # and into the socket.
612
Georg Brandlf78e02b2008-06-10 17:40:04 +0000613 # default -- use global socket timeout
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000614 self.assertTrue(socket.getdefaulttimeout() is None)
Georg Brandlf78e02b2008-06-10 17:40:04 +0000615 socket.setdefaulttimeout(30)
616 try:
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000617 httpConn = client.HTTPConnection(HOST, TimeoutTest.PORT)
Georg Brandlf78e02b2008-06-10 17:40:04 +0000618 httpConn.connect()
619 finally:
620 socket.setdefaulttimeout(None)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000621 self.assertEqual(httpConn.sock.gettimeout(), 30)
622 httpConn.close()
623
Georg Brandlf78e02b2008-06-10 17:40:04 +0000624 # no timeout -- do not use global socket default
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000625 self.assertTrue(socket.getdefaulttimeout() is None)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000626 socket.setdefaulttimeout(30)
627 try:
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000628 httpConn = client.HTTPConnection(HOST, TimeoutTest.PORT,
Christian Heimes5e696852008-04-09 08:37:03 +0000629 timeout=None)
Guido van Rossumd8faa362007-04-27 19:54:29 +0000630 httpConn.connect()
631 finally:
Georg Brandlf78e02b2008-06-10 17:40:04 +0000632 socket.setdefaulttimeout(None)
633 self.assertEqual(httpConn.sock.gettimeout(), None)
634 httpConn.close()
635
636 # a value
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000637 httpConn = client.HTTPConnection(HOST, TimeoutTest.PORT, timeout=30)
Georg Brandlf78e02b2008-06-10 17:40:04 +0000638 httpConn.connect()
Guido van Rossumd8faa362007-04-27 19:54:29 +0000639 self.assertEqual(httpConn.sock.gettimeout(), 30)
640 httpConn.close()
641
Antoine Pitrou803e6d62010-10-13 10:36:15 +0000642
643class HTTPSTest(TestCase):
644
645 def setUp(self):
646 if not hasattr(client, 'HTTPSConnection'):
647 self.skipTest('ssl support required')
648
649 def make_server(self, certfile):
650 from test.ssl_servers import make_https_server
651 return make_https_server(self, certfile)
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000652
653 def test_attributes(self):
Antoine Pitrou803e6d62010-10-13 10:36:15 +0000654 # simple test to check it's storing the timeout
655 h = client.HTTPSConnection(HOST, TimeoutTest.PORT, timeout=30)
656 self.assertEqual(h.timeout, 30)
657
658 def _check_svn_python_org(self, resp):
659 # Just a simple check that everything went fine
660 server_string = resp.getheader('server')
661 self.assertIn('Apache', server_string)
662
663 def test_networked(self):
664 # Default settings: no cert verification is done
665 support.requires('network')
666 with support.transient_internet('svn.python.org'):
667 h = client.HTTPSConnection('svn.python.org', 443)
668 h.request('GET', '/')
669 resp = h.getresponse()
670 self._check_svn_python_org(resp)
671
672 def test_networked_good_cert(self):
673 # We feed a CA cert that validates the server's cert
674 import ssl
675 support.requires('network')
676 with support.transient_internet('svn.python.org'):
677 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
678 context.verify_mode = ssl.CERT_REQUIRED
679 context.load_verify_locations(CACERT_svn_python_org)
680 h = client.HTTPSConnection('svn.python.org', 443, context=context)
681 h.request('GET', '/')
682 resp = h.getresponse()
683 self._check_svn_python_org(resp)
684
685 def test_networked_bad_cert(self):
686 # We feed a "CA" cert that is unrelated to the server's cert
687 import ssl
688 support.requires('network')
689 with support.transient_internet('svn.python.org'):
690 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
691 context.verify_mode = ssl.CERT_REQUIRED
692 context.load_verify_locations(CERT_localhost)
693 h = client.HTTPSConnection('svn.python.org', 443, context=context)
694 with self.assertRaises(ssl.SSLError):
695 h.request('GET', '/')
696
697 def test_local_good_hostname(self):
698 # The (valid) cert validates the HTTP hostname
699 import ssl
Brett Cannon252365b2011-08-04 22:43:11 -0700700 server = self.make_server(CERT_localhost)
Antoine Pitrou803e6d62010-10-13 10:36:15 +0000701 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
702 context.verify_mode = ssl.CERT_REQUIRED
703 context.load_verify_locations(CERT_localhost)
704 h = client.HTTPSConnection('localhost', server.port, context=context)
705 h.request('GET', '/nonexistent')
706 resp = h.getresponse()
707 self.assertEqual(resp.status, 404)
Brett Cannon252365b2011-08-04 22:43:11 -0700708 del server
Antoine Pitrou803e6d62010-10-13 10:36:15 +0000709
710 def test_local_bad_hostname(self):
711 # The (valid) cert doesn't validate the HTTP hostname
712 import ssl
Brett Cannon252365b2011-08-04 22:43:11 -0700713 server = self.make_server(CERT_fakehostname)
Antoine Pitrou803e6d62010-10-13 10:36:15 +0000714 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
715 context.verify_mode = ssl.CERT_REQUIRED
716 context.load_verify_locations(CERT_fakehostname)
717 h = client.HTTPSConnection('localhost', server.port, context=context)
718 with self.assertRaises(ssl.CertificateError):
719 h.request('GET', '/')
720 # Same with explicit check_hostname=True
721 h = client.HTTPSConnection('localhost', server.port, context=context,
722 check_hostname=True)
723 with self.assertRaises(ssl.CertificateError):
724 h.request('GET', '/')
725 # With check_hostname=False, the mismatching is ignored
726 h = client.HTTPSConnection('localhost', server.port, context=context,
727 check_hostname=False)
728 h.request('GET', '/nonexistent')
729 resp = h.getresponse()
730 self.assertEqual(resp.status, 404)
Brett Cannon252365b2011-08-04 22:43:11 -0700731 del server
Antoine Pitrou803e6d62010-10-13 10:36:15 +0000732
Petri Lehtinene119c402011-10-26 21:29:15 +0300733 @unittest.skipIf(not hasattr(client, 'HTTPSConnection'),
734 'http.client.HTTPSConnection not available')
Łukasz Langaa5a9a9c2011-10-18 21:17:39 +0200735 def test_host_port(self):
736 # Check invalid host_port
737
738 for hp in ("www.python.org:abc", "user:password@www.python.org"):
739 self.assertRaises(client.InvalidURL, client.HTTPSConnection, hp)
740
741 for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000",
742 "fe80::207:e9ff:fe9b", 8000),
743 ("www.python.org:443", "www.python.org", 443),
744 ("www.python.org:", "www.python.org", 443),
745 ("www.python.org", "www.python.org", 443),
746 ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 443),
747 ("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b",
748 443)):
749 c = client.HTTPSConnection(hp)
750 self.assertEqual(h, c.host)
751 self.assertEqual(p, c.port)
752
Guido van Rossumd59da4b2007-05-22 18:11:13 +0000753
Jeremy Hylton236654b2009-03-27 20:24:34 +0000754class RequestBodyTest(TestCase):
755 """Test cases where a request includes a message body."""
756
757 def setUp(self):
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000758 self.conn = client.HTTPConnection('example.com')
Jeremy Hylton636950f2009-03-28 04:34:21 +0000759 self.conn.sock = self.sock = FakeSocket("")
Jeremy Hylton236654b2009-03-27 20:24:34 +0000760 self.conn.sock = self.sock
761
762 def get_headers_and_fp(self):
763 f = io.BytesIO(self.sock.data)
764 f.readline() # read the request line
Jeremy Hylton7c1692d2009-03-27 21:31:03 +0000765 message = client.parse_headers(f)
Jeremy Hylton236654b2009-03-27 20:24:34 +0000766 return message, f
767
768 def test_manual_content_length(self):
769 # Set an incorrect content-length so that we can verify that
770 # it will not be over-ridden by the library.
771 self.conn.request("PUT", "/url", "body",
772 {"Content-Length": "42"})
773 message, f = self.get_headers_and_fp()
774 self.assertEqual("42", message.get("content-length"))
775 self.assertEqual(4, len(f.read()))
776
777 def test_ascii_body(self):
778 self.conn.request("PUT", "/url", "body")
779 message, f = self.get_headers_and_fp()
780 self.assertEqual("text/plain", message.get_content_type())
Raymond Hettinger7beae8a2011-01-06 05:34:17 +0000781 self.assertIsNone(message.get_charset())
Jeremy Hylton236654b2009-03-27 20:24:34 +0000782 self.assertEqual("4", message.get("content-length"))
783 self.assertEqual(b'body', f.read())
784
785 def test_latin1_body(self):
786 self.conn.request("PUT", "/url", "body\xc1")
787 message, f = self.get_headers_and_fp()
788 self.assertEqual("text/plain", message.get_content_type())
Raymond Hettinger7beae8a2011-01-06 05:34:17 +0000789 self.assertIsNone(message.get_charset())
Jeremy Hylton236654b2009-03-27 20:24:34 +0000790 self.assertEqual("5", message.get("content-length"))
791 self.assertEqual(b'body\xc1', f.read())
792
793 def test_bytes_body(self):
794 self.conn.request("PUT", "/url", b"body\xc1")
795 message, f = self.get_headers_and_fp()
796 self.assertEqual("text/plain", message.get_content_type())
Raymond Hettinger7beae8a2011-01-06 05:34:17 +0000797 self.assertIsNone(message.get_charset())
Jeremy Hylton236654b2009-03-27 20:24:34 +0000798 self.assertEqual("5", message.get("content-length"))
799 self.assertEqual(b'body\xc1', f.read())
800
801 def test_file_body(self):
Victor Stinner18d15cb2011-09-21 01:09:04 +0200802 self.addCleanup(support.unlink, support.TESTFN)
Brett Cannon77b7de62010-10-29 23:31:11 +0000803 with open(support.TESTFN, "w") as f:
804 f.write("body")
805 with open(support.TESTFN) as f:
806 self.conn.request("PUT", "/url", f)
807 message, f = self.get_headers_and_fp()
808 self.assertEqual("text/plain", message.get_content_type())
Raymond Hettinger7beae8a2011-01-06 05:34:17 +0000809 self.assertIsNone(message.get_charset())
Brett Cannon77b7de62010-10-29 23:31:11 +0000810 self.assertEqual("4", message.get("content-length"))
811 self.assertEqual(b'body', f.read())
Jeremy Hylton236654b2009-03-27 20:24:34 +0000812
813 def test_binary_file_body(self):
Victor Stinner18d15cb2011-09-21 01:09:04 +0200814 self.addCleanup(support.unlink, support.TESTFN)
Brett Cannon77b7de62010-10-29 23:31:11 +0000815 with open(support.TESTFN, "wb") as f:
816 f.write(b"body\xc1")
817 with open(support.TESTFN, "rb") as f:
818 self.conn.request("PUT", "/url", f)
819 message, f = self.get_headers_and_fp()
820 self.assertEqual("text/plain", message.get_content_type())
Raymond Hettinger7beae8a2011-01-06 05:34:17 +0000821 self.assertIsNone(message.get_charset())
Brett Cannon77b7de62010-10-29 23:31:11 +0000822 self.assertEqual("5", message.get("content-length"))
823 self.assertEqual(b'body\xc1', f.read())
Jeremy Hylton236654b2009-03-27 20:24:34 +0000824
Senthil Kumaran9f8dc442010-08-02 11:04:58 +0000825
826class HTTPResponseTest(TestCase):
827
828 def setUp(self):
829 body = "HTTP/1.1 200 Ok\r\nMy-Header: first-value\r\nMy-Header: \
830 second-value\r\n\r\nText"
831 sock = FakeSocket(body)
832 self.resp = client.HTTPResponse(sock)
833 self.resp.begin()
834
835 def test_getting_header(self):
836 header = self.resp.getheader('My-Header')
837 self.assertEqual(header, 'first-value, second-value')
838
839 header = self.resp.getheader('My-Header', 'some default')
840 self.assertEqual(header, 'first-value, second-value')
841
842 def test_getting_nonexistent_header_with_string_default(self):
843 header = self.resp.getheader('No-Such-Header', 'default-value')
844 self.assertEqual(header, 'default-value')
845
846 def test_getting_nonexistent_header_with_iterable_default(self):
847 header = self.resp.getheader('No-Such-Header', ['default', 'values'])
848 self.assertEqual(header, 'default, values')
849
850 header = self.resp.getheader('No-Such-Header', ('default', 'values'))
851 self.assertEqual(header, 'default, values')
852
853 def test_getting_nonexistent_header_without_default(self):
854 header = self.resp.getheader('No-Such-Header')
855 self.assertEqual(header, None)
856
857 def test_getting_header_defaultint(self):
858 header = self.resp.getheader('No-Such-Header',default=42)
859 self.assertEqual(header, 42)
860
Jeremy Hylton2c178252004-08-07 16:28:14 +0000861def test_main(verbose=None):
Benjamin Petersonee8712c2008-05-20 21:35:26 +0000862 support.run_unittest(HeaderTests, OfflineTest, BasicTest, TimeoutTest,
Antoine Pitrou803e6d62010-10-13 10:36:15 +0000863 HTTPSTest, RequestBodyTest, SourceAddressTest,
Senthil Kumaran9f8dc442010-08-02 11:04:58 +0000864 HTTPResponseTest)
Jeremy Hylton2c178252004-08-07 16:28:14 +0000865
Thomas Wouters89f507f2006-12-13 04:49:30 +0000866if __name__ == '__main__':
867 test_main()