Merge "swob.Match: remove quotes when checking __contains__"
This commit is contained in:
commit
cb3692f8db
@ -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):
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user