# Path: hq/verbosity.py
# def verbose_print(text, indent_after=False, outdent_before=False):
#     if settings.VERBOSE:
#         if outdent_before:
#             pop_indent()
#         if not is_a_string(text):
#             text = text()
#         print(u'{0}{1}'.format(' ' * indent_level, text), file=sys.stderr)
#         if indent_after:
#             push_indent()
# 
# Path: hq/hquery/evaluation_error.py
# class HqueryEvaluationError(RuntimeError):
# 
#     @classmethod
#     def must_be_node_set(cls, obj):
#         if not is_node_set(obj):
#             raise HqueryEvaluationError('Expected a node set, but found a(n) {0}'.format(obj.__class__.__name__))
# 
#     @classmethod
#     def must_be_node_set_or_sequence(cls, obj):
#         if not (is_node_set(obj) or is_sequence(obj)):
#             raise HqueryEvaluationError('Expected a node set or sequence, but found a(n) {0}'.format(
#                 obj.__class__.__name__
#             ))


import os
import re
from inspect import isclass, isfunction
from pkgutil import walk_packages
from hq.verbosity import verbose_print
from hq.hquery.evaluation_error import HqueryEvaluationError



class FunctionSupport:
    all_functions = None


    def call_function(self, name, *args):
        self._load_all_functions()

        py_name = name.replace('-', '_')

        try:
            fn = self.all_functions[py_name]
        except KeyError:
            raise HqueryEvaluationError('Unknown function name "{0}"'.format(name))

        try:
            return fn(*args)
        except TypeError as err:
            if re.search(r'\d+ (?:.+ )?argument', err.args[0]):
                raise HqueryEvaluationError(err.args[0])
            else:
                raise


    def _load_all_functions(self):
        if self.all_functions is None:
            self.all_functions = dict()
            my_package = '{0}/__init__.py'.format(os.path.dirname(__file__))

# Path: hq/verbosity.py
# def verbose_print(text, indent_after=False, outdent_before=False):
#     if settings.VERBOSE:
#         if outdent_before:
#             pop_indent()
#         if not is_a_string(text):
#             text = text()
#         print(u'{0}{1}'.format(' ' * indent_level, text), file=sys.stderr)
#         if indent_after:
#             push_indent()
# 
# Path: hq/hquery/evaluation_error.py
# class HqueryEvaluationError(RuntimeError):
# 
#     @classmethod
#     def must_be_node_set(cls, obj):
#         if not is_node_set(obj):
#             raise HqueryEvaluationError('Expected a node set, but found a(n) {0}'.format(obj.__class__.__name__))
# 
#     @classmethod
#     def must_be_node_set_or_sequence(cls, obj):
#         if not (is_node_set(obj) or is_sequence(obj)):
#             raise HqueryEvaluationError('Expected a node set or sequence, but found a(n) {0}'.format(
#                 obj.__class__.__name__
#             ))


# Path: hq/hquery/function_support.py
import os
import re
from inspect import isclass, isfunction
from pkgutil import walk_packages
from hq.verbosity import verbose_print
from hq.hquery.evaluation_error import HqueryEvaluationError




class FunctionSupport:
    all_functions = None


    def call_function(self, name, *args):
        self._load_all_functions()

        py_name = name.replace('-', '_')

        try:
            fn = self.all_functions[py_name]
        except KeyError:
            raise HqueryEvaluationError('Unknown function name "{0}"'.format(name))

        try:
            return fn(*args)
        except TypeError as err:
            if re.search(r'\d+ (?:.+ )?argument', err.args[0]):
                raise HqueryEvaluationError(err.args[0])
            else:
                raise


    def _load_all_functions(self):
        if self.all_functions is None:
            self.all_functions = dict()
            my_package = '{0}/__init__.py'.format(os.path.dirname(__file__))

            verbose_print('FunctionSupport loading all function modules near {0}.'.format(my_package),