• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python tools.print_exception函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中xonsh.tools.print_exception函数的典型用法代码示例。如果您正苦于以下问题:Python print_exception函数的具体用法?Python print_exception怎么用?Python print_exception使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: _wizard

def _wizard(ns):
    env = builtins.__xonsh__.env
    shell = builtins.__xonsh__.shell.shell
    fname = env.get("XONSHRC")[-1] if ns.file is None else ns.file
    no_wiz = os.path.join(env.get("XONSH_CONFIG_DIR"), "no-wizard")
    w = make_xonfig_wizard(
        default_file=fname, confirm=ns.confirm, no_wizard_file=no_wiz
    )
    tempenv = {"PROMPT": "", "XONSH_STORE_STDOUT": False}
    pv = wiz.PromptVisitor(w, store_in_history=False, multiline=False)

    @contextlib.contextmanager
    def force_hide():
        if env.get("XONSH_STORE_STDOUT") and hasattr(shell, "_force_hide"):
            orig, shell._force_hide = shell._force_hide, False
            yield
            shell._force_hide = orig
        else:
            yield

    with force_hide(), env.swap(tempenv):
        try:
            pv.visit()
        except (KeyboardInterrupt, Exception):
            print()
            print_exception()
开发者ID:ericmharris,项目名称:xonsh,代码行数:26,代码来源:xonfig.py


示例2: default

 def default(self, line):
     """Implements code execution."""
     line = line if line.endswith('\n') else line + '\n'
     src, code = self.push(line)
     if code is None:
         return
     env = builtins.__xonsh_env__
     hist = builtins.__xonsh_history__  # pylint: disable=no-member
     ts1 = None
     enc = env.get('XONSH_ENCODING')
     err = env.get('XONSH_ENCODING_ERRORS')
     tee = Tee(encoding=enc, errors=err)
     try:
         ts0 = time.time()
         run_compiled_code(code, self.ctx, None, 'single')
         ts1 = time.time()
         if hist is not None and hist.last_cmd_rtn is None:
             hist.last_cmd_rtn = 0  # returncode for success
     except XonshError as e:
         print(e.args[0], file=sys.stderr)
         if hist is not None and hist.last_cmd_rtn is None:
             hist.last_cmd_rtn = 1  # return code for failure
     except Exception:  # pylint: disable=broad-except
         print_exception()
         if hist is not None and hist.last_cmd_rtn is None:
             hist.last_cmd_rtn = 1  # return code for failure
     finally:
         ts1 = ts1 or time.time()
         self._append_history(inp=src, ts=[ts0, ts1], tee_out=tee.getvalue())
         tee.close()
         self._fix_cwd()
     if builtins.__xonsh_exit__:  # pylint: disable=no-member
         return True
开发者ID:vsajip,项目名称:xonsh,代码行数:33,代码来源:base_shell.py


示例3: push

 def push(self, line):
     """Pushes a line onto the buffer and compiles the code in a way that
     enables multiline input.
     """
     code = None
     self.buffer.append(line)
     if self.need_more_lines:
         return None, code
     src = ''.join(self.buffer)
     try:
         code = self.execer.compile(src,
                                    mode='single',
                                    glbs=None,
                                    locs=self.ctx)
         self.reset_buffer()
     except SyntaxError:
         if line == '\n':
             self.reset_buffer()
             print_exception()
             return src, None
         self.need_more_lines = True
     except Exception:  # pylint: disable=broad-except
         self.reset_buffer()
         print_exception()
         return src, None
     return src, code
开发者ID:gitter-badger,项目名称:xonsh,代码行数:26,代码来源:base_shell.py


示例4: compile

 def compile(self, src):
     """Compiles source code and returns the (possibly modified) source and
     a valid code object.
     """
     _cache = should_use_cache(self.execer, 'single')
     if _cache:
         codefname = code_cache_name(src)
         cachefname = get_cache_filename(codefname, code=True)
         usecache, code = code_cache_check(cachefname)
         if usecache:
             self.reset_buffer()
             return src, code
     try:
         code = self.execer.compile(src,
                                    mode='single',
                                    glbs=self.ctx,
                                    locs=None)
         if _cache:
             update_cache(code, cachefname)
         self.reset_buffer()
     except SyntaxError:
         partial_string_info = check_for_partial_string(src)
         in_partial_string = (partial_string_info[0] is not None and
                              partial_string_info[1] is None)
         if (src == '\n' or src.endswith('\n\n')) and not in_partial_string:
             self.reset_buffer()
             print_exception()
             return src, None
         self.need_more_lines = True
         code = None
     except Exception:  # pylint: disable=broad-except
         self.reset_buffer()
         print_exception()
         code = None
     return src, code
