swob.Match: remove quotes when checking __contains__

If we're going to drop the quotes during initialization, we should
probably drop them when making comparisons, too.

Change-Id: I90c6e8a7c6faf8fafb0cd64fabbc9629d6c4c48a
This commit is contained in:
Tim Burke 2018-03-26 21:49:12 +00:00
parent 4c2ef69d31
commit 158d4c28b2
2 changed files with 17 additions and 0 deletions

View File

@ -651,6 +651,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):