コード例 #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)