当前位置: 首页>>代码示例>>Python>>正文


Python cgitb.enable方法代码示例

本文整理汇总了Python中cgitb.enable方法的典型用法代码示例。如果您正苦于以下问题:Python cgitb.enable方法的具体用法?Python cgitb.enable怎么用?Python cgitb.enable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cgitb的用法示例。


在下文中一共展示了cgitb.enable方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import enable [as 别名]
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_()) 
开发者ID:PyQt5,项目名称:CustomWidgets,代码行数:27,代码来源:CColorPicker.py

示例2: test_syshook_no_logdir_default_format

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import enable [as 别名]
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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_cgitb.py

示例3: test_syshook_no_logdir_text_format

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import enable [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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_cgitb.py

示例4: __init__

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import enable [as 别名]
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 
开发者ID:windelbouwman,项目名称:ppci,代码行数:17,代码来源:base.py

示例5: quickexp_main

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import enable [as 别名]
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 
开发者ID:amir-zeldes,项目名称:rstWeb,代码行数:43,代码来源:quick_export.py

示例6: RunWithErrorHandling

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import enable [as 别名]
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) 
开发者ID:ChrisCummins,项目名称:clgen,代码行数:54,代码来源:clgen.py

示例7: DoFlagsAction

# 需要导入模块: import cgitb [as 别名]
# 或者: from cgitb import enable [as 别名]
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) 
开发者ID:ChrisCummins,项目名称:clgen,代码行数:55,代码来源:clgen.py


注:本文中的cgitb.enable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。