py-cvs-rel2_1 (Rev 1.2) merge
[python/dscho.git] / Lib / test / test_httplib.py
blobaef65a68112e399a96a38ffedd54bb43e9e1d728
1 from test.test_support import verify,verbose
2 import httplib
3 import StringIO
5 class FakeSocket:
6 def __init__(self, text):
7 self.text = text
9 def makefile(self, mode, bufsize=None):
10 if mode != 'r' and mode != 'rb':
11 raise UnimplementedFileMode()
12 return StringIO.StringIO(self.text)
14 # Test HTTP status lines
16 body = "HTTP/1.1 200 Ok\r\n\r\nText"
17 sock = FakeSocket(body)
18 resp = httplib.HTTPResponse(sock,1)
19 resp.begin()
20 print resp.read()
21 resp.close()
23 body = "HTTP/1.1 400.100 Not Ok\r\n\r\nText"
24 sock = FakeSocket(body)
25 resp = httplib.HTTPResponse(sock,1)
26 try:
27 resp.begin()
28 except httplib.BadStatusLine:
29 print "BadStatusLine raised as expected"
30 else:
31 print "Expect BadStatusLine"