Python werkzeug.utils 模块,escape() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用werkzeug.utils.escape()

项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def render_full(self, evalex=False, secret=None,
                    evalex_trusted=True):
        """Render the Full HTML page with the traceback info."""
        exc = escape(self.exception)
        return PAGE_HTML % {
            'evalex':           evalex and 'true' or 'false',
            'evalex_trusted':   evalex_trusted and 'true' or 'false',
            'console':          'false',
            'title':            exc,
            'exception':        exc,
            'exception_type':   escape(self.exception_type),
            'summary':          self.render_summary(include_title=False),
            'plaintext':        self.plaintext,
            'plaintext_cs':     re.sub('-{2,}', '-', self.plaintext),
            'traceback_id':     self.id,
            'secret':           secret
        }
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def render_line_context(self):
        before, current, after = self.get_context_lines()
        rv = []

        def render_line(line, cls):
            line = line.expandtabs().rstrip()
            stripped_line = line.strip()
            prefix = len(line) - len(stripped_line)
            rv.append(
                '<pre class="line %s"><span class="ws">%s</span>%s</pre>' % (
                    cls, ' ' * prefix, escape(stripped_line) or ' '))

        for line in before:
            render_line(line, 'before')
        render_line(current, 'current')
        for line in after:
            render_line(line, 'after')

        return '\n'.join(rv)
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def render_full(self, evalex=False, secret=None,
                    evalex_trusted=True):
        """Render the Full HTML page with the traceback info."""
        exc = escape(self.exception)
        return PAGE_HTML % {
            'evalex':           evalex and 'true' or 'false',
            'evalex_trusted':   evalex_trusted and 'true' or 'false',
            'console':          'false',
            'title':            exc,
            'exception':        exc,
            'exception_type':   escape(self.exception_type),
            'summary':          self.render_summary(include_title=False),
            'plaintext':        escape(self.plaintext),
            'plaintext_cs':     re.sub('-{2,}', '-', self.plaintext),
            'traceback_id':     self.id,
            'secret':           secret
        }
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def render_line_context(self):
        before, current, after = self.get_context_lines()
        rv = []

        def render_line(line, cls):
            line = line.expandtabs().rstrip()
            stripped_line = line.strip()
            prefix = len(line) - len(stripped_line)
            rv.append(
                '<pre class="line %s"><span class="ws">%s</span>%s</pre>' % (
                    cls, ' ' * prefix, escape(stripped_line) or ' '))

        for line in before:
            render_line(line, 'before')
        render_line(current, 'current')
        for line in after:
            render_line(line, 'after')

        return '\n'.join(rv)
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def render_full(self, evalex=False, secret=None,
                    evalex_trusted=True):
        """Render the Full HTML page with the traceback info."""
        exc = escape(self.exception)
        return PAGE_HTML % {
            'evalex':           evalex and 'true' or 'false',
            'evalex_trusted':   evalex_trusted and 'true' or 'false',
            'console':          'false',
            'title':            exc,
            'exception':        exc,
            'exception_type':   escape(self.exception_type),
            'summary':          self.render_summary(include_title=False),
            'plaintext':        self.plaintext,
            'plaintext_cs':     re.sub('-{2,}', '-', self.plaintext),
            'traceback_id':     self.id,
            'secret':           secret
        }
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def render_line_context(self):
        before, current, after = self.get_context_lines()
        rv = []

        def render_line(line, cls):
            line = line.expandtabs().rstrip()
            stripped_line = line.strip()
            prefix = len(line) - len(stripped_line)
            rv.append(
                '<pre class="line %s"><span class="ws">%s</span>%s</pre>' % (
                    cls, ' ' * prefix, escape(stripped_line) or ' '))

        for line in before:
            render_line(line, 'before')
        render_line(current, 'current')
        for line in after:
            render_line(line, 'after')

        return '\n'.join(rv)
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def runsource(self, source):
        source = source.rstrip() + '\n'
        ThreadedStream.push()
        prompt = self.more and '... ' or '>>> '
        try:
            source_to_eval = ''.join(self.buffer + [source])
            if code.InteractiveInterpreter.runsource(self,
                                                     source_to_eval, '<debugger>', 'single'):
                self.more = True
                self.buffer.append(source)
            else:
                self.more = False
                del self.buffer[:]
        finally:
            output = ThreadedStream.fetch()
        return prompt + escape(source) + output
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def render_line_context(self):
        before, current, after = self.get_context_lines()
        rv = []

        def render_line(line, cls):
            line = line.expandtabs().rstrip()
            stripped_line = line.strip()
            prefix = len(line) - len(stripped_line)
            rv.append(
                '<pre class="line %s"><span class="ws">%s</span>%s</pre>' % (
                    cls, ' ' * prefix, escape(stripped_line) or ' '))

        for line in before:
            render_line(line, 'before')
        render_line(current, 'current')
        for line in after:
            render_line(line, 'after')

        return '\n'.join(rv)
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def runsource(self, source):
        source = source.rstrip() + '\n'
        ThreadedStream.push()
        prompt = self.more and '... ' or '>>> '
        try:
            source_to_eval = ''.join(self.buffer + [source])
            if code.InteractiveInterpreter.runsource(self,
                                                     source_to_eval, '<debugger>', 'single'):
                self.more = True
                self.buffer.append(source)
            else:
                self.more = False
                del self.buffer[:]
        finally:
            output = ThreadedStream.fetch()
        return prompt + escape(source) + output
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def render_full(self, evalex=False, secret=None,
                    evalex_trusted=True):
        """Render the Full HTML page with the traceback info."""
        exc = escape(self.exception)
        return PAGE_HTML % {
            'evalex':           evalex and 'true' or 'false',
            'evalex_trusted':   evalex_trusted and 'true' or 'false',
            'console':          'false',
            'title':            exc,
            'exception':        exc,
            'exception_type':   escape(self.exception_type),
            'summary':          self.render_summary(include_title=False),
            'plaintext':        escape(self.plaintext),
            'plaintext_cs':     re.sub('-{2,}', '-', self.plaintext),
            'traceback_id':     self.id,
            'secret':           secret
        }
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def render_line_context(self):
        before, current, after = self.get_context_lines()
        rv = []

        def render_line(line, cls):
            line = line.expandtabs().rstrip()
            stripped_line = line.strip()
            prefix = len(line) - len(stripped_line)
            rv.append(
                '<pre class="line %s"><span class="ws">%s</span>%s</pre>' % (
                    cls, ' ' * prefix, escape(stripped_line) or ' '))

        for line in before:
            render_line(line, 'before')
        render_line(current, 'current')
        for line in after:
            render_line(line, 'after')

        return '\n'.join(rv)
