# Path: sitetree/compat.py
# TOKEN_TEXT = TokenType.TEXT
# 
# TOKEN_VAR = TokenType.VAR
# 
# Path: sitetree/exceptions.py
# class SiteTreeError(Exception):
#     """Exception class for sitetree application."""
# 
# Path: sitetree/settings.py
# ALIAS_TRUNK = 'trunk'
# 
# ALIAS_THIS_CHILDREN = 'this-children'
# 
# ALIAS_THIS_SIBLINGS = 'this-siblings'
# 
# ALIAS_THIS_PARENT_SIBLINGS = 'this-parent-siblings'
# 
# ALIAS_THIS_ANCESTOR_CHILDREN = 'this-ancestor-children'
# 
# UNRESOLVED_ITEM_MARKER: str = getattr(settings, 'SITETREE_UNRESOLVED_ITEM_MARKER', u'#unresolved')
# 
# RAISE_ITEMS_ERRORS_ON_DEBUG: bool = getattr(settings, 'SITETREE_RAISE_ITEMS_ERRORS_ON_DEBUG', True)
# 
# CACHE_TIMEOUT: int = getattr(settings, 'SITETREE_CACHE_TIMEOUT', 31536000)
# 
# CACHE_NAME: str = getattr(settings, 'SITETREE_CACHE_NAME', 'default')
# 
# DYNAMIC_ONLY: bool = getattr(settings, 'SITETREE_DYNAMIC_ONLY', False)
# 
# ADMIN_APP_NAME: str = getattr(settings, 'SITETREE_ADMIN_APP_NAME', 'admin')
# 
# SITETREE_CLS: str = getattr(settings, 'SITETREE_CLS', None)
# 
# Path: sitetree/utils.py
# def get_tree_model() -> Type['TreeBase']:
#     """Returns the Tree model, set for the project."""
#     return get_model_class('MODEL_TREE')
# 
# def get_tree_item_model() -> Type['TreeItemBase']:
#     """Returns the TreeItem model, set for the project."""
#     return get_model_class('MODEL_TREE_ITEM')
# 
# def import_app_sitetree_module(app: str) -> Optional[ModuleType]:
#     """Imports sitetree module from a given app.
# 
#     :param app: Application name
# 
#     """
#     module_name = settings.APP_MODULE_NAME
#     module = import_module(app)
# 
#     try:
#         sub_module = import_module(f'{app}.{module_name}')
#         return sub_module
# 
#     except ImportError:
#         if module_has_submodule(module, module_name):
#             raise
#         return None
# 
# def generate_id_for(obj: Any):
#     """Generates and returns a unique identifier for the given object."""
#     return id(obj)


import warnings
from collections import defaultdict
from copy import deepcopy
from inspect import getfullargspec
from sys import exc_info
from threading import local
from typing import Callable, List, Optional, Dict, Union, Sequence, Any, Tuple
from django.conf import settings
from django.core.cache import caches
from django.db.models import signals, QuerySet
from django.template.base import (
    FilterExpression, Lexer, Parser, Variable, VariableDoesNotExist, VARIABLE_TAG_START)
from django.template.context import Context
from django.template.loader import get_template
from django.urls import reverse, NoReverseMatch
from django.utils import module_loading
from django.utils.encoding import iri_to_uri
from django.utils.translation import get_language
from .compat import TOKEN_TEXT, TOKEN_VAR
from .exceptions import SiteTreeError
from .settings import (
    ALIAS_TRUNK, ALIAS_THIS_CHILDREN, ALIAS_THIS_SIBLINGS, ALIAS_THIS_PARENT_SIBLINGS, ALIAS_THIS_ANCESTOR_CHILDREN,
    UNRESOLVED_ITEM_MARKER, RAISE_ITEMS_ERRORS_ON_DEBUG, CACHE_TIMEOUT, CACHE_NAME, DYNAMIC_ONLY, ADMIN_APP_NAME,
    SITETREE_CLS)
from .utils import get_tree_model, get_tree_item_model, import_app_sitetree_module, generate_id_for
    from django.contrib.auth.models import User  # noqa
    from .models import TreeItemBase, TreeBase

    def resolve_var(
            self,
            varname: Union[str, 'TreeItemBase', FilterExpression],
            context: Context = None
    ) -> Any:
        """Resolves name as a variable in a given context.

        If no context specified page context is considered as context.

        :param varname:
        :param context:

        """
        context = context or self.current_page_context

        if isinstance(varname, FilterExpression):
            varname = varname.resolve(context)

        else:
            varname = varname.strip()

            try:
                varname = Variable(varname).resolve(context)
            except VariableDoesNotExist:
                varname = varname

        return varname



