예제 #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
파일: shell.py 프로젝트: ericmharris/xonsh
 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