"""This module holds the logic for doing simple data conversions.""" import re def escape_term(term): """Apply escaping to the passed in query term. Args: term: String Returns: String with escaped characters """ escape_rules = [ '+', '-', '&&', '/', '||', '!', '(', ')', '{', '}', '[', ']', '^', '~', '*', '?', ':', '"', ] escaped_term = term.replace('\\', r'\\') for rule in escape_rules: escaped_term = escaped_term.replace(rule, fr'\{rule}') return escaped_term def to_snake_case_dict(dictionary): """Apply snake case to dictionary keys. Args: dictionary: dict Returns: Dictionary with snake case keys """ result = dict() pattern = re.compile(r'(?