当前位置: 首页>>代码示例>>Python>>正文


Python utils.escape函数代码示例

本文整理汇总了Python中pyramid_debugtoolbar.utils.escape函数的典型用法代码示例。如果您正苦于以下问题:Python escape函数的具体用法?Python escape怎么用?Python escape使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了escape函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render_summary

    def render_summary(self, include_title=True, request=None):
        """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 = text_('Syntax Error')
            else:
                title = text_('Traceback <em>(most recent call last)</em>:')

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

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

        vars = {
            'classes':      text_(' '.join(classes)),
            'title':        title and text_('<h3>%s</h3>' % title) or text_(''),
            'frames':       text_('\n'.join(frames)),
            'description':  text_(description_wrapper % escape(self.exception)),
        }
        return render('pyramid_debugtoolbar:templates/exception_summary.mako',
                      vars, request=request)
开发者ID:Cito,项目名称:pyramid_debugtoolbar,代码行数:35,代码来源:tbtools.py

示例2: render_full

 def render_full(self, request, lodgeit_url=None):
     """Render the Full HTML page with the traceback info."""
     static_path = request.static_url(STATIC_PATH)
     root_path = request.route_url(ROOT_ROUTE_NAME)
     exc = escape(self.exception)
     summary = self.render_summary(include_title=False, request=request)
     qs = {'token': request.exc_history.token, 'tb': str(self.id)}
     url = request.route_url(EXC_ROUTE_NAME, _query=qs)
     evalex = request.exc_history.eval_exc
     vars = {
         'evalex':           evalex and 'true' or 'false',
         'console':          'false',
         'lodgeit_url':      escape(lodgeit_url),
         'title':            exc,
         'exception':        exc,
         'exception_type':   escape(self.exception_type),
         'summary':          summary,
         'plaintext':        self.plaintext,
         'plaintext_cs':     re.sub('-{2,}', '-', self.plaintext),
         'traceback_id':     self.id,
         'static_path':      static_path,
         'token':            request.exc_history.token,
         'root_path':        root_path,
         'url':              url,
     }
     return render('pyramid_debugtoolbar:templates/exception.dbtmako',
                   vars, request=request)
开发者ID:adroullier,项目名称:pyramid_debugtoolbar,代码行数:27,代码来源:tbtools.py

示例3: render

 def render(self):
     """Render a single frame in a traceback."""
     return FRAME_HTML % {
         'id':               self.id,
         'filename':         escape(self.filename),
         'lineno':           self.lineno,
         'function_name':    escape(self.function_name),
         'current_line':     escape(self.current_line.strip())
     }
开发者ID:adroullier,项目名称:pyramid_debugtoolbar,代码行数:9,代码来源:tbtools.py

示例4: render_object_dump

 def render_object_dump(self, items, title, repr=None):
     html_items = []
     for key, value in items:
         html_items.append('<tr><th>%s<td><pre class=repr>%s</pre>' %
                           (escape(key), value))
     if not html_items:
         html_items.append('<tr><td><em>Nothing</em>')
     return OBJECT_DUMP_HTML % {
         'title':    escape(title),
         'repr':     repr and '<pre class=repr>%s</pre>' % repr or '',
         'items':    '\n'.join(html_items)
     }
开发者ID:AaronAsAChimp,项目名称:pyramid_debugtoolbar,代码行数:12,代码来源:repr.py

示例5: fallback_repr

 def fallback_repr(self):
     try:
         info = ''.join(format_exception_only(*sys.exc_info()[:2]))
     except Exception: # pragma: no cover
         info = '?'
     return u'<span class="brokenrepr">&lt;broken repr (%s)&gt;' \
            u'</span>' % escape(info.decode('utf-8', 'ignore').strip())
开发者ID:caseman,项目名称:pyramid_debugtoolbar,代码行数:7,代码来源:repr.py

示例6: py3_text_repr

 def py3_text_repr(self, obj, limit=70):
     buf = ['<span class="string">']
     escaped = escape(obj)
     a = repr(escaped[:limit])
     b = repr(escaped[limit:])
     if b != "''":
         buf.extend((a[:-1], '<span class="extended">', b[1:], '</span>'))
     else:
         buf.append(a)
     buf.append('</span>')
     return _add_subclass_info(text_(''.join(buf)), obj, text_type)
开发者ID:AaronAsAChimp,项目名称:pyramid_debugtoolbar,代码行数:11,代码来源:repr.py

示例7: process_response

    def process_response(self, response):
        self.traceback = traceback = getattr(
            self.request.debug_toolbar, 'traceback', None)
        if self.traceback is not None:
            exc = escape(traceback.exception)
            evalex = self.request.registry.pdtb_eval_exc

            self.data = {
                'evalex': evalex and 'true' or 'false',
                'console': 'false',
                'lodgeit_url': None,
                'title': exc,
                'exception': exc,
                'exception_type': escape(traceback.exception_type),
                'plaintext': traceback.plaintext,
                'plaintext_cs': re.sub('-{2,}', '-', traceback.plaintext),
                'pdtb_token': self.request.registry.pdtb_token,
                'request_id': self.request.pdtb_id,
            }

        # stop hanging onto the request after the response is processed
        del self.request
开发者ID:Pylons,项目名称:pyramid_debugtoolbar,代码行数:22,代码来源:traceback.py

示例8: process_response

    def process_response(self, response):
        self.traceback = traceback = getattr(self.request, 'pdbt_tb', None)
        if self.traceback is not None:
            exc = escape(traceback.exception)
            token = self.request.registry.pdtb_token
            url = '' # self.request.route_url(EXC_ROUTE_NAME, _query=qs)
            evalex = self.exc_history.eval_exc

            self.data = {
                'evalex':           evalex and 'true' or 'false',
                'console':          'false',
                'lodgeit_url':      None,
                'title':            exc,
                'exception':        exc,
                'exception_type':   escape(traceback.exception_type),
                'plaintext':        traceback.plaintext,
                'plaintext_cs':     re.sub('-{2,}', '-', traceback.plaintext),
                'traceback_id':     traceback.id,
                'token':            token,
                'url':              url,
            }

        # stop hanging onto the request after the response is processed
        del self.request
开发者ID:chiho924,项目名称:session05,代码行数:24,代码来源:traceback.py

示例9: process_response

    def process_response(self, response):
        if self.has_content:
            traceback = self.request.pdbt_tb

            exc = escape(traceback.exception)
            summary = Traceback.render_summary(traceback, include_title=False, request=self.request)
            token = self.request.registry.pdtb_token
            url = '' # self.request.route_url(EXC_ROUTE_NAME, _query=qs)
            evalex = self.exc_history.eval_exc

            self.data = {
                'evalex':           evalex and 'true' or 'false',
                'console':          'false',
                'lodgeit_url':      None,
                'title':            exc,
                'exception':        exc,
                'exception_type':   escape(traceback.exception_type),
                'summary':          summary,
                'plaintext':        traceback.plaintext,
                'plaintext_cs':     re.sub('-{2,}', '-', traceback.plaintext),
                'traceback_id':     traceback.id,
                'token':            token,
                'url':              url,
            }
开发者ID:Bedrock02,项目名称:Vigenere,代码行数:24,代码来源:traceback.py

示例10: py2_string_repr

 def py2_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):
         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(text_('').join(buf), obj, (str, unicode))
开发者ID:AaronAsAChimp,项目名称:pyramid_debugtoolbar,代码行数:15,代码来源:repr.py

示例11: test_escape

 def test_escape(self):
     from pyramid_debugtoolbar.utils import escape
     class Foo(str):
         def __html__(self):
             return text_(self)
     assert escape(None) == ''
     assert escape(42) == '42'
     assert escape('<>') == '&lt;&gt;'
     assert escape('"foo"') == '"foo"'
     assert escape('"foo"', True) == '&quot;foo&quot;'
     assert escape(Foo('<foo>')) == '<foo>'
开发者ID:Themanwithoutaplan,项目名称:pyramid_debugtoolbar,代码行数:11,代码来源:test_utils.py

示例12: test_escape

    def test_escape(self):
        from pyramid_debugtoolbar.utils import escape

        class Foo(str):
            def __html__(self):
                return text_(self)

        assert escape(None) == ""
        assert escape(42) == "42"
        assert escape("<>") == "&lt;&gt;"
        assert escape('"foo"') == '"foo"'
        assert escape('"foo"', True) == "&quot;foo&quot;"
        assert escape(Foo("<foo>")) == "<foo>"
开发者ID:Cito,项目名称:pyramid_debugtoolbar,代码行数:13,代码来源:test_utils.py

示例13: writelines

 def writelines(self, x):
     self._write(escape(''.join(x)))
开发者ID:Pylons,项目名称:pyramid_debugtoolbar,代码行数:2,代码来源:console.py

示例14: write

 def write(self, x):
     self._write(escape(x))
开发者ID:Pylons,项目名称:pyramid_debugtoolbar,代码行数:2,代码来源:console.py

示例15: object_repr

 def object_repr(self, obj):
     return text_('<span class="object">%s</span>' % 
                  escape(text_(repr(obj), 'utf-8', 'replace')))
开发者ID:AaronAsAChimp,项目名称:pyramid_debugtoolbar,代码行数:3,代码来源:repr.py


注:本文中的pyramid_debugtoolbar.utils.escape函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。