Python cgitb.text() Examples
The following are 22
code examples of cgitb.text().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cgitb
, or try the search function
.
Example #1
Source File: bottle.py From contrail-server-manager with Apache License 2.0 | 6 votes |
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)
Example #2
Source File: bottle.py From contrail-server-manager with Apache License 2.0 | 6 votes |
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)]
Example #3
Source File: bottle.py From contrail-server-manager with Apache License 2.0 | 6 votes |
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.
Example #4
Source File: bottle.py From contrail-server-manager with Apache License 2.0 | 5 votes |
def abort(code=500, text='Unknown Error: Application stopped.'): """ Aborts execution and causes a HTTP error. """ raise HTTPError(code, text)
Example #5
Source File: restricted.py From termite-visualizations with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #6
Source File: reporting.py From ppci with BSD 2-Clause "Simplified" License | 5 votes |
def dump_raw_text(self, text): """ Spitout text not to be formatted """ self.print("<pre>") self.print(text) self.print("</pre>")
Example #7
Source File: reporting.py From ppci with BSD 2-Clause "Simplified" License | 5 votes |
def dump_exception(self, einfo): self.print(cgitb.text(einfo))
Example #8
Source File: reporting.py From ppci with BSD 2-Clause "Simplified" License | 5 votes |
def dump_raw_text(self, text): self.print(text)
Example #9
Source File: reporting.py From ppci with BSD 2-Clause "Simplified" License | 5 votes |
def dump_raw_text(self, text): pass
Example #10
Source File: reporting.py From ppci with BSD 2-Clause "Simplified" License | 5 votes |
def dump_raw_text(self, text): raise NotImplementedError()
Example #11
Source File: test_cgitb.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #12
Source File: test_cgitb.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #13
Source File: test_cgitb.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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))
Example #14
Source File: base.py From daf-recipes with GNU General Public License v3.0 | 5 votes |
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
Example #15
Source File: test_cgitb.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #16
Source File: test_cgitb.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #17
Source File: test_cgitb.py From ironpython3 with Apache License 2.0 | 5 votes |
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))
Example #18
Source File: test_cgitb.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #19
Source File: test_cgitb.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #20
Source File: test_cgitb.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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))
Example #21
Source File: __init__.py From daf-recipes with GNU General Public License v3.0 | 5 votes |
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
Example #22
Source File: base.py From daf-recipes with GNU General Public License v3.0 | 5 votes |
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