项目:harbour-sailfinder    作者:DylanVanAssche    | 项目源码 | 文件源码
def render_full(self, evalex=False, secret=None,
                    evalex_trusted=True):
        """Render the Full HTML page with the traceback info."""
        exc = escape(self.exception)
        return PAGE_HTML % {
            'evalex':           evalex and 'true' or 'false',
            'evalex_trusted':   evalex_trusted and 'true' or 'false',
            'console':          'false',
            'title':            exc,
            'exception':        exc,
            'exception_type':   escape(self.exception_type),
            'summary':          self.render_summary(include_title=False),
            'plaintext':        escape(self.plaintext),
            'plaintext_cs':     re.sub('-{2,}', '-', self.plaintext),
            'traceback_id':     self.id,
            'secret':           secret
        }
项目:harbour-sailfinder    作者:DylanVanAssche    | 项目源码 | 文件源码
def render_line_context(self):
        before, current, after = self.get_context_lines()
        rv = []

        def render_line(line, cls):
            line = line.expandtabs().rstrip()
            stripped_line = line.strip()
            prefix = len(line) - len(stripped_line)
            rv.append(
                '<pre class="line %s"><span class="ws">%s</span>%s</pre>' % (
                    cls, ' ' * prefix, escape(stripped_line) or ' '))

        for line in before:
            render_line(line, 'before')
        render_line(current, 'current')
        for line in after:
            render_line(line, 'after')

        return '\n'.join(rv)
项目:harbour-sailfinder    作者:DylanVanAssche    | 项目源码 | 文件源码
def render_full(self, evalex=False, secret=None,
                    evalex_trusted=True):
        """Render the Full HTML page with the traceback info."""
        exc = escape(self.exception)
        return PAGE_HTML % {
            'evalex':           evalex and 'true' or 'false',
            'evalex_trusted':   evalex_trusted and 'true' or 'false',
            'console':          'false',
            'title':            exc,
            'exception':        exc,
            'exception_type':   escape(self.exception_type),
            'summary':          self.render_summary(include_title=False),
            'plaintext':        escape(self.plaintext),
            'plaintext_cs':     re.sub('-{2,}', '-', self.plaintext),
            'traceback_id':     self.id,
            'secret':           secret
        }
