本文整理匯總了Python中werkzeug.debug.tbtools.get_current_traceback方法的典型用法代碼示例。如果您正苦於以下問題:Python tbtools.get_current_traceback方法的具體用法?Python tbtools.get_current_traceback怎麽用?Python tbtools.get_current_traceback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類werkzeug.debug.tbtools
的用法示例。
在下文中一共展示了tbtools.get_current_traceback方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: showtraceback
# 需要導入模塊: from werkzeug.debug import tbtools [as 別名]
# 或者: from werkzeug.debug.tbtools import get_current_traceback [as 別名]
def showtraceback(self):
from werkzeug.debug.tbtools import get_current_traceback
tb = get_current_traceback(skip=1)
sys.stdout._write(tb.render_summary())
示例2: showsyntaxerror
# 需要導入模塊: from werkzeug.debug import tbtools [as 別名]
# 或者: from werkzeug.debug.tbtools import get_current_traceback [as 別名]
def showsyntaxerror(self, filename=None):
from werkzeug.debug.tbtools import get_current_traceback
tb = get_current_traceback(skip=4)
sys.stdout._write(tb.render_summary())
示例3: send_exception
# 需要導入模塊: from werkzeug.debug import tbtools [as 別名]
# 或者: from werkzeug.debug.tbtools import get_current_traceback [as 別名]
def send_exception(subject):
"""Send Python exception tracebacks via email to the ADMINS list.
Use the same HTML styling as Flask tracebacks in debug web servers.
This function must be called while the exception is happening. It picks up the raised exception with sys.exc_info().
Positional arguments:
subject -- subject line of the email (to be prepended by 'Application Error: ').
"""
# Generate and modify html.
tb = tbtools.get_current_traceback() # Get exception information.
with _override_html():
html = tb.render_full().encode('utf-8', 'replace')
html = html.replace('<blockquote>', '<blockquote style="margin: 1em 0 0; padding: 0;">')
subject = 'Application Error: {}'.format(subject)
# Apply throttle.
md5 = hashlib.md5('{}{}'.format(subject, html)).hexdigest()
seconds = int(current_app.config['MAIL_EXCEPTION_THROTTLE'])
lock = redis.lock(EMAIL_THROTTLE.format(md5=md5), timeout=seconds)
have_lock = lock.acquire(blocking=False)
if not have_lock:
LOG.debug('Suppressing email: {}'.format(subject))
return
# Send email.
msg = Message(subject=subject, recipients=current_app.config['ADMINS'], html=html)
mail.send(msg)
示例4: query_error
# 需要導入模塊: from werkzeug.debug import tbtools [as 別名]
# 或者: from werkzeug.debug.tbtools import get_current_traceback [as 別名]
def query_error(e):
tb = get_current_traceback()
return render_template('show_query_error.html', e=e, tb=tb), 500
示例5: exception_handler
# 需要導入模塊: from werkzeug.debug import tbtools [as 別名]
# 或者: from werkzeug.debug.tbtools import get_current_traceback [as 別名]
def exception_handler(e):
tb = get_current_traceback()
last_frame = tb.frames[-1]
last_frame_args = inspect.getargs(last_frame.code)
return render_template('show_error.html',
tb=tb,
last_frame=last_frame,
last_frame_args=last_frame_args), 500
示例6: debug_application
# 需要導入模塊: from werkzeug.debug import tbtools [as 別名]
# 或者: from werkzeug.debug.tbtools import get_current_traceback [as 別名]
def debug_application(self, environ, start_response):
"""Run the application and conserve the traceback frames."""
app_iter = None
try:
app_iter = self.app(environ, start_response)
for item in app_iter:
yield item
if hasattr(app_iter, 'close'):
app_iter.close()
except Exception:
if hasattr(app_iter, 'close'):
app_iter.close()
traceback = get_current_traceback(skip=1, show_hidden_frames=
self.show_hidden_frames,
ignore_system_exceptions=True)
for frame in traceback.frames:
self.frames[frame.id] = frame
self.tracebacks[traceback.id] = traceback
try:
start_response('500 INTERNAL SERVER ERROR', [
('Content-Type', 'text/html; charset=utf-8'),
# Disable Chrome's XSS protection, the debug
# output can cause false-positives.
('X-XSS-Protection', '0'),
])
except Exception:
# if we end up here there has been output but an error
# occurred. in that situation we can do nothing fancy any
# more, better log something into the error log and fall
# back gracefully.
environ['wsgi.errors'].write(
'Debugging middleware caught exception in streamed '
'response at a point where response headers were already '
'sent.\n')
else:
yield traceback.render_full(evalex=self.evalex,
secret=self.secret) \
.encode('utf-8', 'replace')
traceback.log(environ['wsgi.errors'])
示例7: render_exception
# 需要導入模塊: from werkzeug.debug import tbtools [as 別名]
# 或者: from werkzeug.debug.tbtools import get_current_traceback [as 別名]
def render_exception(self):
traceback = get_current_traceback()
for frame in traceback.frames:
self.debug_app.frames[frame.id] = frame
self.debug_app.tracebacks[traceback.id] = traceback
return traceback.render_full(evalex=True,
secret=self.debug_app.secret)