Ejemplo n.º 1
0
 def toPaths(self, converterPath, invalid=None):
     '''
     Converts the matches into path elements.
     
     @param converterPath: ConverterPath
         The converter path to use in constructing the paths elements.
     @param invalid: callable(Match, ConverterPath)|None
         The invalid match handling, if a callable is provided then the callable will be used to get a valid 
         string representation for the invalid match, the callable has to take to parameters, first one is the 
         invalid match and the second one is the converter path to be used. If the invalid is None then an exception 
         will be raised in case of invalid matches.
     @return: list[string]
         A list of strings representing the paths elements, or None if the path elements cannot be obtained.
     '''
     assert isinstance(converterPath, ConverterPath), 'Invalid converter path %s' % converterPath
     assert invalid is None or callable(invalid), 'Invalid callable for invalid %s' % invalid
     paths = []
     for isFirst, isLast, match in firstLastCheck(self.matches):
         assert isinstance(match, Match)
         if match.isValid(): path = match.toPath(converterPath, isFirst, isLast)
         elif invalid: path = invalid(match, converterPath)
         else: raise DevelError('Invalid match %s' % match)
         if path is not None:
             if isinstance(path, list): paths.extend(path)
             paths.append(path)
     return paths
Ejemplo n.º 2
0
 def toPaths(self, converterPath, invalid=None):
     '''
     Converts the matches into path elements.
     
     @param converterPath: ConverterPath
         The converter path to use in constructing the paths elements.
     @param invalid: callable(Match, ConverterPath)|None
         The invalid match handling, if a callable is provided then the callable will be used to get a valid 
         string representation for the invalid match, the callable has to take to parameters, first one is the 
         invalid match and the second one is the converter path to be used. If the invalid is None then an exception 
         will be raised in case of invalid matches.
     @return: list[string]
         A list of strings representing the paths elements, or None if the path elements cannot be obtained.
     '''
     assert isinstance(
         converterPath,
         ConverterPath), 'Invalid converter path %s' % converterPath
     assert invalid is None or callable(
         invalid), 'Invalid callable for invalid %s' % invalid
     paths = []
     for isFirst, isLast, match in firstLastCheck(self.matches):
         assert isinstance(match, Match)
         if match.isValid():
             path = match.toPath(converterPath, isFirst, isLast)
         elif invalid:
             path = invalid(match, converterPath)
         else:
             raise DevelError('Invalid match %s' % match)
         if path is not None:
             if isinstance(path, list): paths.extend(path)
             paths.append(path)
     return paths
Ejemplo n.º 3
0
 def toPaths(self, converterPath):
     '''
     Converts the matches into path elements.
     
     @param converterPath: ConverterPath
         The converter path to use in constructing the paths elements.
     @return: list[string]
         A list of strings representing the paths elements, or None if the path elements cannot be obtained.
     @raise AssertionError:
         If the path cannot be represented, check first the 'isValid' method.
     '''
     assert isinstance(converterPath, ConverterPath), 'Invalid converter path %s' % converterPath
     paths = []
     for k in range(0, len(self.matches)):
         match = self.matches[k]
         assert isinstance(match, Match)
         path = match.toPath(converterPath, k == 0, k == len(self.matches) - 1)
         if path is not None:
             if isinstance(path, list):
                 paths.extend(path)
             paths.append(path)
     return paths