Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # this is all fucked up!
- import re
- import string
- t = string.Template('$var')
- print t.patern.patern
- #\$(?:
- # (?P<escaped>\$) |
- #delimiters
- # (?P<named>[_a-z][_a-z0-9]*) |
- #identifier
- # {(?P<braced>[_a-z][_a-z0-9]*)} |
- #identifier
- # (?P<invalid>)
- #ill-formed delimeter exprs
- #)
- class MyTemplate(string.Template):
- delimeter = '{{'
- pattern = r'''
- \{\{(?:
- (?P<escaped>\{\{)|
- (?P<named>[_a-z][_a-z0-9]*)\}\}|
- (?P<braced>[_a-z][_a-z0-9]*)\}\}|
- (?P<invalid>)
- )
- '''
- t = MyTemplate('''
- {{{{
- {{var}}
- ''')
- print 'MATCHES:',
- t.pattern.findall(t.template)
- print 'SUBSTITUTED:',
- t.safe_substitute(var='replacement')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement