Esempio n. 1
0
def markup_join(seq):
    """Concatenation that escapes if necessary and converts to unicode."""
    buf = []
    iterator = map(soft_unicode, seq)
    for arg in iterator:
        buf.append(arg)
        if hasattr(arg, '__html__'):
            return Markup('').join(chain(buf, iterator))
    return concat(buf)
Esempio n. 2
0
    def render(self, *args, **kwargs):
        """This method accepts the same arguments as the `dict` constructor:
        A dict, a dict subclass or some keyword arguments.  If no arguments
        are given the context will be empty.  These two calls do the same::

            template.render(knights='that say nih')
            template.render({'knights': 'that say nih'})

        This will return the rendered template as unicode string.
        """
        vars = dict(*args, **kwargs)
        try:
            return concat(self.root_render_func(self.new_context(vars)))
        except:
            exc_info = sys.exc_info()
        return self.environment.handle_exception(exc_info, True)
Esempio n. 3
0
        def generator(next):
            buf = []
            c_size = 0
            push = buf.append

            while 1:
                try:
                    while c_size < size:
                        c = next()
                        push(c)
                        if c:
                            c_size += 1
                except StopIteration:
                    if not c_size:
                        return
                yield concat(buf)
                del buf[:]
                c_size = 0
Esempio n. 4
0
def unicode_join(seq):
    """Simple args to unicode conversion and concatenation."""
    return concat(map(str, seq))
Esempio n. 5
0
 def __call__(self):
     rv = concat(self._stack[self._depth](self._context))
     if self._context.eval_ctx.autoescape:
         rv = Markup(rv)
     return rv
Esempio n. 6
0
 def __html__(self):
     return Markup(concat(self._body_stream))
Esempio n. 7
0
 def __str__(self):
     return concat(self._body_stream)