项目:harbour-sailfinder    作者:DylanVanAssche    | 项目源码 | 文件源码
def render_line_context(self):
        before, current, after = self.get_context_lines()
        rv = []

        def render_line(line, cls):
            line = line.expandtabs().rstrip()
            stripped_line = line.strip()
            prefix = len(line) - len(stripped_line)
            rv.append(
                '<pre class="line %s"><span class="ws">%s</span>%s</pre>' % (
                    cls, ' ' * prefix, escape(stripped_line) or ' '))

        for line in before:
            render_line(line, 'before')
        render_line(current, 'current')
        for line in after:
            render_line(line, 'after')

        return '\n'.join(rv)
项目:Texty    作者:sarthfrey    | 项目源码 | 文件源码
def render_full(self, evalex=False, secret=None,
                    evalex_trusted=True):
        """Render the Full HTML page with the traceback info."""
        exc = escape(self.exception)
        return PAGE_HTML % {
            'evalex':           evalex and 'true' or 'false',
            'evalex_trusted':   evalex_trusted and 'true' or 'false',
            'console':          'false',
            'title':            exc,
            'exception':        exc,
            'exception_type':   escape(self.exception_type),
            'summary':          self.render_summary(include_title=False),
            'plaintext':        self.plaintext,
            'plaintext_cs':     re.sub('-{2,}', '-', self.plaintext),
            'traceback_id':     self.id,
            'secret':           secret
        }
项目:Texty    作者:sarthfrey    | 项目源码 | 文件源码
def render_line_context(self):
        before, current, after = self.get_context_lines()
        rv = []

        def render_line(line, cls):
            line = line.expandtabs().rstrip()
            stripped_line = line.strip()
            prefix = len(line) - len(stripped_line)
            rv.append(
                '<pre class="line %s"><span class="ws">%s</span>%s</pre>' % (
                    cls, ' ' * prefix, escape(stripped_line) or ' '))

        for line in before:
            render_line(line, 'before')
        render_line(current, 'current')
        for line in after:
            render_line(line, 'after')

        return '\n'.join(rv)
项目:RPoint    作者:george17-meet    | 项目源码 | 文件源码
def runsource(self, source):
        source = source.rstrip() + '\n'
        ThreadedStream.push()
        prompt = self.more and '... ' or '>>> '
        try:
            source_to_eval = ''.join(self.buffer + [source])
            if code.InteractiveInterpreter.runsource(self,
                                                     source_to_eval, '<debugger>', 'single'):
                self.more = True
                self.buffer.append(source)
            else:
                self.more = False
                del self.buffer[:]
        finally:
            output = ThreadedStream.fetch()
        return prompt + escape(source) + output
项目:RPoint    作者:george17-meet    | 项目源码 | 文件源码
def render_line_context(self):
        before, current, after = self.get_context_lines()
        rv = []

        def render_line(line, cls):
            line = line.expandtabs().rstrip()
            stripped_line = line.strip()
            prefix = len(line) - len(stripped_line)
            rv.append(
                '<pre class="line %s"><span class="ws">%s</span>%s</pre>' % (
                    cls, ' ' * prefix, escape(stripped_line) or ' '))

        for line in before:
            render_line(line, 'before')
        render_line(current, 'current')
        for line in after:
            render_line(line, 'after')

        return '\n'.join(rv)
项目:isni-reconcile    作者:cmh2166    | 项目源码 | 文件源码
def render_full(self, evalex=False, secret=None,
                    evalex_trusted=True):
        """Render the Full HTML page with the traceback info."""
        exc = escape(self.exception)
        return PAGE_HTML % {
            'evalex':           evalex and 'true' or 'false',
            'evalex_trusted':   evalex_trusted and 'true' or 'false',
            'console':          'false',
            'title':            exc,
            'exception':        exc,
            'exception_type':   escape(self.exception_type),
            'summary':          self.render_summary(include_title=False),
            'plaintext':        self.plaintext,
            'plaintext_cs':     re.sub('-{2,}', '-', self.plaintext),
            'traceback_id':     self.id,
            'secret':           secret
        }
