658 raise error.ParseError(_("sub expects three arguments")) |
658 raise error.ParseError(_("sub expects three arguments")) |
659 |
659 |
660 pat = stringify(args[0][0](context, mapping, args[0][1])) |
660 pat = stringify(args[0][0](context, mapping, args[0][1])) |
661 rpl = stringify(args[1][0](context, mapping, args[1][1])) |
661 rpl = stringify(args[1][0](context, mapping, args[1][1])) |
662 src = stringify(args[2][0](context, mapping, args[2][1])) |
662 src = stringify(args[2][0](context, mapping, args[2][1])) |
663 yield re.sub(pat, rpl, src) |
663 try: |
|
664 patre = re.compile(pat) |
|
665 except re.error: |
|
666 # i18n: "sub" is a keyword |
|
667 raise error.ParseError(_("sub got an invalid pattern: %s") % pat) |
|
668 try: |
|
669 yield patre.sub(rpl, src) |
|
670 except re.error: |
|
671 # i18n: "sub" is a keyword |
|
672 raise error.ParseError(_("sub got an invalid replacement: %s") % rpl) |
664 |
673 |
665 def startswith(context, mapping, args): |
674 def startswith(context, mapping, args): |
666 """:startswith(pattern, text): Returns the value from the "text" argument |
675 """:startswith(pattern, text): Returns the value from the "text" argument |
667 if it begins with the content from the "pattern" argument.""" |
676 if it begins with the content from the "pattern" argument.""" |
668 if len(args) != 2: |
677 if len(args) != 2: |