Remove old-style set-cookie cruft, unit tests to 100%

This commit is contained in:
Aldo Cortesi 2015-04-14 10:13:03 +12:00
parent de9e741125
commit 6db5e0a4a1
2 changed files with 9 additions and 11 deletions

View File

@ -88,14 +88,12 @@ def _read_value(s, start, delims):
return _read_until(s, start, delims) return _read_until(s, start, delims)
def _read_pairs(s, off=0, term=None, specials=()): def _read_pairs(s, off=0, specials=()):
""" """
Read pairs of lhs=rhs values. Read pairs of lhs=rhs values.
off: start offset off: start offset
term: if True, treat a comma as a terminator for the pairs lists specials: a lower-cased list of keys that may contain commas
specials: a lower-cased list of keys that may contain commas if term is
True
""" """
vals = [] vals = []
while 1: while 1:
@ -105,17 +103,11 @@ def _read_pairs(s, off=0, term=None, specials=()):
rhs = None rhs = None
if off < len(s): if off < len(s):
if s[off] == "=": if s[off] == "=":
if term and lhs.lower() not in specials: rhs, off = _read_value(s, off+1, ";")
delims = ";,"
else:
delims = ";"
rhs, off = _read_value(s, off+1, delims)
vals.append([lhs, rhs]) vals.append([lhs, rhs])
off += 1 off += 1
if not off < len(s): if not off < len(s):
break break
if term and s[off-1] == ",":
break
return vals, off return vals, off

View File

@ -155,6 +155,12 @@ def test_parse_set_cookie_pairs():
["one", "uno"] ["one", "uno"]
] ]
], ],
[
"one=un\x20",
[
["one", "un\x20"]
]
],
[ [
"one=uno; foo", "one=uno; foo",
[ [