Пример #1
0
def force_escape(value):
    """
    Escapes a string's HTML. This returns a new string containing the escaped
    characters (as opposed to "escape", which marks the content for later
    possible escaping).
    """
    from google.appengine._internal.django.utils.html import escape
    return mark_safe(escape(value))
Пример #2
0
def force_escape(value):
    """
    Escapes a string's HTML. This returns a new string containing the escaped
    characters (as opposed to "escape", which marks the content for later
    possible escaping).
    """
    from google.appengine._internal.django.utils.html import escape
    return mark_safe(escape(value))
Пример #3
0
def linebreaksbr(value, autoescape=None):
    """
    Converts all newlines in a piece of plain text to HTML line breaks
    (``<br />``).
    """
    if autoescape and not isinstance(value, SafeData):
        from google.appengine._internal.django.utils.html import escape
        value = escape(value)
    return mark_safe(value.replace('\n', '<br />'))
Пример #4
0
def linebreaksbr(value, autoescape=None):
    """
    Converts all newlines in a piece of plain text to HTML line breaks
    (``<br />``).
    """
    if autoescape and not isinstance(value, SafeData):
        from google.appengine._internal.django.utils.html import escape
        value = escape(value)
    return mark_safe(value.replace('\n', '<br />'))
Пример #5
0
def _render_value_in_context(value, context):
    """
    Converts any value to a string to become part of a rendered template. This
    means escaping, if required, and conversion to a unicode object. If value
    is a string, it is expected to have already been translated.
    """
    value = localize(value)
    value = force_unicode(value)
    if (context.autoescape and not isinstance(value, SafeData)) or isinstance(value, EscapeData):
        return escape(value)
    else:
        return value
Пример #6
0
def _render_value_in_context(value, context):
    """
    Converts any value to a string to become part of a rendered template. This
    means escaping, if required, and conversion to a unicode object. If value
    is a string, it is expected to have already been translated.
    """
    value = localize(value)
    value = force_unicode(value)
    if (context.autoescape and not isinstance(value, SafeData)) or isinstance(value, EscapeData):
        return escape(value)
    else:
        return value
Пример #7
0
def linenumbers(value, autoescape=None):
    """Displays text with line numbers."""
    from google.appengine._internal.django.utils.html import escape
    lines = value.split(u'\n')
    # Find the maximum width of the line count, for use with zero padding
    # string format command
    width = unicode(len(unicode(len(lines))))
    if not autoescape or isinstance(value, SafeData):
        for i, line in enumerate(lines):
            lines[i] = (u"%0" + width + u"d. %s") % (i + 1, line)
    else:
        for i, line in enumerate(lines):
            lines[i] = (u"%0" + width + u"d. %s") % (i + 1, escape(line))
    return mark_safe(u'\n'.join(lines))
Пример #8
0
def linenumbers(value, autoescape=None):
    """Displays text with line numbers."""
    from google.appengine._internal.django.utils.html import escape
    lines = value.split('\n')
    # Find the maximum width of the line count, for use with zero padding
    # string format command
    width = str(len(str(len(lines))))
    if not autoescape or isinstance(value, SafeData):
        for i, line in enumerate(lines):
            lines[i] = ("%0" + width  + "d. %s") % (i + 1, line)
    else:
        for i, line in enumerate(lines):
            lines[i] = ("%0" + width  + "d. %s") % (i + 1, escape(line))
    return mark_safe('\n'.join(lines))
Пример #9
0
 def render(self, context):
     try:
         output = self.filter_expression.resolve(context)
         output = localize(output)
         output = force_unicode(output)
     except TemplateSyntaxError as e:
         if not hasattr(e, 'source'):
             e.source = self.source
         raise
     except UnicodeDecodeError:
         return ''
     if (context.autoescape and not isinstance(output, SafeData)) or isinstance(output, EscapeData):
         return escape(output)
     else:
         return output
Пример #10
0
            result = node.render(context)
        except TemplateSyntaxError, e:
            if not hasattr(e, 'source'):
                e.source = node.source
            raise
        except Exception, e:
            from sys import exc_info
            wrapped = TemplateSyntaxError(u'Caught %s while rendering: %s' %
                (e.__class__.__name__, force_unicode(e, errors='replace')))
            wrapped.source = node.source
            wrapped.exc_info = exc_info()
            raise wrapped, None, wrapped.exc_info[2]
        return result

class DebugVariableNode(VariableNode):
    def render(self, context):
        try:
            output = self.filter_expression.resolve(context)
            output = localize(output)
            output = force_unicode(output)
        except TemplateSyntaxError, e:
            if not hasattr(e, 'source'):
                e.source = self.source
            raise
        except UnicodeDecodeError:
            return ''
        if (context.autoescape and not isinstance(output, SafeData)) or isinstance(output, EscapeData):
            return escape(output)
        else:
            return output
Пример #11
0
            raise
        except Exception, e:
            from sys import exc_info
            wrapped = TemplateSyntaxError(
                u'Caught %s while rendering: %s' %
                (e.__class__.__name__, force_unicode(e, errors='replace')))
            wrapped.source = node.source
            wrapped.exc_info = exc_info()
            raise wrapped, None, wrapped.exc_info[2]
        return result


class DebugVariableNode(VariableNode):
    def render(self, context):
        try:
            output = self.filter_expression.resolve(context)
            output = localize(output)
            output = force_unicode(output)
        except TemplateSyntaxError, e:
            if not hasattr(e, 'source'):
                e.source = self.source
            raise
        except UnicodeDecodeError:
            return ''
        if (context.autoescape
                and not isinstance(output, SafeData)) or isinstance(
                    output, EscapeData):
            return escape(output)
        else:
            return output