我们从Python开源项目中,提取了以下19个代码示例,用于说明如何使用cgitb.text()。
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
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
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
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))
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)
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)