Exemple #1
0
 def subn(self, replacement, text, count=0):
     if self.__factory and not isinstance(replacement, Callable):
         # we should probably test what is returned from callable,
         # but i am not so sure these tests are a good idea (they
         # are needed to pass the existing python test suite)
         self.__parser_state.alphabet.validate_input(
             replacement, self.__parser_state.flags)
     replacement = compile_replacement(replacement, self.__parser_state)
     n = 0
     pos = 0
     results = []
     for found in self.subiter(text, count):
         results.append(text[pos:found.start()])
         results.append(replacement(found))
         n += 1
         pos = found.end()
     results += text[pos:]
     return (self.__parser_state.alphabet.join(*results), n)
Exemple #2
0
 def subn(self, replacement, text, count=0):
     if self.__factory and not isinstance(replacement, Callable):
         # we should probably test what is returned from callable,
         # but i am not so sure these tests are a good idea (they
         # are needed to pass the existing python test suite)
         self.__parser_state.alphabet.validate_input(replacement,
                                                     self.__parser_state.flags)
     replacement = compile_replacement(replacement, self.__parser_state)
     n = 0
     pos = 0
     results = []
     for found in self.subiter(text, count):
         results.append(text[pos:found.start()])
         results.append(replacement(found))
         n += 1
         pos = found.end()
     results += text[pos:]
     return (self.__parser_state.alphabet.join(*results), n)
Exemple #3
0
 def expand(self, replacement):
     replacement = compile_replacement(replacement, self.__state)
     return replacement(self)
Exemple #4
0
 def expand(self, replacement):
     replacement = compile_replacement(replacement, self.__state)
     return replacement(self)