Beispiel #1
0
 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(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)
Beispiel #3
0
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))
Beispiel #4
0
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))
Beispiel #5
0
 def filter(match, template=template):
     return sre_parse.expand_template(template, match)
Beispiel #6
0
def _expand(pattern, match, template):
    # internal: match.expand implementation hook
    template = sre_parse.parse_template(template, pattern)
    return sre_parse.expand_template(template, match)
Beispiel #7
0
def _expand(pattern, match, template):
    template = sre_parse.parse_template(template, pattern)
    return sre_parse.expand_template(template, match)
Beispiel #8
0
def _expand(pattern, match, template):
    template = sre_parse.parse_template(template, pattern)
    return sre_parse.expand_template(template, match)
Beispiel #9
0
#
Beispiel #10
0
 def expand(self, template) :
     template = sre_parse.parse_template(template, self.pattern)
     return sre_parse.expand_template(template, self)
Beispiel #11
0
 def expand(self, template):
     template = sre_parse.parse_template(template, self.pattern)
     return sre_parse.expand_template(template, self)
Beispiel #12
0
 def filter(match, template = template): #@ReservedAssignment
     return sre_parse.expand_template(template, match)
Beispiel #13
0
#
Beispiel #14
0
 def update_event(self, inp=-1):
     self.set_output_val(
         0, sre_parse.expand_template(self.input(0), self.input(1)))
Beispiel #15
0
 def filter(match, template=template):  #@ReservedAssignment
     return sre_parse.expand_template(template, match)
Beispiel #16
0
import string