本文整理汇总了Python中cgitb.text方法的典型用法代码示例。如果您正苦于以下问题:Python cgitb.text方法的具体用法?Python cgitb.text怎么用?Python cgitb.text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cgitb
的用法示例。
在下文中一共展示了cgitb.text方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _handle
# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def _handle(self, environ):
try:
environ['bottle.app'] = self
request.bind(environ)
response.bind()
route, args = self.router.match(environ)
environ['route.handle'] = route
environ['bottle.route'] = route
environ['route.url_args'] = args
return route.call(**args)
except HTTPResponse:
return _e()
except RouteReset:
route.reset()
return self._handle(environ)
except (KeyboardInterrupt, SystemExit, MemoryError):
raise
except Exception:
if not self.catchall: raise
stacktrace = format_exc()
environ['wsgi.errors'].write(stacktrace)
detailed_tb = cgitb.text(sys.exc_info())
return HTTPError(500, detailed_tb, _e(), stacktrace)
示例2: wsgi
# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def wsgi(self, environ, start_response):
""" The bottle WSGI-interface. """
try:
out = self._cast(self._handle(environ))
# rfc2616 section 4.3
if response._status_code in (100, 101, 204, 304)\
or environ['REQUEST_METHOD'] == 'HEAD':
if hasattr(out, 'close'): out.close()
out = []
start_response(response._status_line, response.headerlist)
return out
except (KeyboardInterrupt, SystemExit, MemoryError):
raise
except Exception:
if not self.catchall: raise
err = '<h1>Critical error while processing request: %s</h1>' \
% html_escape(environ.get('PATH_INFO', '/'))
if DEBUG:
err += '<h2>Error:</h2>\n<pre>\n%s\n</pre>\n' \
'<h2>Traceback:</h2>\n<pre>\n%s\n</pre>\n' \
% (html_escape(repr(_e())), html_escape(format_exc()))
environ['wsgi.errors'].write(err)
headers = [('Content-Type', 'text/html; charset=UTF-8')]
start_response('500 INTERNAL SERVER ERROR', headers)
return [tob(err)]
示例3: auth_basic
# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def auth_basic(check, realm="private", text="Access denied"):
''' Callback decorator to require HTTP auth (basic).
TODO: Add route(check_auth=...) parameter. '''
def decorator(func):
def wrapper(*a, **ka):
user, password = request.auth or (None, None)
if user is None or not check(user, password):
response.headers['WWW-Authenticate'] = 'Basic realm="%s"' % realm
return HTTPError(401, text)
return func(*a, **ka)
return wrapper
return decorator
# Shortcuts for common Bottle methods.
# They all refer to the current default application.
示例4: text_traceback
# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def text_traceback():
with warnings.catch_warnings():
warnings.simplefilter("ignore")
res = 'the original traceback:'.join(
cgitb.text(sys.exc_info()).split('the original traceback:')[1:]
).strip()
return res
示例5: _get_content_as_unicode
# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def _get_content_as_unicode(self, url):
'''
Get remote content as unicode.
We let requests handle the conversion [1] , which will use the
content-type header first or chardet if the header is missing
(requests uses its own embedded chardet version).
As we will be storing and serving the contents as unicode, we actually
replace the original XML encoding declaration with an UTF-8 one.
[1] http://github.com/kennethreitz/requests/blob/63243b1e3b435c7736acf1e51c0f6fa6666d861d/requests/models.py#L811
'''
url = url.replace(' ', '%20')
response = requests.get(url, timeout=10)
content = response.text
# Remove original XML declaration
content = re.sub('<\?xml(.*)\?>', '', content)
# Get rid of the BOM and other rubbish at the beginning of the file
content = re.sub('.*?<', '<', content, 1)
content = content[content.index('<'):]
return content
示例6: test_fonts
# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def test_fonts(self):
text = "Hello Robbie!"
self.assertEqual(cgitb.small(text), "<small>{}</small>".format(text))
self.assertEqual(cgitb.strong(text), "<strong>{}</strong>".format(text))
self.assertEqual(cgitb.grey(text),
'<font color="#909090">{}</font>'.format(text))
示例7: test_text
# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def test_text(self):
try:
raise ValueError("Hello World")
except ValueError as err:
text = cgitb.text(sys.exc_info())
self.assertIn("ValueError", text)
self.assertIn("Hello World", text)
示例8: test_syshook_no_logdir_text_format
# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def test_syshook_no_logdir_text_format(self):
# Issue 12890: we were emitting the <p> tag in text mode.
with temp_dir() as tracedir:
rc, out, err = assert_python_failure(
'-c',
('import cgitb; cgitb.enable(format="text", logdir=%s); '
'raise ValueError("Hello World")') % repr(tracedir))
out = out.decode(sys.getfilesystemencoding())
self.assertIn("ValueError", out)
self.assertIn("Hello World", out)
self.assertNotIn('<p>', out)
self.assertNotIn('</p>', out)
示例9: abort
# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def abort(code=500, text='Unknown Error: Application stopped.'):
""" Aborts execution and causes a HTTP error. """
raise HTTPError(code, text)
示例10: dump_raw_text
# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def dump_raw_text(self, text):
raise NotImplementedError()
示例11: dump_exception
# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def dump_exception(self, einfo):
self.print(cgitb.text(einfo))
示例12: _get_table
# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import text [as 别名]
def _get_table(self, db, tablename, app):
tablename = tablename + '_' + app
table = db.get(tablename)
if not table:
table = db.define_table(
tablename,
db.Field('ticket_id', length=100),
db.Field('ticket_data', 'text'),
db.Field('created_datetime', 'datetime'))
return table