mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-31672: Restore the former behavior when override flags in Template. (#5099)
Overriding flags to 0 will make the default pattern matching only lower case letters.
This commit is contained in:
parent
78e24d4415
commit
87be28f4a1
3 changed files with 21 additions and 11 deletions
|
@ -219,6 +219,16 @@ class TestTemplate(unittest.TestCase):
|
|||
self.assertRaises(KeyError, s.substitute,
|
||||
dict(who='tim', what='ham'))
|
||||
|
||||
def test_regular_templates_with_upper_case(self):
|
||||
s = Template('$WHO likes ${WHAT} for ${MEAL}')
|
||||
d = dict(WHO='tim', WHAT='ham', MEAL='dinner')
|
||||
self.assertEqual(s.substitute(d), 'tim likes ham for dinner')
|
||||
|
||||
def test_regular_templates_with_non_letters(self):
|
||||
s = Template('$_wh0_ likes ${_w_h_a_t_} for ${mea1}')
|
||||
d = dict(_wh0_='tim', _w_h_a_t_='ham', mea1='dinner')
|
||||
self.assertEqual(s.substitute(d), 'tim likes ham for dinner')
|
||||
|
||||
def test_escapes(self):
|
||||
eq = self.assertEqual
|
||||
s = Template('$who likes to eat a bag of $$what worth $$100')
|
||||
|
@ -288,6 +298,14 @@ class TestTemplate(unittest.TestCase):
|
|||
s = PathPattern('$bag.foo.who likes to eat a bag of $bag.what')
|
||||
self.assertEqual(s.substitute(m), 'tim likes to eat a bag of ham')
|
||||
|
||||
def test_flags_override(self):
|
||||
class MyPattern(Template):
|
||||
flags = 0
|
||||
s = MyPattern('$wHO likes ${WHAT} for ${meal}')
|
||||
d = dict(wHO='tim', WHAT='ham', meal='dinner', w='fred')
|
||||
self.assertRaises(ValueError, s.substitute, d)
|
||||
self.assertEqual(s.safe_substitute(d), 'fredHO likes ${WHAT} for dinner')
|
||||
|
||||
def test_idpattern_override_inside_outside(self):
|
||||
# bpo-1198569: Allow the regexp inside and outside braces to be
|
||||
# different when deriving from Template.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue