Esempio 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
Esempio 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
Esempio n. 3
0
 def isValid(self):
     '''
     Checks if the path is valid, this means that the path will provide valid paths elements.
     
     @return: boolean
         True if the path can provide the paths, false otherwise.
     '''
     if self.node is not None:
         valid = True
         for match in self.matches:
             assert isinstance(match, Match)
             valid &= match.isValid()
         return valid
     return False
Esempio n. 4
0
 def isValid(self):
     '''
     Checks if the path is valid, this means that the path will provide valid paths elements.
     
     @return: boolean
         True if the path can provide the paths, false otherwise.
     '''
     if self.node is not None:
         valid = True
         for match in self.matches:
             assert isinstance(match, Match)
             valid &= match.isValid()
         return valid
     return False