blob: 218ae9c163131b9207d45bd09fe78ee3c7db3ec7 [file] [log] [blame]
Tim Petersd48004f2001-09-25 19:29:35 +00001from test_support import verify,verbose
Jeremy Hylton79fa2b62001-04-13 14:57:44 +00002import httplib
3import StringIO
4
5class FakeSocket:
6 def __init__(self, text):
7 self.text = text
8
9 def makefile(self, mode, bufsize=None):
10 if mode != 'r' and mode != 'rb':
Neal Norwitz28bb5722002-04-01 19:00:50 +000011 raise httplib.UnimplementedFileMode()
Jeremy Hylton79fa2b62001-04-13 14:57:44 +000012 return StringIO.StringIO(self.text)
13
14# Test HTTP status lines
15
16body = "HTTP/1.1 200 Ok\r\n\r\nText"
17sock = FakeSocket(body)
18resp = httplib.HTTPResponse(sock,1)
19resp.begin()
20print resp.read()
21resp.close()
22
23body = "HTTP/1.1 400.100 Not Ok\r\n\r\nText"
24sock = FakeSocket(body)
25resp = httplib.HTTPResponse(sock,1)
26try:
27 resp.begin()
28except httplib.BadStatusLine:
29 print "BadStatusLine raised as expected"
30else:
31 print "Expect BadStatusLine"
Skip Montanaro03ff86d2002-03-24 16:54:16 +000032
33# Check invalid host_port
34
35for hp in ("www.python.org:abc", "www.python.org:"):
36 try:
37 h = httplib.HTTP(hp)
38 except httplib.InvalidURL:
39 print "InvalidURL raised as expected"
40 else:
41 print "Expect InvalidURL"