def _expand(self, m, template): # XXX This code depends on internals of the regular expression # engine! There's no standard API to do a substitution when you # have already found the match. One should be added. # The solution here is designed to be backwards compatible # with previous Python versions, e.g. 1.5.2. # XXX This dynamic test should be done only once. if getattr(re, "engine", "pre") == "pre": return re.pcre_expand(m, template) else: # sre # XXX This import should be avoidable... import sre_parse # XXX This parses the template over and over... ptemplate = sre_parse.parse_template(template, m.re) return sre_parse.expand_template(ptemplate, m)
def expand_sub(string, template, debug=0, mode='all') : """ Given a regular expression and a replacement string, generate expansions of the regular expression and for each one return it and its transformation as applied by the replacement string. string : regular expression to expand template : transformation to apply to each regular expression mode : can take 3 values all : return all possible shortest strings that the regular expression would match first : return the first string that all would return random : return one random string that the regular expression would match """ pattern = sre_parse.parse(string, flags=sre_parse.SRE_FLAG_VERBOSE) pattern.mode = mode template = sre_parse.parse_template(template, pattern) if debug : print pattern print template for s in _iterate(pattern, pattern.data, MatchObj(pattern, "")) : s.patient = 0 yield (s.string, sre_parse.expand_template(template, s))
def expand_sub(string, template, debug=0, mode='all'): """ Given a regular expression and a replacement string, generate expansions of the regular expression and for each one return it and its transformation as applied by the replacement string. string : regular expression to expand template : transformation to apply to each regular expression mode : can take 3 values all : return all possible shortest strings that the regular expression would match first : return the first string that all would return random : return one random string that the regular expression would match """ pattern = sre_parse.parse(string, flags=sre_parse.SRE_FLAG_VERBOSE) pattern.mode = mode template = sre_parse.parse_template(template, pattern) if debug: print(pattern) print(template) for s in _iterate(pattern, pattern.data, MatchObj(pattern, "")): s.patient = 0 yield (s.string, sre_parse.expand_template(template, s))
def filter(match, template=template): return sre_parse.expand_template(template, match)
def _expand(pattern, match, template): # internal: match.expand implementation hook template = sre_parse.parse_template(template, pattern) return sre_parse.expand_template(template, match)
def _expand(pattern, match, template): template = sre_parse.parse_template(template, pattern) return sre_parse.expand_template(template, match)
#
def expand(self, template) : template = sre_parse.parse_template(template, self.pattern) return sre_parse.expand_template(template, self)
def expand(self, template): template = sre_parse.parse_template(template, self.pattern) return sre_parse.expand_template(template, self)
def filter(match, template = template): #@ReservedAssignment return sre_parse.expand_template(template, match)
def update_event(self, inp=-1): self.set_output_val( 0, sre_parse.expand_template(self.input(0), self.input(1)))
def filter(match, template=template): #@ReservedAssignment return sre_parse.expand_template(template, match)
import string