예제 #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)
예제 #2
0
파일: support.py 프로젝트: gcarothers/lepl
 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)
예제 #3
0
 def expand(self, replacement):
     replacement = compile_replacement(replacement, self.__state)
     return replacement(self)
예제 #4
0
파일: support.py 프로젝트: gcarothers/lepl
 def expand(self, replacement):
     replacement = compile_replacement(replacement, self.__state)
     return replacement(self)