Python cgitb.enable() Examples
The following are 11
code examples of cgitb.enable().
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: CColorPicker.py From CustomWidgets with GNU General Public License v3.0 | 6 votes |
def test(): import sys import cgitb sys.excepthook = cgitb.enable(1, None, 5, '') from PyQt5.QtWidgets import QApplication, QLabel app = QApplication(sys.argv) def getColor(): ret, color = CColorPicker.getColor() if ret == QDialog.Accepted: r, g, b, a = color.red(), color.green(), color.blue(), color.alpha() label.setText('color: rgba(%d, %d, %d, %d)' % (r, g, b, a)) label.setStyleSheet( 'background: rgba(%d, %d, %d, %d);' % (r, g, b, a)) window = QWidget() window.resize(200, 200) layout = QVBoxLayout(window) label = QLabel('', window, alignment=Qt.AlignCenter) button = QPushButton('点击选择颜色', window, clicked=getColor) layout.addWidget(label) layout.addWidget(button) window.show() sys.exit(app.exec_())
Example #2
Source File: test_cgitb.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_syshook_no_logdir_default_format(self): with temp_dir() as tracedir: rc, out, err = assert_python_failure( '-c', ('import cgitb; cgitb.enable(logdir=%s); ' 'raise ValueError("Hello World")') % repr(tracedir)) out = out.decode(sys.getfilesystemencoding()) self.assertIn("ValueError", out) self.assertIn("Hello World", out) # By default we emit HTML markup. self.assertIn('<p>', out) self.assertIn('</p>', out)
Example #3
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 #4
Source File: test_cgitb.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_syshook_no_logdir_default_format(self): with temp_dir() as tracedir: rc, out, err = assert_python_failure( '-c', ('import cgitb; cgitb.enable(logdir=%s); ' 'raise ValueError("Hello World")') % repr(tracedir)) out = out.decode(sys.getfilesystemencoding()) self.assertIn("ValueError", out) self.assertIn("Hello World", out) # By default we emit HTML markup. self.assertIn('<p>', out) self.assertIn('</p>', out)
Example #5
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 #6
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_default_format(self): with temp_dir() as tracedir: rc, out, err = assert_python_failure( '-c', ('import cgitb; cgitb.enable(logdir=%s); ' 'raise ValueError("Hello World")') % repr(tracedir)) out = out.decode(sys.getfilesystemencoding()) self.assertIn("ValueError", out) self.assertIn("Hello World", out) # By default we emit HTML markup. self.assertIn('<p>', out) self.assertIn('</p>', out)
Example #7
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 #8
Source File: base.py From ppci with BSD 2-Clause "Simplified" License | 5 votes |
def __init__(self, args): self.args = args self.console_handler = None self.file_handler = None self.logger = logging.getLogger() cgitb.enable(format="text") if args.drop_into_pudb: def hook(typ, value, tb): import pudb pudb.post_mortem(tb) sys.excepthook = hook
Example #9
Source File: quick_export.py From rstWeb with MIT License | 5 votes |
def quickexp_main(user, admin, mode, **kwargs): scriptpath = os.path.dirname(os.path.realpath(__file__)) + os.sep userdir = scriptpath + "users" + os.sep theform = kwargs UTF8Writer = codecs.getwriter('utf8') sys.stdout = UTF8Writer(sys.stdout) cgitb.enable() ###GRAPHICAL PARAMETERS### top_spacing = 20 layer_spacing = 60 config = ConfigObj(userdir + 'config.ini') templatedir = scriptpath + config['controltemplates'].replace("/",os.sep) if "quickexp_doc" in theform: current_doc = theform["quickexp_doc"] current_project = theform["quickexp_project"] else: current_doc = "" current_project = "" cpout = "" if mode == "server": cpout += "Content-Type: application/download\n" cpout += "Content-Disposition: attachment; filename=" + current_doc + "\n\n" else: #cpout += "Content-Type: application/download\n\n\n" pass cpout += get_export_string(current_doc,current_project,user) if mode == "server": return cpout else: return bytes(cpout.encode('utf-8')) # Main script when running from Apache
Example #10
Source File: clgen.py From clgen with GNU General Public License v3.0 | 4 votes |
def RunWithErrorHandling( function_to_run: typing.Callable, *args, **kwargs ) -> typing.Any: """ Runs the given method as the main entrypoint to a program. If an exception is thrown, print error message and exit. If FLAGS.debug is set, the exception is not caught. Args: function_to_run: The function to run. *args: Arguments to be passed to the function. **kwargs: Arguments to be passed to the function. Returns: The return value of the function when called with the given args. """ if FLAGS.clgen_debug: # Enable verbose stack traces. See: https://pymotw.com/2/cgitb/ import cgitb cgitb.enable(format="text") return function_to_run(*args, **kwargs) try: def RunContext(): """Run the function with arguments.""" return function_to_run(*args, **kwargs) if prof.is_enabled(): return cProfile.runctx("RunContext()", None, locals(), sort="tottime") else: return RunContext() except app.UsageError as err: # UsageError is handled by the call to app.RunWithArgs(), not here. raise err except errors.UserError as err: app.Error("%s (%s)", err, type(err).__name__) sys.exit(1) except KeyboardInterrupt: Flush() print("\nReceived keyboard interrupt, terminating", file=sys.stderr) sys.exit(1) except errors.File404 as e: Flush() LogException(e) sys.exit(1) except Exception as e: Flush() LogExceptionWithStackTrace(e) sys.exit(1)
Example #11
Source File: clgen.py From clgen with GNU General Public License v3.0 | 4 votes |
def DoFlagsAction( instance: Instance, sample_observers: typing.List[sample_observers_lib.SampleObserver], ) -> None: """Do the action requested by the command line flags. By default, this method trains and samples the instance using the given sample observers. Flags which affect this behaviour are: --print_cache_path={corpus,model,sampler}: Prints the path and returns. --stop_after={corpus,train}: Stops after corpus creation or training, respectively --export_model=<path>: Train the model and export it to the requested path. Args: config: The CLgen instance to act on. sample_observer: A list of sample observers. Unused if no sampling occurs. """ if FLAGS.clgen_profiling: prof.enable() with instance.Session(): if FLAGS.clgen_dashboard_only: instance.Create() return if FLAGS.print_cache_path == "corpus": print(instance.model.corpus.cache.path) return elif FLAGS.print_cache_path == "model": print(instance.model.cache.path) return elif FLAGS.print_cache_path == "sampler": print(instance.model.SamplerCache(instance.sampler)) return elif FLAGS.print_cache_path: raise app.UsageError( f"Invalid --print_cache_path argument: '{FLAGS.print_cache_path}'" ) # The default action is to sample the model. if FLAGS.stop_after == "corpus": instance.model.corpus.Create() elif FLAGS.stop_after == "train": instance.Train() app.Log(1, "Model: %s", instance.model.cache.path) elif FLAGS.stop_after: raise app.UsageError( f"Invalid --stop_after argument: '{FLAGS.stop_after}'" ) elif FLAGS.export_model: instance.ExportPretrainedModel(pathlib.Path(FLAGS.export_model)) else: instance.Sample(sample_observers)