keeping consistency, better testing

This commit is contained in:
kira0204 2018-02-11 17:25:44 +05:30
parent 4e9d4b37b3
commit 06f689aa34
3 changed files with 47 additions and 36 deletions

View File

@ -114,8 +114,7 @@ def _read_cookie_pairs(s, off=0):
lhs, off = _read_key(s, off) lhs, off = _read_key(s, off)
lhs = lhs.lstrip() lhs = lhs.lstrip()
if lhs is not None: rhs = ""
rhs = None
if off < len(s) and s[off] == "=": if off < len(s) and s[off] == "=":
rhs, off = _read_value(s, off + 1, ";") rhs, off = _read_value(s, off + 1, ";")
if rhs or lhs: if rhs or lhs:
@ -143,8 +142,7 @@ def _read_set_cookie_pairs(s: str, off=0) -> Tuple[List[TPairs], int]:
lhs, off = _read_key(s, off, ";=,") lhs, off = _read_key(s, off, ";=,")
lhs = lhs.lstrip() lhs = lhs.lstrip()
if lhs is not None: rhs = ""
rhs = None
if off < len(s) and s[off] == "=": if off < len(s) and s[off] == "=":
rhs, off = _read_value(s, off + 1, ";,") rhs, off = _read_value(s, off + 1, ";,")
@ -196,9 +194,6 @@ def _format_pairs(pairs, specials=(), sep="; "):
""" """
vals = [] vals = []
for k, v in pairs: for k, v in pairs:
if v is None:
vals.append(k)
else:
if k.lower() not in specials and _has_special(v): if k.lower() not in specials and _has_special(v):
v = ESCAPE.sub(r"\\\1", v) v = ESCAPE.sub(r"\\\1", v)
v = '"%s"' % v v = '"%s"' % v

View File

@ -20,7 +20,7 @@ cookie_pairs = [
], ],
[ [
"one", "one",
[["one", None]] [["one", ""]]
], ],
[ [
"one=uno; two=due", "one=uno; two=due",
@ -40,7 +40,7 @@ cookie_pairs = [
], ],
[ [
"one=uno; two; three=tre", "one=uno; two; three=tre",
[["one", "uno"], ["two", None], ["three", "tre"]] [["one", "uno"], ["two", ""], ["three", "tre"]]
], ],
[ [
"_lvs2=zHai1+Hq+Tc2vmc2r4GAbdOI5Jopg3EwsdUT9g=; " "_lvs2=zHai1+Hq+Tc2vmc2r4GAbdOI5Jopg3EwsdUT9g=; "
@ -82,9 +82,13 @@ def test_read_quoted_string():
def test_read_cookie_pairs(): def test_read_cookie_pairs():
vals = [ vals = [
[
"=uno",
[["", "uno"]]
],
[ [
"one", "one",
[["one", None]] [["one", ""]]
], ],
[ [
"one=two", "one=two",
@ -104,7 +108,7 @@ def test_read_cookie_pairs():
], ],
[ [
'one="two"; three=four; five', 'one="two"; three=four; five',
[["one", "two"], ["three", "four"], ["five", None]] [["one", "two"], ["three", "four"], ["five", ""]]
], ],
[ [
'one="\\"two"; three=four', 'one="\\"two"; three=four',
@ -138,6 +142,12 @@ def test_cookie_roundtrips():
def test_parse_set_cookie_pairs(): def test_parse_set_cookie_pairs():
pairs = [ pairs = [
[
"=uno",
[[
["", "uno"]
]]
],
[ [
"one=uno", "one=uno",
[[ [[
@ -154,7 +164,7 @@ def test_parse_set_cookie_pairs():
"one=uno; foo", "one=uno; foo",
[[ [[
["one", "uno"], ["one", "uno"],
["foo", None] ["foo", ""]
]] ]]
], ],
[ [
@ -203,6 +213,12 @@ def test_parse_set_cookie_header():
[ [
";", [] ";", []
], ],
[
"=uno",
[
("", "uno", ())
]
],
[ [
"one=uno", "one=uno",
[ [

View File

@ -113,7 +113,7 @@ class TestResponseUtils:
assert attrs["domain"] == "example.com" assert attrs["domain"] == "example.com"
assert attrs["expires"] == "Wed Oct 21 16:29:41 2015" assert attrs["expires"] == "Wed Oct 21 16:29:41 2015"
assert attrs["path"] == "/" assert attrs["path"] == "/"
assert attrs["httponly"] is None assert attrs["httponly"] == ""
def test_get_cookies_no_value(self): def test_get_cookies_no_value(self):
resp = tresp() resp = tresp()