parse_tag_value now deals with bytes.
This commit is contained in:
+12
-12
@@ -30,38 +30,38 @@ class TestParseTagValue(unittest.TestCase):
|
||||
|
||||
def test_single(self):
|
||||
self.assertEqual(
|
||||
{'foo': 'bar'},
|
||||
parse_tag_value('foo=bar'))
|
||||
{b'foo': b'bar'},
|
||||
parse_tag_value(b'foo=bar'))
|
||||
|
||||
def test_trailing_separator_ignored(self):
|
||||
self.assertEqual(
|
||||
{'foo': 'bar'},
|
||||
parse_tag_value('foo=bar;'))
|
||||
{b'foo': b'bar'},
|
||||
parse_tag_value(b'foo=bar;'))
|
||||
|
||||
def test_multiple(self):
|
||||
self.assertEqual(
|
||||
{'foo': 'bar', 'baz': 'foo'},
|
||||
parse_tag_value('foo=bar;baz=foo'))
|
||||
{b'foo': b'bar', b'baz': b'foo'},
|
||||
parse_tag_value(b'foo=bar;baz=foo'))
|
||||
|
||||
def test_value_with_equals(self):
|
||||
self.assertEqual(
|
||||
{'foo': 'bar', 'baz': 'foo=bar'},
|
||||
parse_tag_value('foo=bar;baz=foo=bar'))
|
||||
{b'foo': b'bar', b'baz': b'foo=bar'},
|
||||
parse_tag_value(b'foo=bar;baz=foo=bar'))
|
||||
|
||||
def test_whitespace_is_stripped(self):
|
||||
self.assertEqual(
|
||||
{'foo': 'bar', 'baz': 'f oo=bar'},
|
||||
parse_tag_value(' foo \t= bar;\tbaz= f oo=bar '))
|
||||
{b'foo': b'bar', b'baz': b'f oo=bar'},
|
||||
parse_tag_value(b' foo \t= bar;\tbaz= f oo=bar '))
|
||||
|
||||
def test_missing_value_is_an_error(self):
|
||||
self.assertRaisesRegexp(
|
||||
InvalidTagSpec, 'baz',
|
||||
parse_tag_value, 'foo=bar;baz')
|
||||
parse_tag_value, b'foo=bar;baz')
|
||||
|
||||
def test_duplicate_tag_is_an_error(self):
|
||||
self.assertRaisesRegexp(
|
||||
DuplicateTag, 'foo',
|
||||
parse_tag_value, 'foo=bar;foo=baz')
|
||||
parse_tag_value, b'foo=bar;foo=baz')
|
||||
|
||||
|
||||
def test_suite():
|
||||
|
||||
+2
-2
@@ -55,13 +55,13 @@ def parse_tag_value(tag_list):
|
||||
@param tag_list: A string containing a DKIM Tag=Value list.
|
||||
"""
|
||||
tags = {}
|
||||
tag_specs = tag_list.split(';')
|
||||
tag_specs = tag_list.split(b';')
|
||||
# Trailing semicolons are valid.
|
||||
if not tag_specs[-1]:
|
||||
tag_specs.pop()
|
||||
for tag_spec in tag_specs:
|
||||
try:
|
||||
key, value = tag_spec.split('=', 1)
|
||||
key, value = tag_spec.split(b'=', 1)
|
||||
except ValueError:
|
||||
raise InvalidTagSpec(tag_spec)
|
||||
if key.strip() in tags:
|
||||
|
||||
Reference in New Issue
Block a user