# Path: jinja2/utils.py
#     def _test_gen_bug():
#         def concat(gen):
#     def is_python_keyword(name):
#     def method(self): pass
# def _func():
# def contextfunction(f):
# def environmentfunction(f):
# def is_undefined(obj):
# def consume(iterable):
# def clear_caches():
# def import_string(import_name, silent=False):
# def open_if_exists(filename, mode='r'):
# def pformat(obj, verbose=False):
# def urlize(text, trim_url_limit=None, nofollow=False):
# def generate_lorem_ipsum(n=5, html=True, min=20, max=100):
#     def __new__(cls, base=u'', encoding=None, errors='strict'):
#     def __html__(self):
#     def __add__(self, other):
#     def __radd__(self, other):
#     def __mul__(self, num):
#     def __mod__(self, arg):
#     def __repr__(self):
#     def join(self, seq):
#     def split(self, *args, **kwargs):
#     def rsplit(self, *args, **kwargs):
#     def splitlines(self, *args, **kwargs):
#     def unescape(self):
#         def handle_match(m):
#     def striptags(self):
#     def escape(cls, s):
#     def make_wrapper(name):
#         def func(self, *args, **kwargs):
# def _escape_argspec(obj, iterable):
#     def __init__(self, obj):
#     def __init__(self, capacity):
#     def _postinit(self):
#     def _remove(self, obj):
#     def __getstate__(self):
#     def __setstate__(self, d):
#     def __getnewargs__(self):
#     def copy(self):
#     def get(self, key, default=None):
#     def setdefault(self, key, default=None):
#     def clear(self):
#     def __contains__(self, key):
#     def __len__(self):
#     def __repr__(self):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __delitem__(self, key):
#     def items(self):
#     def iteritems(self):
#     def values(self):
#     def itervalue(self):
#     def keys(self):
#     def iterkeys(self):
#     def __reversed__(self):
#     def __init__(self, *items):
#     def reset(self):
#     def current(self):
#     def next(self):
#     def __init__(self, sep=u', '):
#     def __call__(self):
#     def escape(s):
#     def soft_unicode(s):
#         def __init__(self, _func, *args, **kwargs):
#         def __call__(self, *args, **kwargs):
# class _C(object):
# class Markup(unicode):
# class _MarkupEscapeHelper(object):
# class LRUCache(object):
# class Cycler(object):
# class Joiner(object):
#     class partial(object):
# 
# Path: jinja2/exceptions.py
# class UndefinedError(TemplateRuntimeError):
#     """Raised if a template tries to operate on :class:`Undefined`."""
# 
# class TemplateRuntimeError(TemplateError):
#     """A generic runtime error in the template engine.  Under some situations
#     Jinja may raise this exception.
#     """


import sys
from itertools import chain, imap
from jinja2.utils import Markup, partial, soft_unicode, escape, missing, \
     concat, MethodType, FunctionType
from jinja2.exceptions import UndefinedError, TemplateRuntimeError
    from collections import Mapping
    Runtime helpers.

    :copyright: Copyright 2008 by Armin Ronacher.
    :license: BSD.
"""


# these variables are exported to the template runtime
__all__ = ['LoopContext', 'Context', 'TemplateReference', 'Macro', 'Markup',
           'TemplateRuntimeError', 'missing', 'concat', 'escape',
           'markup_join', 'unicode_join']


#: the types we support for context functions
_context_function_types = (FunctionType, MethodType)


def markup_join(seq):
    """Concatenation that escapes if necessary and converts to unicode."""
    buf = []
    iterator = imap(soft_unicode, seq)
    for arg in iterator:
        buf.append(arg)
        if hasattr(arg, '__html__'):
            return Markup(u'').join(chain(buf, iterator))
    return concat(buf)


def unicode_join(seq):
    """Simple args to unicode conversion and concatenation."""

# Path: jinja2/utils.py
#     def _test_gen_bug():
#         def concat(gen):
#     def is_python_keyword(name):
#     def method(self): pass
# def _func():
# def contextfunction(f):
# def environmentfunction(f):
# def is_undefined(obj):
# def consume(iterable):
# def clear_caches():
# def import_string(import_name, silent=False):
# def open_if_exists(filename, mode='r'):
# def pformat(obj, verbose=False):
# def urlize(text, trim_url_limit=None, nofollow=False):
# def generate_lorem_ipsum(n=5, html=True, min=20, max=100):
#     def __new__(cls, base=u'', encoding=None, errors='strict'):
#     def __html__(self):
#     def __add__(self, other):
#     def __radd__(self, other):
#     def __mul__(self, num):
#     def __mod__(self, arg):
#     def __repr__(self):
#     def join(self, seq):
#     def split(self, *args, **kwargs):
#     def rsplit(self, *args, **kwargs):
#     def splitlines(self, *args, **kwargs):
#     def unescape(self):
#         def handle_match(m):
#     def striptags(self):
#     def escape(cls, s):
#     def make_wrapper(name):
#         def func(self, *args, **kwargs):
# def _escape_argspec(obj, iterable):
#     def __init__(self, obj):
#     def __init__(self, capacity):
#     def _postinit(self):
#     def _remove(self, obj):
#     def __getstate__(self):
#     def __setstate__(self, d):
#     def __getnewargs__(self):
#     def copy(self):
#     def get(self, key, default=None):
#     def setdefault(self, key, default=None):
#     def clear(self):
#     def __contains__(self, key):
#     def __len__(self):
#     def __repr__(self):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __delitem__(self, key):
#     def items(self):
#     def iteritems(self):
#     def values(self):
#     def itervalue(self):
#     def keys(self):
#     def iterkeys(self):
#     def __reversed__(self):
#     def __init__(self, *items):
#     def reset(self):
#     def current(self):
#     def next(self):
#     def __init__(self, sep=u', '):
#     def __call__(self):
#     def escape(s):
#     def soft_unicode(s):
#         def __init__(self, _func, *args, **kwargs):
#         def __call__(self, *args, **kwargs):
# class _C(object):
# class Markup(unicode):
# class _MarkupEscapeHelper(object):
# class LRUCache(object):
# class Cycler(object):
# class Joiner(object):
#     class partial(object):
# 
# Path: jinja2/exceptions.py
# class UndefinedError(TemplateRuntimeError):
#     """Raised if a template tries to operate on :class:`Undefined`."""
# 
# class TemplateRuntimeError(TemplateError):
#     """A generic runtime error in the template engine.  Under some situations
#     Jinja may raise this exception.
#     """


# Path: jinja2/runtime.py
import sys
from itertools import chain, imap
from jinja2.utils import Markup, partial, soft_unicode, escape, missing, \
     concat, MethodType, FunctionType
from jinja2.exceptions import UndefinedError, TemplateRuntimeError
    from collections import Mapping

    Runtime helpers.

    :copyright: Copyright 2008 by Armin Ronacher.
    :license: BSD.
"""


# these variables are exported to the template runtime
__all__ = ['LoopContext', 'Context', 'TemplateReference', 'Macro', 'Markup',
           'TemplateRuntimeError', 'missing', 'concat', 'escape',
           'markup_join', 'unicode_join']


#: the types we support for context functions
_context_function_types = (FunctionType, MethodType)


def markup_join(seq):
    """Concatenation that escapes if necessary and converts to unicode."""
    buf = []
    iterator = imap(soft_unicode, seq)
    for arg in iterator:
        buf.append(arg)
        if hasattr(arg, '__html__'):
            return Markup(u'').join(chain(buf, iterator))
    return concat(buf)


def unicode_join(seq):
    """Simple args to unicode conversion and concatenation."""

    return concat(imap(unicode, seq))