示例#1
0
def test_transform(xession):
    @xession.builtins.events.on_transform_command
    def spam2egg(cmd, **_):
        if cmd == "spam":
            return "egg"
        else:
            return cmd

    assert transform_command("spam") == "egg"
    assert transform_command("egg") == "egg"
    assert transform_command("foo") == "foo"
示例#2
0
def test_transform(xonsh_builtins):
    @xonsh_builtins.events.on_transform_command
    def spam2egg(cmd):
        if cmd == 'spam':
            return 'egg'
        else:
            return cmd

    assert transform_command('spam') == 'egg'
    assert transform_command('egg') == 'egg'
    assert transform_command('foo') == 'foo'
示例#3
0
def test_transform(xonsh_builtins):
    @xonsh_builtins.events.on_transform_command
    def spam2egg(cmd, **_):
        if cmd == "spam":
            return "egg"
        else:
            return cmd

    assert transform_command("spam") == "egg"
    assert transform_command("egg") == "egg"
    assert transform_command("foo") == "foo"
示例#4
0
def test_transform(xonsh_builtins):
    @xonsh_builtins.events.on_transform_command
    def spam2egg(cmd, **_):
        if cmd == 'spam':
            return 'egg'
        else:
            return cmd

    assert transform_command('spam') == 'egg'
    assert transform_command('egg') == 'egg'
    assert transform_command('foo') == 'foo'
示例#5
0
 def push(self, line):
     """Pushes a line onto the buffer and compiles the code in a way that
     enables multiline input.
     """
     self.buffer.append(line)
     if self.need_more_lines:
         return None, None
     src = "".join(self.buffer)
     src = transform_command(src)
     return self.compile(src)
示例#6
0
 def push(self, line):
     """Pushes a line onto the buffer and compiles the code in a way that
     enables multiline input.
     """
     self.buffer.append(line)
     if self.need_more_lines:
         return None, None
     src = "".join(self.buffer)
     src = transform_command(src)
     return self.compile(src)
示例#7
0
def can_compile(src):
    """Returns whether the code can be compiled, i.e. it is valid xonsh."""
    src = src if src.endswith("\n") else src + "\n"
    src = transform_command(src, show_diff=False)
    src = src.lstrip()
    try:
        XSH.execer.compile(src, mode="single", glbs=None, locs=XSH.ctx)
        rtn = True
    except SyntaxError:
        rtn = False
    except Exception:
        rtn = True
    return rtn
示例#8
0
def can_compile(src):
    """Returns whether the code can be compiled, i.e. it is valid xonsh."""
    src = src if src.endswith('\n') else src + '\n'
    src = transform_command(src, show_diff=False)
    src = src.lstrip()
    try:
        builtins.__xonsh_execer__.compile(src, mode='single', glbs=None,
                                          locs=builtins.__xonsh_ctx__)
        rtn = True
    except SyntaxError:
        rtn = False
    except Exception:
        rtn = True
    return rtn
示例#9
0
def can_compile(src):
    """Returns whether the code can be compiled, i.e. it is valid xonsh."""
    src = src if src.endswith('\n') else src + '\n'
    src = transform_command(src, show_diff=False)
    src = src.lstrip()
    try:
        builtins.__xonsh_execer__.compile(src, mode='single', glbs=None,
                                          locs=builtins.__xonsh_ctx__)
        rtn = True
    except SyntaxError:
        rtn = False
    except Exception:
        rtn = True
    return rtn
示例#10
0
 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)
     src = transform_command(src)
     try:
         code = self.execer.compile(src, mode="single", glbs=self.ctx, locs=None)
         self.reset_buffer()
     except Exception:  # pylint: disable=broad-except
         self.reset_buffer()
         print_exception()
         return src, None
     return src, code
示例#11
0
 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)
     src = transform_command(src)
     try:
         code = self.execer.compile(src, mode="single", glbs=self.ctx, locs=None)
         self.reset_buffer()
     except Exception:  # pylint: disable=broad-except
         self.reset_buffer()
         print_exception()
         return src, None
     return src, code