# Path: sitetree/compat.py
# TOKEN_TEXT = TokenType.TEXT
# 
# TOKEN_VAR = TokenType.VAR
# 
# Path: sitetree/exceptions.py
# class SiteTreeError(Exception):
#     """Exception class for sitetree application."""
# 
# Path: sitetree/settings.py
# ALIAS_TRUNK = 'trunk'
# 
# ALIAS_THIS_CHILDREN = 'this-children'
# 
# ALIAS_THIS_SIBLINGS = 'this-siblings'
# 
# ALIAS_THIS_PARENT_SIBLINGS = 'this-parent-siblings'
# 
# ALIAS_THIS_ANCESTOR_CHILDREN = 'this-ancestor-children'
# 
# UNRESOLVED_ITEM_MARKER: str = getattr(settings, 'SITETREE_UNRESOLVED_ITEM_MARKER', u'#unresolved')
# 
# RAISE_ITEMS_ERRORS_ON_DEBUG: bool = getattr(settings, 'SITETREE_RAISE_ITEMS_ERRORS_ON_DEBUG', True)
# 
# CACHE_TIMEOUT: int = getattr(settings, 'SITETREE_CACHE_TIMEOUT', 31536000)
# 
# CACHE_NAME: str = getattr(settings, 'SITETREE_CACHE_NAME', 'default')
# 
# DYNAMIC_ONLY: bool = getattr(settings, 'SITETREE_DYNAMIC_ONLY', False)
# 
# ADMIN_APP_NAME: str = getattr(settings, 'SITETREE_ADMIN_APP_NAME', 'admin')
# 
# SITETREE_CLS: str = getattr(settings, 'SITETREE_CLS', None)
# 
# Path: sitetree/utils.py
# def get_tree_model() -> Type['TreeBase']:
#     """Returns the Tree model, set for the project."""
#     return get_model_class('MODEL_TREE')
# 
# def get_tree_item_model() -> Type['TreeItemBase']:
#     """Returns the TreeItem model, set for the project."""
#     return get_model_class('MODEL_TREE_ITEM')
# 
# def import_app_sitetree_module(app: str) -> Optional[ModuleType]:
#     """Imports sitetree module from a given app.
# 
#     :param app: Application name
# 
#     """
#     module_name = settings.APP_MODULE_NAME
#     module = import_module(app)
# 
#     try:
#         sub_module = import_module(f'{app}.{module_name}')
#         return sub_module
# 
#     except ImportError:
#         if module_has_submodule(module, module_name):
#             raise
#         return None
# 
# def generate_id_for(obj: Any):
#     """Generates and returns a unique identifier for the given object."""
#     return id(obj)


# Path: sitetree/sitetreeapp.py
import warnings
from collections import defaultdict
from copy import deepcopy
from inspect import getfullargspec
from sys import exc_info
from threading import local
from typing import Callable, List, Optional, Dict, Union, Sequence, Any, Tuple
from django.conf import settings
from django.core.cache import caches
from django.db.models import signals, QuerySet
from django.template.base import (
    FilterExpression, Lexer, Parser, Variable, VariableDoesNotExist, VARIABLE_TAG_START)
from django.template.context import Context
from django.template.loader import get_template
from django.urls import reverse, NoReverseMatch
from django.utils import module_loading
from django.utils.encoding import iri_to_uri
from django.utils.translation import get_language
from .compat import TOKEN_TEXT, TOKEN_VAR
from .exceptions import SiteTreeError
from .settings import (
    ALIAS_TRUNK, ALIAS_THIS_CHILDREN, ALIAS_THIS_SIBLINGS, ALIAS_THIS_PARENT_SIBLINGS, ALIAS_THIS_ANCESTOR_CHILDREN,
    UNRESOLVED_ITEM_MARKER, RAISE_ITEMS_ERRORS_ON_DEBUG, CACHE_TIMEOUT, CACHE_NAME, DYNAMIC_ONLY, ADMIN_APP_NAME,
    SITETREE_CLS)
from .utils import get_tree_model, get_tree_item_model, import_app_sitetree_module, generate_id_for
    from django.contrib.auth.models import User  # noqa
    from .models import TreeItemBase, TreeBase


    def resolve_var(
            self,
            varname: Union[str, 'TreeItemBase', FilterExpression],
            context: Context = None
    ) -> Any:
        """Resolves name as a variable in a given context.

        If no context specified page context is considered as context.

        :param varname:
        :param context:

        """
        context = context or self.current_page_context

        if isinstance(varname, FilterExpression):
            varname = varname.resolve(context)

        else:
            varname = varname.strip()

            try:
                varname = Variable(varname).resolve(context)
            except VariableDoesNotExist:
                varname = varname

        return varname



_SITETREE_CLS = module_loading.import_string(SITETREE_CLS) if SITETREE_CLS else SiteTree