Beispiel #1
0
    def match(self, file_path: str, file_content: str) -> MatchResult:
        if self.part == 'extension':
            compare_variable = find_extension(file_path)
        elif self.part == 'filename':
            compare_variable = file_path.split(os.path.sep)[-1]
        elif self.part == 'contents':
            compare_variable = file_content
        elif self.part == 'path':
            compare_variable = file_path
        else:
            module_logger.warning(f'Unrecognised File Part Access {self.name}')
            return MatchResult(False)

        return MatchResult(compare_variable == self.signature,
                           compare_variable)
    def match(self, file_path: str, file_content: str) -> MatchResult:
        if self.part == 'extension':
            compare_variable = find_extension(file_path)[1:]
        elif self.part == 'filename':
            compare_variable = file_path.split(os.path.sep)[-1]
        elif self.part == 'contents':
            compare_variable = file_content
        elif self.part == 'path':
            compare_variable = file_path
        else:
            module_logger.warning(f'Unrecognised File Part Access {self.name}')
            return MatchResult(False)
        match = self.regex.search(compare_variable)

        if not match:
            return MatchResult(False)
        return MatchResult(True, match.group(0))