开发者ID:vsajip,项目名称:xonsh,代码行数:35,代码来源:base_shell.py


示例5: transform_command

def transform_command(src, show_diff=True):
    """Returns the results of firing the precommand handles."""
    i = 0
    limit = sys.getrecursionlimit()
    lst = ""
    raw = src
    while src != lst:
        lst = src
        srcs = events.on_transform_command.fire(cmd=src)
        for s in srcs:
            if s != lst:
                src = s
                break
        i += 1
        if i == limit:
            print_exception(
                "Modifications to source input took more than "
                "the recursion limit number of iterations to "
                "converge."
            )
    debug_level = builtins.__xonsh__.env.get("XONSH_DEBUG")
    if show_diff and debug_level > 1 and src != raw:
        sys.stderr.writelines(
            difflib.unified_diff(
                raw.splitlines(keepends=True),
                src.splitlines(keepends=True),
                fromfile="before precommand event",
                tofile="after precommand event",
            )
        )
    return src
开发者ID:donnemartin,项目名称:gitsome,代码行数:31,代码来源:shell.py


示例6: fire_precommand

def fire_precommand(src, show_diff=True):
    """Returns the results of firing the precommand handles."""
    i = 0
    limit = sys.getrecursionlimit()
    lst = ''
    raw = src
    while src != lst:
        lst = src
        srcs = events.on_precommand.fire(src)
        for s in srcs:
            if s != lst:
                src = s
                break
        i += 1
        if i == limit:
            print_exception('Modifcations to source input took more than '
                            'the recursion limit number of interations to '
                            'converge.')
    debug_level = builtins.__xonsh_env__.get('XONSH_DEBUG')
    if show_diff and debug_level > 1 and src != raw:
        sys.stderr.writelines(difflib.unified_diff(
            raw.splitlines(keepends=True),
            src.splitlines(keepends=True),
            fromfile='before precommand event',
            tofile='after precommand event',
        ))
    return src
开发者ID:vsajip,项目名称:xonsh,代码行数:27,代码来源:shell.py


示例7: default

 def default(self, line):
     """Implements code execution."""
     line = line if line.endswith('\n') else line + '\n'
     src, code = self.push(line)
     if code is None:
         return
     hist = builtins.__xonsh_history__  # pylint: disable=no-member
     ts1 = None
     store_stdout = builtins.__xonsh_env__.get('XONSH_STORE_STDOUT')  # pylint: disable=no-member
     tee = Tee() if store_stdout else io.StringIO()
     try:
         ts0 = time.time()
         run_compiled_code(code, self.ctx, None, 'single')
         ts1 = time.time()
         if hist.last_cmd_rtn is None:
             hist.last_cmd_rtn = 0  # returncode for success
     except XonshError as e:
         print(e.args[0], file=sys.stderr)
         if hist.last_cmd_rtn is None:
             hist.last_cmd_rtn = 1  # return code for failure
     except Exception:  # pylint: disable=broad-except
         print_exception()
         if hist.last_cmd_rtn is None:
             hist.last_cmd_rtn = 1  # return code for failure
     finally:
         ts1 = ts1 or time.time()
         self._append_history(inp=src, ts=[ts0, ts1], tee_out=tee.getvalue())
         tee.close()
     if builtins.__xonsh_exit__:  # pylint: disable=no-member
         return True
开发者ID:TobalJackson,项目名称:xonsh,代码行数:30,代码来源:base_shell.py


示例8: wrapped_simple_command

    def wrapped_simple_command(args, stdin, stdout, stderr):
        try:
            i = stdin.read()
            if bgable:
                with redirect_stdout(stdout), redirect_stderr(stderr):
                    r = f(args, i)
            else:
                r = f(args, i)

            cmd_result = 0
            if isinstance(r, str):
                stdout.write(r)
            elif isinstance(r, abc.Sequence):
                if r[0] is not None:
                    stdout.write(r[0])
                if r[1] is not None:
                    stderr.write(r[1])
                if len(r) > 2 and r[2] is not None:
                    cmd_result = r[2]
            elif r is not None:
                stdout.write(str(r))
            return cmd_result
        except Exception:
            print_exception()
            return 1  # returncode for failure
