本文整理汇总了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)
示例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)
示例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())
}
示例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)
}
示例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"><broken repr (%s)>' \
u'</span>' % escape(info.decode('utf-8', 'ignore').strip())
示例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)
示例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
示例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
示例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,
}
示例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))
示例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('<>') == '<>'
assert escape('"foo"') == '"foo"'
assert escape('"foo"', True) == '"foo"'
assert escape(Foo('<foo>')) == '<foo>'
示例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("<>") == "<>"
assert escape('"foo"') == '"foo"'
assert escape('"foo"', True) == ""foo""
assert escape(Foo("<foo>")) == "<foo>"
示例13: writelines
def writelines(self, x):
self._write(escape(''.join(x)))
示例14: write
def write(self, x):
self._write(escape(x))
示例15: object_repr
def object_repr(self, obj):
return text_('<span class="object">%s</span>' %
escape(text_(repr(obj), 'utf-8', 'replace')))