From 070aa27cf5f88d2036c88c110e00421c427c0c9b Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 28 Sep 2016 15:10:31 +1000 Subject: parse_set_cookie header returns an empty list if no cookies are found This matches parse_cookie, and is more idiomatic. --- netlib/http/cookies.py | 13 ++++--------- test/netlib/http/test_cookies.py | 6 +++--- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/netlib/http/cookies.py b/netlib/http/cookies.py index a3ac4806..cb816ca0 100644 --- a/netlib/http/cookies.py +++ b/netlib/http/cookies.py @@ -241,21 +241,16 @@ def parse_set_cookie_header(line): """ Parse a Set-Cookie header value - Returns a list of (name, value, attrs) tuple for each cokie, or None. - Where attrs is a CookieAttrs dict of attributes. No attempt is made - to parse attribute values - they are treated purely as strings. + Returns a list of (name, value, attrs) tuples, where attrs is a + CookieAttrs dict of attributes. No attempt is made to parse attribute + values - they are treated purely as strings. """ cookie_pairs, off = _read_set_cookie_pairs(line) - cookies = [ (pairs[0][0], pairs[0][1], CookieAttrs(tuple(x) for x in pairs[1:])) for pairs in cookie_pairs if pairs ] - - if cookies: - return cookies - else: - return None + return cookies def parse_set_cookie_headers(headers): diff --git a/test/netlib/http/test_cookies.py b/test/netlib/http/test_cookies.py index 905f549c..80ffb0a6 100644 --- a/test/netlib/http/test_cookies.py +++ b/test/netlib/http/test_cookies.py @@ -194,10 +194,10 @@ def test_parse_set_cookie_header(): vals = [ [ - "", None + "", [] ], [ - ";", None + ";", [] ], [ "one=uno", @@ -257,7 +257,7 @@ def test_parse_set_cookie_header(): for i in range(len(expected)): set_cookie_equal(ret2[i], expected[i]) else: - assert ret is None + assert not ret def test_refresh_cookie(): -- cgit v1.2.3