开发者ID:AndreaCrotti,项目名称:xonsh,代码行数:25,代码来源:proc.py


示例9: default

 def default(self, line):
     """Implements code execution."""
     line = line if line.endswith('\n') else line + '\n'
     src, code = self.push(line)
     if code is None:
         return
     hist = builtins.__xonsh_history__
     ts1 = None
     tee = Tee() if builtins.__xonsh_env__.get('XONSH_STORE_STDOUT') \
                 else io.StringIO()
     try:
         ts0 = time.time()
         self.execer.exec(code, mode='single', glbs=self.ctx)  # no locals
         ts1 = time.time()
         if hist.last_cmd_rtn is None:
             hist.last_cmd_rtn = 0  # returncode for success
     except XonshError as e:
         print(e.args[0], file=sys.stderr)
         if hist.last_cmd_rtn is None:
             hist.last_cmd_rtn = 1  # return code for failure
     except Exception:
         print_exception()
         if hist.last_cmd_rtn is None:
             hist.last_cmd_rtn = 1  # return code for failure
     finally:
         ts1 = ts1 or time.time()
         self._append_history(inp=src, ts=[ts0, ts1], tee_out=tee.getvalue())
         tee.close()
     if builtins.__xonsh_exit__:
         return True
开发者ID:ArRolin,项目名称:gitsome,代码行数:30,代码来源:base_shell.py


示例10: prompt

 def prompt(self):
     """Obtains the current prompt string."""
     global RL_LIB, RL_CAN_RESIZE
     if RL_CAN_RESIZE:
         # This is needed to support some system where line-wrapping doesn't
         # work. This is a bug in upstream Python, or possibly readline.
         RL_LIB.rl_reset_screen_size()
     if self.need_more_lines:
         if self.mlprompt is None:
             try:
                 self.mlprompt = multiline_prompt(curr=self._current_prompt)
             except Exception:  # pylint: disable=broad-except
                 print_exception()
                 self.mlprompt = '<multiline prompt error> '
         return self.mlprompt
     env = builtins.__xonsh_env__  # pylint: disable=no-member
     p = env.get('PROMPT')
     try:
         p = partial_format_prompt(p)
     except Exception:  # pylint: disable=broad-except
         print_exception()
     hide = True if self._force_hide is None else self._force_hide
     p = ansi_partial_color_format(p, style=env.get('XONSH_COLOR_STYLE'),
                                   hide=hide)
     self._current_prompt = p
     self.settitle()
     return p
开发者ID:PaulReiber,项目名称:xonsh,代码行数:27,代码来源:readline_shell.py


示例11: push

 def push(self, line):
     """Pushes a line onto the buffer and compiles the code in a way that
     enables multiline input.
     """
     code = None
     self.buffer.append(line)
     if self.need_more_lines:
         return None, code
     src = "".join(self.buffer)
     _cache = should_use_cache(self.execer, "single")
     if _cache:
         codefname = code_cache_name(src)
         cachefname = get_cache_filename(codefname, code=True)
         usecache, code = code_cache_check(cachefname)
         if usecache:
             self.reset_buffer()
             return src, code
     try:
         code = self.execer.compile(src, mode="single", glbs=self.ctx, locs=None)
         if _cache:
             update_cache(code, cachefname)
         self.reset_buffer()
     except SyntaxError:
         if line == "\n":
             self.reset_buffer()
             print_exception()
             return src, None
         self.need_more_lines = True
     except Exception:  # pylint: disable=broad-except
         self.reset_buffer()
         print_exception()
         return src, None
     return src, code
开发者ID:yonas,项目名称:xonsh,代码行数:33,代码来源:base_shell.py


示例12: fire

    def fire(self, **kwargs):
        """
        Fires an event, calling registered handlers with the given arguments. A non-unique iterable
        of the results is returned.

        Each handler is called immediately. Exceptions are turned in to warnings.

        Parameters
        ----------
        **kwargs :
            Keyword arguments to pass to each handler

        Returns
        -------
        vals : iterable
            Return values of each handler. If multiple handlers return the same value, it will
            appear multiple times.
        """
        vals = []
        for handler in self._filterhandlers(self._handlers, **kwargs):
            try:
                rv = handler(**kwargs)
            except Exception:
                print_exception("Exception raised in event handler; ignored.")
            else:
                vals.append(rv)
        return vals
开发者ID:laerus,项目名称:xonsh,代码行数:27,代码来源:events.py


示例13: _failover_template_format

