Fix incorrect use of assertRaises

This commit is contained in:
Kovid Goyal 2015-06-01 12:24:55 +05:30
parent 1e8c38d994
commit e03e50730d
2 changed files with 13 additions and 10 deletions

View File

@ -125,13 +125,16 @@ class HTTPHeaderParser(object):
val = existing + ', ' + val
self.hdict[key] = val
if self.finished:
raise ValueError('Header block already terminated')
if line == b'\r\n':
# Normal end of headers
commit()
self.finished = True
return
if line[0] in b' \t':
if line and line[0] in b' \t':
# It's a continuation line.
if not self.lines:
raise ValueError('Orphaned continuation line')

View File

@ -42,16 +42,16 @@ class TestHTTP(BaseTest):
'accept-Encoding: two',
'\r\n', accept_encoding='one, two')
def parse(line):
HTTPHeaderParser()(line)
def parse(*lines):
lines = list(lines)
lines.append(b'\r\n')
self.assertRaises(ValueError, HTTPHeaderParser().push, *lines)
with self.assertRaises(ValueError):
parse('Connection:mūs\r\n')
parse('Connection\r\n')
parse('Connection:a\r\n')
parse('Connection:a\n')
parse(' Connection:a\n')
parse(':a\n')
parse(b'Connection:mūs\r\n')
parse(b'Connection\r\n')
parse(b'Connection:a\r\n', b'\r\n')
parse(b' Connection:a\n')
parse(b':a\n')
# }}}
def test_accept_encoding(self): # {{{