def visit_simple_value(self, node): # In case of date specifiers convert relative or text date to normal date. for regexp, date_conversion_handler in DATE_SPECIFIERS_CONVERSION_HANDLERS.items( ): date_value = node.value regexp_match = regexp.match(node.value) if regexp_match: relative_date_specifier_suffix = date_value.split( regexp_match.group())[1] return ast.Value( str(date_conversion_handler( relative_date_specifier_suffix))) # Normal text value return ast.Value( node.value, True if ast.GenericValue.WILDCARD_TOKEN in node.value else False)
def visit_complex_value(self, node): """Convert :class:`ComplexValue` to one of ExactMatch, PartialMatch and Regex Value nodes.""" if node.value.startswith(ComplexValue.EXACT_VALUE_TOKEN): value = node.value.strip(ComplexValue.EXACT_VALUE_TOKEN) return ExactMatchValue(value) elif node.value.startswith(ComplexValue.PARTIAL_VALUE_TOKEN): value = node.value.strip(ComplexValue.PARTIAL_VALUE_TOKEN) return PartialMatchValue( value, True if ast.GenericValue.WILDCARD_TOKEN in value else False) elif node.value.startswith(ComplexValue.REGEX_VALUE_TOKEN): return RegexValue(node.value.strip(ComplexValue.REGEX_VALUE_TOKEN)) else: # Covering the case where ComplexValue supports more than ExactMatch, PartialMatch and Regex values. msg = self.__class__.__name__ + ': Unrecognized complex value' try: msg += ' lookahead token: "' + node.value[0] + '"' except IndexError: msg += ': \"' + repr(node.value) + '"' msg += '.\nUsing simple value instead: "' + node.value + '".' logger.warn(msg) return ast.Value(node.value)
def visit_simple_range_value(self, node): return ast.Value(node.value)
def visit_less_equal_op(self, node): try: value = node.op.accept(self) except AttributeError: # Case of "100-" format where 100 is text (and not a SimpleValue). value = ast.Value(node.op) return ast.LessEqualThanOp(value)