mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix incorrect use of assertRaises
This commit is contained in:
parent
1e8c38d994
commit
e03e50730d
@ -125,13 +125,16 @@ class HTTPHeaderParser(object):
|
|||||||
val = existing + ', ' + val
|
val = existing + ', ' + val
|
||||||
self.hdict[key] = val
|
self.hdict[key] = val
|
||||||
|
|
||||||
|
if self.finished:
|
||||||
|
raise ValueError('Header block already terminated')
|
||||||
|
|
||||||
if line == b'\r\n':
|
if line == b'\r\n':
|
||||||
# Normal end of headers
|
# Normal end of headers
|
||||||
commit()
|
commit()
|
||||||
self.finished = True
|
self.finished = True
|
||||||
return
|
return
|
||||||
|
|
||||||
if line[0] in b' \t':
|
if line and line[0] in b' \t':
|
||||||
# It's a continuation line.
|
# It's a continuation line.
|
||||||
if not self.lines:
|
if not self.lines:
|
||||||
raise ValueError('Orphaned continuation line')
|
raise ValueError('Orphaned continuation line')
|
||||||
|
@ -42,16 +42,16 @@ class TestHTTP(BaseTest):
|
|||||||
'accept-Encoding: two',
|
'accept-Encoding: two',
|
||||||
'\r\n', accept_encoding='one, two')
|
'\r\n', accept_encoding='one, two')
|
||||||
|
|
||||||
def parse(line):
|
def parse(*lines):
|
||||||
HTTPHeaderParser()(line)
|
lines = list(lines)
|
||||||
|
lines.append(b'\r\n')
|
||||||
|
self.assertRaises(ValueError, HTTPHeaderParser().push, *lines)
|
||||||
|
|
||||||
with self.assertRaises(ValueError):
|
parse(b'Connection:mūs\r\n')
|
||||||
parse('Connection:mūs\r\n')
|
parse(b'Connection\r\n')
|
||||||
parse('Connection\r\n')
|
parse(b'Connection:a\r\n', b'\r\n')
|
||||||
parse('Connection:a\r\n')
|
parse(b' Connection:a\n')
|
||||||
parse('Connection:a\n')
|
parse(b':a\n')
|
||||||
parse(' Connection:a\n')
|
|
||||||
parse(':a\n')
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def test_accept_encoding(self): # {{{
|
def test_accept_encoding(self): # {{{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user