# Path: pyston/filters/filters.py
# OPERATORS = Enum(
#     ('GT', 'gt'),
#     ('LT', 'lt'),
#     ('EQ', 'eq'),
#     ('NEQ', 'neq'),
#     ('LTE', 'lte'),
#     ('GTE', 'gte'),
#     ('CONTAINS', 'contains'),
#     ('ICONTAINS', 'icontains'),
#     ('RANGE', 'range'),
#     ('EXACT', 'exact'),
#     ('IEXACT', 'iexact'),
#     ('STARTSWITH', 'startswith'),
#     ('ISTARTSWITH', 'istartswith'),
#     ('ENDSWITH', 'endswith'),
#     ('IENDSWITH', 'iendswith'),
#     ('IN', 'in'),
#     ('RANGE', 'range'),
#     ('ALL', 'all'),
#     ('ISNULL', 'isnull'),
# )
# 
# Path: pyston/filters/utils.py
# LOGICAL_OPERATORS = Enum(
#     'AND',
#     'OR',
#     'NOT',
# )


import re
import pyparsing as pp
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext
from .filters import OPERATORS
from .utils import LOGICAL_OPERATORS

    def _parse_to_composed_conditions(self, conditions_list):
        if len(conditions_list) == 1:
            return conditions_list[0]
        else:
            return ComposedCondition(LOGICAL_OPERATORS.AND, self._parse_to_composed_conditions(conditions_list[1:]),
                                     conditions_list[0])

    def parse(self, request):
        filter_terms_with_values = [
            (filter_term, value) for filter_term, value in request.GET.dict().items()
            if not filter_term.startswith('_') and filter_term not in request._rest_context
        ]
        if not filter_terms_with_values:
            return None

        conditions_list = []
        for filter_term, value in filter_terms_with_values:
            identifiers = filter_term.split(self.DELIMITER) if self.DELIMITER else [filter_term]

            if len(identifiers) > 1 and identifiers[-1].upper() == LOGICAL_OPERATORS.NOT:
                identifiers = identifiers[:-1]
                exclude = True
            else:
                exclude = False

            if len(identifiers) > 1 and identifiers[-1].lower() in OPERATORS:
                operator_slug = identifiers[-1].lower()
                identifiers = identifiers[:-1]
            else:

# Path: pyston/filters/filters.py
# OPERATORS = Enum(
#     ('GT', 'gt'),
#     ('LT', 'lt'),
#     ('EQ', 'eq'),
#     ('NEQ', 'neq'),
#     ('LTE', 'lte'),
#     ('GTE', 'gte'),
#     ('CONTAINS', 'contains'),
#     ('ICONTAINS', 'icontains'),
#     ('RANGE', 'range'),
#     ('EXACT', 'exact'),
#     ('IEXACT', 'iexact'),
#     ('STARTSWITH', 'startswith'),
#     ('ISTARTSWITH', 'istartswith'),
#     ('ENDSWITH', 'endswith'),
#     ('IENDSWITH', 'iendswith'),
#     ('IN', 'in'),
#     ('RANGE', 'range'),
#     ('ALL', 'all'),
#     ('ISNULL', 'isnull'),
# )
# 
# Path: pyston/filters/utils.py
# LOGICAL_OPERATORS = Enum(
#     'AND',
#     'OR',
#     'NOT',
# )


# Path: pyston/filters/parser.py
import re
import pyparsing as pp
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext
from .filters import OPERATORS
from .utils import LOGICAL_OPERATORS


    def _parse_to_composed_conditions(self, conditions_list):
        if len(conditions_list) == 1:
            return conditions_list[0]
        else:
            return ComposedCondition(LOGICAL_OPERATORS.AND, self._parse_to_composed_conditions(conditions_list[1:]),
                                     conditions_list[0])

    def parse(self, request):
        filter_terms_with_values = [
            (filter_term, value) for filter_term, value in request.GET.dict().items()
            if not filter_term.startswith('_') and filter_term not in request._rest_context
        ]
        if not filter_terms_with_values:
            return None

        conditions_list = []
        for filter_term, value in filter_terms_with_values:
            identifiers = filter_term.split(self.DELIMITER) if self.DELIMITER else [filter_term]

            if len(identifiers) > 1 and identifiers[-1].upper() == LOGICAL_OPERATORS.NOT:
                identifiers = identifiers[:-1]
                exclude = True
            else:
                exclude = False

            if len(identifiers) > 1 and identifiers[-1].lower() in OPERATORS:
                operator_slug = identifiers[-1].lower()
                identifiers = identifiers[:-1]
            else:

                operator_slug = OPERATORS.EQ