# Path: lighty/utils.py
# def print_func(*args):
# def with_metaclass(meta, base=object):
#     def __init__(self, name, flag=True, optional=True, default=None, help='',
#                  type=str, nargs=1):
#     def __init__(self, program=None, description='', help=''):
#     def add_option(self, name, *args, **kwargs):
#     def add_argument(self, name, **kwargs):
#     def help_text(self):
#     def parse(self, args=None):
#     def _parse(self, args_for_parse):
# PY3 = sys.version_info[0] == 3
# class Argument(object):
# class CommandParser(object):
# 
# Path: lighty/templates/context.py
# def resolve(var_name, context):
#     if '.' in var_name:
#         fields = var_name.split('.')
#         return reduce(get_field, [get_value(fields[0], context)] + fields[1:])
#     return get_value(var_name, context)
# 
# Path: lighty/templates/loaders.py
# class TemplateLoader(object):
#     '''Class fot managing templates
#     '''
# 
#     def __init__(self):
#         '''Create new template loader
#         '''
#         super(TemplateLoader, self).__init__()
#         # Create new templates dictionary
#         self.templates = {}
# 
#     def register(self, name, template):
#         '''Add loaded or generated template
#         '''
#         self.templates[name] = template
# 
#     def get_template(self, name):
#         '''Get template by name
#         '''
#         if name not in self.templates:
#             raise Exception("Template '%s' was not found" % name)
#         return self.templates[name]
# 
# Path: lighty/templates/filter.py
# class FilterManager(object):
#     def __init__(self):
#     def is_filter_exists(self, name):
#     def register(self, filter):
#     def apply(self, filter, value, args, arg_types, context):
# 
# Path: lighty/templates/tag.py
# VARIABLE = 0
# STRING = 1
# NUMBER = 2
# def parse_token(token):
#     def __init__(self):
#     def register(self, name, tag, is_block_tag=False, context_required=False,
#                  template_required=False, loader_required=False,
#                  is_lazy_tag=True):
#     def is_tag_exists(self, name):
#     def is_block_tag(self, name):
#     def is_lazy_tag(self, name):
#     def execute(self, name, token, context, block, template, loader):
# class TagManager(object):


from collections import deque
from functools import reduce
from decimal import Decimal
from ..utils import StringIO
from .context import resolve
from .loaders import TemplateLoader
from .filter import filter_manager
from .tag import tag_manager, parse_token
                        token = ''
                    current = Template.CLOSE
                elif char == '|':
                    current = Template.FILTER
                    token += str(char)
                else:
                    token += str(char)
            elif current == Template.TAG:
                if char == '%':
                    current = Template.CLOSE
                    token = token.strip()
                    name = token.split(' ', 1)[0]
                    if name.startswith('end'):
                        name = name[3:]
                        tag = tag_stack.pop()
                        # Close block
                        if name == tag:
                            block = cmds
                            cmds = cmd_stack.pop()
                            token = token_stack.pop()
                            cmds.append(self.tag(name, token, block))
                        else:
                            raise Exception(
                                "Invalid closing tag: 'end%s' except 'end%s'" %
                                (name, tag))
                    else:
                        if ' ' in token:
                            token = token.split(' ', 1)[1]
                        else:
                            token = ''

# Path: lighty/utils.py
# def print_func(*args):
# def with_metaclass(meta, base=object):
#     def __init__(self, name, flag=True, optional=True, default=None, help='',
#                  type=str, nargs=1):
#     def __init__(self, program=None, description='', help=''):
#     def add_option(self, name, *args, **kwargs):
#     def add_argument(self, name, **kwargs):
#     def help_text(self):
#     def parse(self, args=None):
#     def _parse(self, args_for_parse):
# PY3 = sys.version_info[0] == 3
# class Argument(object):
# class CommandParser(object):
# 
# Path: lighty/templates/context.py
# def resolve(var_name, context):
#     if '.' in var_name:
#         fields = var_name.split('.')
#         return reduce(get_field, [get_value(fields[0], context)] + fields[1:])
#     return get_value(var_name, context)
# 
# Path: lighty/templates/loaders.py
# class TemplateLoader(object):
#     '''Class fot managing templates
#     '''
# 
#     def __init__(self):
#         '''Create new template loader
#         '''
#         super(TemplateLoader, self).__init__()
#         # Create new templates dictionary
#         self.templates = {}
# 
#     def register(self, name, template):
#         '''Add loaded or generated template
#         '''
#         self.templates[name] = template
# 
#     def get_template(self, name):
#         '''Get template by name
#         '''
#         if name not in self.templates:
#             raise Exception("Template '%s' was not found" % name)
#         return self.templates[name]
# 
# Path: lighty/templates/filter.py
# class FilterManager(object):
#     def __init__(self):
#     def is_filter_exists(self, name):
#     def register(self, filter):
#     def apply(self, filter, value, args, arg_types, context):
# 
# Path: lighty/templates/tag.py
# VARIABLE = 0
# STRING = 1
# NUMBER = 2
# def parse_token(token):
#     def __init__(self):
#     def register(self, name, tag, is_block_tag=False, context_required=False,
#                  template_required=False, loader_required=False,
#                  is_lazy_tag=True):
#     def is_tag_exists(self, name):
#     def is_block_tag(self, name):
#     def is_lazy_tag(self, name):
#     def execute(self, name, token, context, block, template, loader):
# class TagManager(object):


# Path: lighty/templates/template.py
from collections import deque
from functools import reduce
from decimal import Decimal
from ..utils import StringIO
from .context import resolve
from .loaders import TemplateLoader
from .filter import filter_manager
from .tag import tag_manager, parse_token

                        token = ''
                    current = Template.CLOSE
                elif char == '|':
                    current = Template.FILTER
                    token += str(char)
                else:
                    token += str(char)
            elif current == Template.TAG:
                if char == '%':
                    current = Template.CLOSE
                    token = token.strip()
                    name = token.split(' ', 1)[0]
                    if name.startswith('end'):
                        name = name[3:]
                        tag = tag_stack.pop()
                        # Close block
                        if name == tag:
                            block = cmds
                            cmds = cmd_stack.pop()
                            token = token_stack.pop()
                            cmds.append(self.tag(name, token, block))
                        else:
                            raise Exception(
                                "Invalid closing tag: 'end%s' except 'end%s'" %
                                (name, tag))
                    else:
                        if ' ' in token:
                            token = token.split(' ', 1)[1]
                        else:
                            token = ''

                        if tag_manager.is_block_tag(name):