1 from test
.test_support
import verify
,verbose
6 def __init__(self
, text
):
9 def makefile(self
, mode
, bufsize
=None):
10 if mode
!= 'r' and mode
!= 'rb':
11 raise httplib
.UnimplementedFileMode()
12 return StringIO
.StringIO(self
.text
)
14 # Collect output to a buffer so that we don't have to cope with line-ending
15 # issues across platforms. Specifically, the headers will have \r\n pairs
16 # and some platforms will strip them from the output file.
21 buf
= StringIO
.StringIO()
29 # print individual lines with endings stripped
31 for line
in s
.split("\n"):
35 # Test HTTP status lines
37 body
= "HTTP/1.1 200 Ok\r\n\r\nText"
38 sock
= FakeSocket(body
)
39 resp
= httplib
.HTTPResponse(sock
, 1)
44 body
= "HTTP/1.1 400.100 Not Ok\r\n\r\nText"
45 sock
= FakeSocket(body
)
46 resp
= httplib
.HTTPResponse(sock
, 1)
49 except httplib
.BadStatusLine
:
50 print "BadStatusLine raised as expected"
52 print "Expect BadStatusLine"
54 # Check invalid host_port
56 for hp
in ("www.python.org:abc", "www.python.org:"):
59 except httplib
.InvalidURL
:
60 print "InvalidURL raised as expected"
62 print "Expect InvalidURL"
64 # test response with multiple message headers with the same field name.
65 text
= ('HTTP/1.1 200 OK\r\n'
66 'Set-Cookie: Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"\r\n'
67 'Set-Cookie: Part_Number="Rocket_Launcher_0001"; Version="1";'
71 hdr
= ('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"'
73 'Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme"')
75 r
= httplib
.HTTPResponse(s
, 1)
77 cookies
= r
.getheader("Set-Cookie")
79 raise AssertionError, "multiple headers not combined properly"