From a6a179c5ad1e011a73610588de3046487244bed1 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 7 Jul 2014 21:25:28 -0700 Subject: [PATCH] seems .splitlines() has bug use .split() instead #97 --- aiohttp/__init__.py | 2 +- aiohttp/protocol.py | 10 +++++----- tests/test_http_parser.py | 22 +++++++++++----------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/aiohttp/__init__.py b/aiohttp/__init__.py index d7c5f6eba88..3ba356f839d 100644 --- a/aiohttp/__init__.py +++ b/aiohttp/__init__.py @@ -1,6 +1,6 @@ # This relies on each of the submodules having an __all__ variable. -__version__ = '0.9.0dev' +__version__ = '0.9.0dev2' from .protocol import * diff --git a/aiohttp/protocol.py b/aiohttp/protocol.py index e3f77b88c7e..a0ae13215b6 100644 --- a/aiohttp/protocol.py +++ b/aiohttp/protocol.py @@ -60,7 +60,7 @@ def parse_headers(self, lines): lines_idx = 1 line = lines[1] - while line not in ('\r\n', '\n'): + while line: header_length = len(line) # Parse initial header name : value pair. @@ -78,7 +78,7 @@ def parse_headers(self, lines): line = lines[lines_idx] # consume continuation lines - continuation = line[0] in CONTINUATION + continuation = line and line[0] in CONTINUATION if continuation: value = [value] @@ -93,7 +93,7 @@ def parse_headers(self, lines): lines_idx += 1 line = lines[lines_idx] continuation = line[0] in CONTINUATION - value = ''.join(value) + value = '\r\n'.join(value) else: if header_length > self.max_field_size: raise errors.LineTooLong( @@ -156,7 +156,7 @@ def __call__(self, out, buf): raise errors.LineTooLong(exc.limit) from None lines = raw_data.decode( - 'ascii', 'surrogateescape').splitlines(True) + 'ascii', 'surrogateescape').split('\r\n') # request line line = lines[0] @@ -205,7 +205,7 @@ def __call__(self, out, buf): raise errors.LineTooLong(exc.limit) from None lines = raw_data.decode( - 'ascii', 'surrogateescape').splitlines(True) + 'ascii', 'surrogateescape').split('\r\n') line = lines[0] try: diff --git a/tests/test_http_parser.py b/tests/test_http_parser.py index aad3207ef24..0abbd64d9be 100644 --- a/tests/test_http_parser.py +++ b/tests/test_http_parser.py @@ -19,8 +19,8 @@ def setUp(self): self.parser = protocol.HttpParser(8190, 32768, 8190) def test_parse_headers(self): - hdrs = ('', 'test: line\r\n', ' continue\r\n', - 'test2: data\r\n', '\r\n') + hdrs = ('', 'test: line', ' continue', + 'test2: data', '', '') headers, close, compression = self.parser.parse_headers(hdrs) @@ -31,8 +31,8 @@ def test_parse_headers(self): def test_parse_headers_multi(self): hdrs = ('', - 'Set-Cookie: c1=cookie1\r\n', - 'Set-Cookie: c2=cookie2\r\n', '\r\n') + 'Set-Cookie: c1=cookie1', + 'Set-Cookie: c2=cookie2', '') headers, close, compression = self.parser.parse_headers(hdrs) @@ -44,32 +44,32 @@ def test_parse_headers_multi(self): def test_conn_close(self): headers, close, compression = self.parser.parse_headers( - ['', 'connection: close\r\n', '\r\n']) + ['', 'connection: close', '']) self.assertTrue(close) def test_conn_keep_alive(self): headers, close, compression = self.parser.parse_headers( - ['', 'connection: keep-alive\r\n', '\r\n']) + ['', 'connection: keep-alive', '']) self.assertFalse(close) def test_conn_other(self): headers, close, compression = self.parser.parse_headers( - ['', 'connection: test\r\n', '\r\n']) + ['', 'connection: test', '', '']) self.assertIsNone(close) def test_compression_gzip(self): headers, close, compression = self.parser.parse_headers( - ['', 'content-encoding: gzip\r\n', '\r\n']) + ['', 'content-encoding: gzip', '', '']) self.assertEqual('gzip', compression) def test_compression_deflate(self): headers, close, compression = self.parser.parse_headers( - ['', 'content-encoding: deflate\r\n', '\r\n']) + ['', 'content-encoding: deflate', '', '']) self.assertEqual('deflate', compression) def test_compression_unknown(self): headers, close, compression = self.parser.parse_headers( - ['', 'content-encoding: compress\r\n', '\r\n']) + ['', 'content-encoding: compress', '', '']) self.assertIsNone(compression) def test_max_field_size(self): @@ -480,7 +480,7 @@ def test_http_response_parser_bad_version(self): next(p) with self.assertRaises(errors.BadStatusLine) as cm: p.send(b'HT/11 200 Ok\r\n\r\n') - self.assertEqual('HT/11 200 Ok\r\n', cm.exception.args[0]) + self.assertEqual('HT/11 200 Ok', cm.exception.args[0]) def test_http_response_parser_no_reason(self): out = aiohttp.FlowControlDataQueue(self.stream)