本文整理汇总了Python中pyramid_debugtoolbar.compat.text_函数的典型用法代码示例。如果您正苦于以下问题:Python text_函数的具体用法?Python text_怎么用?Python text_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了text_函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: dispatch_repr
def dispatch_repr(self, obj, recursive):
if obj is helper:
return text_('<span class="help">%r</span>' % helper)
if isinstance(obj, (int, long, float, complex)):
return text_('<span class="number">%r</span>' % obj)
if PY3:
if isinstance(obj, text_type):
return self.py3_text_repr(obj)
if isinstance(obj, binary_type):
return self.py3_binary_repr(obj)
else:
if isinstance(obj, basestring):
return self.py2_string_repr(obj)
if isinstance(obj, RegexType):
return self.regex_repr(obj)
if isinstance(obj, list):
return self.list_repr(obj, recursive)
if isinstance(obj, tuple):
return self.tuple_repr(obj, recursive)
if isinstance(obj, set):
return self.set_repr(obj, recursive)
if isinstance(obj, frozenset):
return self.frozenset_repr(obj, recursive)
if isinstance(obj, dict):
return self.dict_repr(obj, recursive)
if deque is not None and isinstance(obj, deque):
return self.deque_repr(obj, recursive)
return self.object_repr(obj)
开发者ID:AaronAsAChimp,项目名称:pyramid_debugtoolbar,代码行数:28,代码来源:repr.py
示例2: 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
示例3: sse
def sse(request):
response = request.response
response.content_type = 'text/event-stream'
history = request.pdtb_history
response.text = U_BLANK
active_request_id = text_(request.GET.get('request_id'))
client_last_request_id = text_(request.headers.get('Last-Event-Id', 0))
max_visible_requests = get_setting(request.registry.settings,
'max_visible_requests')
if history:
last_request_pair = history.last(1)[0]
last_request_id = last_request_pair[0]
if not last_request_id == client_last_request_id:
data = [
[
_id,
toolbar.json,
'active' if active_request_id == _id else ''
]
for _id, toolbar in history.last(max_visible_requests)
if toolbar.visible
]
if data:
response.text = U_SSE_PAYLOAD.format(last_request_id,
json.dumps(data))
return response
开发者ID:Pylons,项目名称:pyramid_debugtoolbar,代码行数:28,代码来源:toolbar_app.py
示例4: format_sql
def format_sql(query):
if not HAVE_PYGMENTS: # pragma: no cover
return text_(query)
return text_(
highlight(
query, SqlLexer(encoding="utf-8"), HtmlFormatter(encoding="utf-8", noclasses=True, style=PYGMENT_STYLE)
)
)
开发者ID:keitheis,项目名称:pyramid_debugtoolbar,代码行数:9,代码来源:utils.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 text_(
'<span class="brokenrepr"><broken repr (%s)>'
'</span>' % escape(text_(info, 'utf-8', 'ignore').strip())
)
开发者ID:AaronAsAChimp,项目名称:pyramid_debugtoolbar,代码行数:9,代码来源:repr.py
示例6: generate_plaintext_traceback
def generate_plaintext_traceback(self):
"""Like the plaintext attribute but returns a generator"""
yield text_('Traceback (most recent call last):')
for frame in self.frames:
yield text_(' File "%s", line %s, in %s' % (
frame.filename,
frame.lineno,
frame.function_name
))
yield text_(' ' + frame.current_line.strip())
yield text_(self.exception, 'utf-8')
开发者ID:adroullier,项目名称:pyramid_debugtoolbar,代码行数:11,代码来源:tbtools.py
示例7: dict_repr
def dict_repr(self, d, recursive):
if recursive:
return _add_subclass_info(text_('{...}'), d, dict)
buf = ['{']
for idx, (key, value) in enumerate(iteritems_(d)):
if idx:
buf.append(', ')
buf.append('<span class="pair"><span class="key">%s</span>: '
'<span class="value">%s</span></span>' %
(self.repr(key), self.repr(value)))
buf.append('}')
return _add_subclass_info(text_(''.join(buf)), d, dict)
开发者ID:AaronAsAChimp,项目名称:pyramid_debugtoolbar,代码行数:12,代码来源:repr.py
示例8: py3_binary_repr
def py3_binary_repr(self, obj, limit=70):
buf = ['<span class="string">']
escaped = escape(text_(obj, 'utf-8', 'replace'))
a = repr(escaped[:limit])
b = repr(escaped[limit:])
buf.append('b')
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, binary_type)
开发者ID:AaronAsAChimp,项目名称:pyramid_debugtoolbar,代码行数:12,代码来源:repr.py
示例9: regex_repr
def regex_repr(self, obj):
if PY3:
pattern = text_("'%s'" % str(obj.pattern), 'string-escape', 'ignore')
pattern = 'r' + pattern
else:
pattern = text_(repr(obj.pattern), 'string-escape', 'ignore')
if pattern[:1] == 'u':
pattern = 'ur' + pattern[1:]
else:
pattern = 'r' + pattern
return text_(
're.compile(<span class="string regex">%s</span>)' % pattern)
开发者ID:AaronAsAChimp,项目名称:pyramid_debugtoolbar,代码行数:12,代码来源:repr.py
示例10: 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 = text_(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.mako',
vars, request=request)
开发者ID:Cito,项目名称:pyramid_debugtoolbar,代码行数:27,代码来源:tbtools.py
示例11: dict_repr
def dict_repr(self, d, recursive, limit=5):
if recursive:
return _add_subclass_info(text_('{...}'), d, dict)
buf = ['{']
have_extended_section = False
for idx, (key, value) in enumerate(iteritems_(d)):
if idx:
buf.append(', ')
if idx == limit - 1:
buf.append('<span class="extended">')
have_extended_section = True
buf.append('<span class="pair"><span class="key">%s</span>: '
'<span class="value">%s</span></span>' %
(self.repr(key), self.repr(value)))
if have_extended_section:
buf.append('</span>')
buf.append('}')
return _add_subclass_info(text_(''.join(buf)), d, dict)
开发者ID:Cito,项目名称:pyramid_debugtoolbar,代码行数:18,代码来源:repr.py
示例12: proxy
def proxy(self, obj, recursive):
if recursive:
return _add_subclass_info(left + '...' + right, obj, base)
buf = [left]
for idx, item in enumerate(obj):
if idx:
buf.append(', ')
buf.append(self.repr(item))
buf.append(right)
return _add_subclass_info(text_(''.join(buf)), obj, base)
开发者ID:AaronAsAChimp,项目名称:pyramid_debugtoolbar,代码行数:10,代码来源:repr.py
示例13: sse
def sse(request):
response = request.response
response.content_type = 'text/event-stream'
history = find_request_history(request)
response.text = U_BLANK
active_request_id = text_(request.GET.get('request_id'))
client_last_request_id = text_(request.headers.get('Last-Event-Id', 0))
if history:
last_request_pair = history.last(1)[0]
last_request_id = last_request_pair[0]
if not last_request_id == client_last_request_id:
data = [[_id, toolbar.json, 'active'
if active_request_id == _id else '']
for _id,toolbar in history.last(10)]
if data:
response.text = U_SSE_PAYLOAD.format(last_request_id,
json.dumps(data))
return response
开发者ID:kevinruizmayoral,项目名称:zodiac2,代码行数:20,代码来源:views.py
示例14: process_beforerender
def process_beforerender(self, event):
if not self.renderings:
self.renderings = []
name = event["renderer_info"].name
if name and name.startswith("pyramid_debugtoolbar"):
return
val = getattr(event, "rendering_val", "<unknown>")
try:
val = repr(val)
except:
# crazyass code raises an exception during __repr__ (formish)
val = "<unknown>"
self.renderings.append(dict(name=name, system=dictrepr(event), val=text_(val, "utf-8")))
开发者ID:nbasu02,项目名称:pyramid_debugtoolbar,代码行数:13,代码来源:renderings.py
示例15: __call__
def __call__(self, topic=None):
if topic is None:
sys.stdout._write('<span class=help>%s</span>' % repr(self))
return
import pydoc
pydoc.help(topic)
rv = text_(sys.stdout.reset(), 'utf-8', 'ignore')
paragraphs = _paragraph_re.split(rv)
if len(paragraphs) > 1:
title = paragraphs[0]
text = '\n\n'.join(paragraphs[1:])
else: # pragma: no cover
title = 'Help'
text = paragraphs[0]
sys.stdout._write(HELP_HTML % {'title': title, 'text': text})
开发者ID:AaronAsAChimp,项目名称:pyramid_debugtoolbar,代码行数:15,代码来源:repr.py
示例16: 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
示例17: process_beforerender
def process_beforerender(self, event):
if not self.renderings:
self.renderings = []
name = event['renderer_info'].name
if name and name.startswith('pyramid_debugtoolbar'):
return
val = getattr(event, 'rendering_val', '<unknown>')
try:
val = repr(val)
except:
# crazyass code raises an exception during __repr__ (formish)
val = '<unknown>'
self.renderings.append(
dict(name=name, system=dictrepr(event), val=text_(val, 'utf-8'))
)
开发者ID:Rafails,项目名称:MyCalc,代码行数:15,代码来源:renderings.py
示例18: proxy
def proxy(self, obj, recursive):
if recursive:
return _add_subclass_info(left + '...' + right, obj, base)
buf = [left]
have_extended_section = False
for idx, item in enumerate(obj):
if idx:
buf.append(', ')
if idx == limit:
buf.append('<span class="extended">')
have_extended_section = True
buf.append(self.repr(item))
if have_extended_section:
buf.append('</span>')
buf.append(right)
return _add_subclass_info(text_(''.join(buf)), obj, base)
开发者ID:Cito,项目名称:pyramid_debugtoolbar,代码行数:16,代码来源:repr.py
示例19: test_exception_summary
def test_exception_summary(self):
from pyramid.renderers import render
self.config.include("pyramid_jinja2")
request = self._makeRequest()
request.static_url = lambda *arg, **kw: "http://static"
vars = {
"classes": text_("classfoo class&bar"),
"title": text_("<h3>TEH TITLE</h3>"),
"frames": text_("<pre>Frame1</pre><pre>Frame2</pre>"),
}
html = render("pyramid_debugtoolbar:templates/exception_summary.jinja2", vars, request=request)
self.assertTrue(text_('<div class="classfoo class&bar">') in html, html)
self.assertTrue(text_("<h3>TEH TITLE</h3>") in html, html)
self.assertTrue(text_("<pre>Frame1</pre><pre>Frame2</pre>") in html, html)
开发者ID:sundisee,项目名称:appsync-vendor,代码行数:15,代码来源:test_views.py
示例20: __init__
def __init__(self, exc_type, exc_value, tb):
self.lineno = tb.tb_lineno
self.function_name = tb.tb_frame.f_code.co_name
self.locals = tb.tb_frame.f_locals
self.globals = tb.tb_frame.f_globals
fn = inspect.getsourcefile(tb) or inspect.getfile(tb)
if fn[-4:] in ('.pyo', '.pyc'):
fn = fn[:-1]
# if it's a file on the file system resolve the real filename.
if os.path.isfile(fn):
fn = os.path.realpath(fn)
self.filename = fn
self.module = self.globals.get('__name__')
self.loader = self.globals.get('__loader__')
self.code = tb.tb_frame.f_code
# support for paste's traceback extensions
self.hide = self.locals.get('__traceback_hide__', False)
info = self.locals.get('__traceback_info__')
if info is not None:
info = text_(info, errors='replace')
self.info = info
开发者ID:stevepiercy,项目名称:pyramid_debugtoolbar,代码行数:23,代码来源:tbtools.py
注:本文中的pyramid_debugtoolbar.compat.text_函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论