项目:isni-reconcile    作者:cmh2166    | 项目源码 | 文件源码
def render_line_context(self):
        before, current, after = self.get_context_lines()
        rv = []

        def render_line(line, cls):
            line = line.expandtabs().rstrip()
            stripped_line = line.strip()
            prefix = len(line) - len(stripped_line)
            rv.append(
                '<pre class="line %s"><span class="ws">%s</span>%s</pre>' % (
                    cls, ' ' * prefix, escape(stripped_line) or ' '))

        for line in before:
            render_line(line, 'before')
        render_line(current, 'current')
        for line in after:
            render_line(line, 'after')

        return '\n'.join(rv)
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def write(self, x):
        self._write(escape(x))
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def writelines(self, x):
        self._write(escape(''.join(x)))
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def render(self):
        return SOURCE_LINE_HTML % {
            'classes':      u' '.join(self.classes),
            'lineno':       self.lineno,
            'code':         escape(self.code)
        }
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def render_summary(self, include_title=True):
        """Render the traceback for the interactive console."""
        title = ''
        frames = []
        classes = ['traceback']
        if not self.frames:
            classes.append('noframe-traceback')

        if include_title:
            if self.is_syntax_error:
                title = u'Syntax Error'
            else:
                title = u'Traceback <em>(most recent call last)</em>:'

        for frame in self.frames:
            frames.append(u'<li%s>%s' % (
                frame.info and u' title="%s"' % escape(frame.info) or u'',
                frame.render()
            ))

        if self.is_syntax_error:
            description_wrapper = u'<pre class=syntaxerror>%s</pre>'
        else:
            description_wrapper = u'<blockquote>%s</blockquote>'

        return SUMMARY_HTML % {
            'classes':      u' '.join(classes),
            'title':        title and u'<h3>%s</h3>' % title or u'',
            'frames':       u'\n'.join(frames),
            'description':  description_wrapper % escape(self.exception)
        }
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def regex_repr(self, obj):
        pattern = repr(obj.pattern)
        if PY2:
            pattern = pattern.decode('string-escape', 'ignore')
        else:
            pattern = codecs.decode(pattern, 'unicode-escape', 'ignore')
        if pattern[:1] == 'u':
            pattern = 'ur' + pattern[1:]
        else:
            pattern = 'r' + pattern
        return u're.compile(<span class="string regex">%s</span>)' % pattern
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def string_repr(self, obj, limit=70):
        buf = ['<span class="string">']
        escaped = escape(obj)
        a = repr(escaped[:limit])
        b = repr(escaped[limit:])
        if isinstance(obj, text_type) and PY2:
            buf.append('u')
            a = a[1:]
            b = b[1:]
        if b != "''":
            buf.extend((a[:-1], '<span class="extended">', b[1:], '</span>'))
        else:
            buf.append(a)
        buf.append('</span>')
        return _add_subclass_info(u''.join(buf), obj, (bytes, text_type))
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def object_repr(self, obj):
        r = repr(obj)
        if PY2:
            r = r.decode('utf-8', 'replace')
        return u'<span class="object">%s</span>' % escape(r)
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def fallback_repr(self):
        try:
            info = ''.join(format_exception_only(*sys.exc_info()[:2]))
        except Exception:  # pragma: no cover
            info = '?'
        if PY2:
            info = info.decode('utf-8', 'ignore')
        return u'<span class="brokenrepr">&lt;broken repr (%s)&gt;' \
               u'</span>' % escape(info.strip())
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def _make_text_block(name, content, content_type=None):
    """Helper function for the builder that creates an XML text block."""
    if content_type == 'xhtml':
        return u'<%s type="xhtml"><div xmlns="%s">%s</div></%s>\n' % \
               (name, XHTML_NAMESPACE, content, name)
    if not content_type:
        return u'<%s>%s</%s>\n' % (name, escape(content), name)
    return u'<%s type="%s">%s</%s>\n' % (name, content_type,
                                         escape(content), name)
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def generate(self):
        """Yields pieces of ATOM XML."""
        base = ''
        if self.xml_base:
            base = ' xml:base="%s"' % escape(self.xml_base)
        yield u'<entry%s>\n' % base
        yield u'  ' + _make_text_block('title', self.title, self.title_type)
        yield u'  <id>%s</id>\n' % escape(self.id)
        yield u'  <updated>%s</updated>\n' % format_iso8601(self.updated)
        if self.published:
            yield u'  <published>%s</published>\n' % \
                  format_iso8601(self.published)
        if self.url:
            yield u'  <link href="%s" />\n' % escape(self.url)
        for author in self.author:
            yield u'  <author>\n'
            yield u'    <name>%s</name>\n' % escape(author['name'])
            if 'uri' in author:
                yield u'    <uri>%s</uri>\n' % escape(author['uri'])
            if 'email' in author:
                yield u'    <email>%s</email>\n' % escape(author['email'])
            yield u'  </author>\n'
        for link in self.links:
            yield u'  <link %s/>\n' % ''.join('%s="%s" ' %
                                              (k, escape(link[k])) for k in link)
        for category in self.categories:
            yield u'  <category %s/>\n' % ''.join('%s="%s" ' %
                                                  (k, escape(category[k])) for k in category)
        if self.summary:
            yield u'  ' + _make_text_block('summary', self.summary,
                                           self.summary_type)
        if self.content:
            yield u'  ' + _make_text_block('content', self.content,
                                           self.content_type)
        yield u'</entry>\n'
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def get_description(self, environ=None):
        """Get the description."""
        return u'<p>%s</p>' % escape(self.description)
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def write(self, x):
        self._write(escape(x))
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def writelines(self, x):
        self._write(escape(''.join(x)))
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def render(self):
        return SOURCE_LINE_HTML % {
            'classes':      u' '.join(self.classes),
            'lineno':       self.lineno,
            'code':         escape(self.code)
        }
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def render_summary(self, include_title=True):
        """Render the traceback for the interactive console."""
        title = ''
        frames = []
        classes = ['traceback']
        if not self.frames:
            classes.append('noframe-traceback')

        if include_title:
            if self.is_syntax_error:
                title = u'Syntax Error'
            else:
                title = u'Traceback <em>(most recent call last)</em>:'

        for frame in self.frames:
            frames.append(u'<li%s>%s' % (
                frame.info and u' title="%s"' % escape(frame.info) or u'',
                frame.render()
            ))

        if self.is_syntax_error:
            description_wrapper = u'<pre class=syntaxerror>%s</pre>'
        else:
            description_wrapper = u'<blockquote>%s</blockquote>'

        return SUMMARY_HTML % {
            'classes':      u' '.join(classes),
            'title':        title and u'<h3>%s</h3>' % title or u'',
            'frames':       u'\n'.join(frames),
            'description':  description_wrapper % escape(self.exception)
        }
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def regex_repr(self, obj):
        pattern = repr(obj.pattern)
        if PY2:
            pattern = pattern.decode('string-escape', 'ignore')
        else:
            pattern = codecs.decode(pattern, 'unicode-escape', 'ignore')
        if pattern[:1] == 'u':
            pattern = 'ur' + pattern[1:]
        else:
            pattern = 'r' + pattern
        return u're.compile(<span class="string regex">%s</span>)' % pattern
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def string_repr(self, obj, limit=70):
        buf = ['<span class="string">']
        escaped = escape(obj)
        a = repr(escaped[:limit])
        b = repr(escaped[limit:])
        if isinstance(obj, text_type) and PY2:
            buf.append('u')
            a = a[1:]
            b = b[1:]
        if b != "''":
            buf.extend((a[:-1], '<span class="extended">', b[1:], '</span>'))
        else:
            buf.append(a)
        buf.append('</span>')
        return _add_subclass_info(u''.join(buf), obj, (bytes, text_type))
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def object_repr(self, obj):
        r = repr(obj)
        if PY2:
            r = r.decode('utf-8', 'replace')
        return u'<span class="object">%s</span>' % escape(r)
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def fallback_repr(self):
        try:
            info = ''.join(format_exception_only(*sys.exc_info()[:2]))
        except Exception:  # pragma: no cover
            info = '?'
        if PY2:
            info = info.decode('utf-8', 'ignore')
        return u'<span class="brokenrepr">&lt;broken repr (%s)&gt;' \
               u'</span>' % escape(info.strip())
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def _make_text_block(name, content, content_type=None):
    """Helper function for the builder that creates an XML text block."""
    if content_type == 'xhtml':
        return u'<%s type="xhtml"><div xmlns="%s">%s</div></%s>\n' % \
               (name, XHTML_NAMESPACE, content, name)
    if not content_type:
        return u'<%s>%s</%s>\n' % (name, escape(content), name)
    return u'<%s type="%s">%s</%s>\n' % (name, content_type,
                                         escape(content), name)
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def generate(self):
        """Yields pieces of ATOM XML."""
        base = ''
        if self.xml_base:
            base = ' xml:base="%s"' % escape(self.xml_base)
        yield u'<entry%s>\n' % base
        yield u'  ' + _make_text_block('title', self.title, self.title_type)
        yield u'  <id>%s</id>\n' % escape(self.id)
        yield u'  <updated>%s</updated>\n' % format_iso8601(self.updated)
        if self.published:
            yield u'  <published>%s</published>\n' % \
                  format_iso8601(self.published)
        if self.url:
            yield u'  <link href="%s" />\n' % escape(self.url)
        for author in self.author:
            yield u'  <author>\n'
            yield u'    <name>%s</name>\n' % escape(author['name'])
            if 'uri' in author:
                yield u'    <uri>%s</uri>\n' % escape(author['uri'])
            if 'email' in author:
                yield u'    <email>%s</email>\n' % escape(author['email'])
            yield u'  </author>\n'
        for link in self.links:
            yield u'  <link %s/>\n' % ''.join('%s="%s" ' %
                                              (k, escape(link[k])) for k in link)
        for category in self.categories:
            yield u'  <category %s/>\n' % ''.join('%s="%s" ' %
                                                  (k, escape(category[k])) for k in category)
        if self.summary:
            yield u'  ' + _make_text_block('summary', self.summary,
                                           self.summary_type)
        if self.content:
            yield u'  ' + _make_text_block('content', self.content,
                                           self.content_type)
        yield u'</entry>\n'
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def get_description(self, environ=None):
        """Get the description."""
        return u'<p>%s</p>' % escape(self.description)
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def write(self, x):
        self._write(escape(x))
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def writelines(self, x):
        self._write(escape(''.join(x)))
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def render(self):
        return SOURCE_LINE_HTML % {
            'classes':      u' '.join(self.classes),
            'lineno':       self.lineno,
            'code':         escape(self.code)
        }
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def render_summary(self, include_title=True):
        """Render the traceback for the interactive console."""
        title = ''
        frames = []
        classes = ['traceback']
        if not self.frames:
            classes.append('noframe-traceback')

        if include_title:
            if self.is_syntax_error:
                title = u'Syntax Error'
            else:
                title = u'Traceback <em>(most recent call last)</em>:'

        for frame in self.frames:
            frames.append(u'<li%s>%s' % (
                frame.info and u' title="%s"' % escape(frame.info) or u'',
                frame.render()
            ))

        if self.is_syntax_error:
            description_wrapper = u'<pre class=syntaxerror>%s</pre>'
        else:
            description_wrapper = u'<blockquote>%s</blockquote>'

        return SUMMARY_HTML % {
            'classes':      u' '.join(classes),
            'title':        title and u'<h3>%s</h3>' % title or u'',
            'frames':       u'\n'.join(frames),
            'description':  description_wrapper % escape(self.exception)
        }
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def regex_repr(self, obj):
        pattern = repr(obj.pattern)
        if PY2:
            pattern = pattern.decode('string-escape', 'ignore')
        else:
            pattern = codecs.decode(pattern, 'unicode-escape', 'ignore')
        if pattern[:1] == 'u':
            pattern = 'ur' + pattern[1:]
        else:
            pattern = 'r' + pattern
        return u're.compile(<span class="string regex">%s</span>)' % pattern
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def string_repr(self, obj, limit=70):
        buf = ['<span class="string">']
        escaped = escape(obj)
        a = repr(escaped[:limit])
        b = repr(escaped[limit:])
        if isinstance(obj, text_type) and PY2:
            buf.append('u')
            a = a[1:]
            b = b[1:]
        if b != "''":
            buf.extend((a[:-1], '<span class="extended">', b[1:], '</span>'))
        else:
            buf.append(a)
        buf.append('</span>')
        return _add_subclass_info(u''.join(buf), obj, (bytes, text_type))
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def object_repr(self, obj):
        r = repr(obj)
        if PY2:
            r = r.decode('utf-8', 'replace')
        return u'<span class="object">%s</span>' % escape(r)