home *** CD-ROM | disk | FTP | other *** search
/ Freelog 33 / Freelog033.iso / Progr / Python-2.2.1.exe / TEST_HTTPLIB.PY < prev    next >
Encoding:
Python Source  |  2001-09-25  |  758 b   |  32 lines

  1. from test_support import verify,verbose
  2. import httplib
  3. import StringIO
  4.  
  5. class 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':
  11.             raise UnimplementedFileMode()
  12.         return StringIO.StringIO(self.text)
  13.  
  14. # Test HTTP status lines
  15.  
  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()
  22.  
  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"
  32.