def _failover_template_format(template):
    if callable(template):
        try:
            # Exceptions raises from function of producing $PROMPT
            # in user's xonshrc should not crash xonsh
            return template()
        except Exception:
            xt.print_exception()
            return "$ "
    return template
开发者ID:donnemartin,项目名称:gitsome,代码行数:10,代码来源:base.py


示例14: prompt_tokens

 def prompt_tokens(self, cli):
     """Returns a list of (token, str) tuples for the current prompt."""
     p = builtins.__xonsh_env__.get('PROMPT')
     try:
         p = partial_format_prompt(p)
     except Exception:  # pylint: disable=broad-except
         print_exception()
     toks = partial_color_tokenize(p)
     self.settitle()
     return toks
开发者ID:AndreaCrotti,项目名称:xonsh,代码行数:10,代码来源:shell.py


示例15: _wizard

def _wizard(ns):
    env = builtins.__xonsh_env__
    fname = env.get('XONSHCONFIG') if ns.file is None else ns.file
    wiz = make_wizard(default_file=fname, confirm=ns.confirm)
    tempenv = {'PROMPT': '', 'XONSH_STORE_STDOUT': False}
    pv = PromptVisitor(wiz, store_in_history=False, multiline=False)
    with env.swap(tempenv):
        try:
            pv.visit()
        except (KeyboardInterrupt, Exception):
            tools.print_exception()
开发者ID:bvenkatr,项目名称:xonsh,代码行数:11,代码来源:xonfig.py


示例16: _get_field_value

 def _get_field_value(self, field):
     field_value = self.fields[field]
     if field_value in self.cache:
         return self.cache[field_value]
     try:
         value = field_value() if callable(field_value) else field_value
         self.cache[field_value] = value
     except Exception:
         print("prompt: error: on field {!r}" "".format(field), file=sys.stderr)
         xt.print_exception()
         value = "(ERROR:{})".format(field)
     return value
开发者ID:donnemartin,项目名称:gitsome,代码行数:12,代码来源:base.py


示例17: rprompt_tokens

 def rprompt_tokens(self, cli):
     """Returns a list of (token, str) tuples for the current right
     prompt.
     """
     p = builtins.__xonsh_env__.get('RIGHT_PROMPT')
     if len(p) == 0:
         return []
     try:
         p = partial_format_prompt(p)
     except Exception:  # pylint: disable=broad-except
         print_exception()
     toks = partial_color_tokenize(p)
     return toks
开发者ID:CJ-Wright,项目名称:xonsh,代码行数:13,代码来源:shell.py


示例18: bottom_toolbar_tokens

 def bottom_toolbar_tokens(self):
     """Returns a list of (token, str) tuples for the current bottom
     toolbar.
     """
     p = builtins.__xonsh__.env.get("BOTTOM_TOOLBAR")
     if not p:
         return
     try:
         p = self.prompt_formatter(p)
     except Exception:  # pylint: disable=broad-except
         print_exception()
     toks = partial_color_tokenize(p)
     return PygmentsTokens(toks)
开发者ID:ericmharris,项目名称:xonsh,代码行数:13,代码来源:shell.py


示例19: prompt_tokens

 def prompt_tokens(self):
     """Returns a list of (token, str) tuples for the current prompt."""
     p = builtins.__xonsh__.env.get("PROMPT")
     try:
         p = self.prompt_formatter(p)
     except Exception:  # pylint: disable=broad-except
         print_exception()
     toks = partial_color_tokenize(p)
     if self._first_prompt:
         carriage_return()
         self._first_prompt = False
     self.settitle()
     return PygmentsTokens(toks)
开发者ID:ericmharris,项目名称:xonsh,代码行数:13,代码来源:shell.py


示例20: wrapper

 def wrapper(*args, **kwargs):
     rootdir = os.path.splitdrive(os.getcwd())[0] + '\\'
     os.chdir(rootdir)
     try:
         out = func(*args, **kwargs)
     finally:
         try:
             pwd = env.get('PWD', rootdir)
             os.chdir(pwd)
         except (FileNotFoundError, NotADirectoryError):
             print_exception()
             newpath = _chdir_up(pwd)
             builtins.__xonsh_env__['PWD'] = newpath
             raise KeyboardInterrupt
     return out
开发者ID:laerus,项目名称:xonsh,代码行数:15,代码来源:free_cwd.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tools.subexpr_from_unbalanced函数代码示例发布时间:2022-05-26
下一篇:
Python tools.print_color函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap