Merge "swob.Match: remove quotes when checking __contains__"

This commit is contained in:
Zuul 2018-07-04 06:34:17 +00:00 committed by Gerrit Code Review
commit cb3692f8db
2 changed files with 17 additions and 0 deletions

View File

@ -665,6 +665,8 @@ class Match(object):
self.tags.add(tag)
def __contains__(self, val):
if val and val.startswith('"') and val.endswith('"'):
val = val[1:-1]
return '*' in self.tags or val in self.tags
def __repr__(self):

View File

@ -270,37 +270,52 @@ class TestMatch(unittest.TestCase):
match = swift.common.swob.Match('"a", "b"')
self.assertEqual(match.tags, set(('a', 'b')))
self.assertIn('a', match)
self.assertIn('"a"', match)
self.assertNotIn('""a""', match)
self.assertIn('b', match)
self.assertNotIn('c', match)
self.assertNotIn(None, match)
self.assertEqual(repr(match), "Match('a, b')")
def test_match_star(self):
match = swift.common.swob.Match('"a", "*"')
self.assertIn('a', match)
self.assertIn('"a"', match)
self.assertIn('""a""', match)
self.assertIn('b', match)
self.assertIn('c', match)
self.assertIn(None, match)
self.assertEqual(repr(match), "Match('*, a')")
def test_match_noquote(self):
match = swift.common.swob.Match('a, b')
self.assertEqual(match.tags, set(('a', 'b')))
self.assertIn('a', match)
self.assertIn('"a"', match)
self.assertNotIn('""a""', match)
self.assertIn('b', match)
self.assertNotIn('c', match)
self.assertNotIn(None, match)
def test_match_no_optional_white_space(self):
match = swift.common.swob.Match('"a","b"')
self.assertEqual(match.tags, set(('a', 'b')))
self.assertIn('a', match)
self.assertIn('"a"', match)
self.assertNotIn('""a""', match)
self.assertIn('b', match)
self.assertNotIn('c', match)
self.assertNotIn(None, match)
def test_match_lots_of_optional_white_space(self):
match = swift.common.swob.Match('"a" , , "b" ')
self.assertEqual(match.tags, set(('a', 'b')))
self.assertIn('a', match)
self.assertIn('"a"', match)
self.assertNotIn('""a""', match)
self.assertIn('b', match)
self.assertNotIn('c', match)
self.assertNotIn(None, match)
class TestTransferEncoding(unittest.TestCase):