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


Python tools.subproc_toks函数代码示例

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


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

示例1: try_subproc_toks

 def try_subproc_toks(self, node, strip_expr=False):
     """Tries to parse the line of the node as a subprocess."""
     line, nlogical, idx = get_logical_line(self.lines, node.lineno - 1)
     if self.mode == "eval":
         mincol = len(line) - len(line.lstrip())
         maxcol = None
     else:
         mincol = max(min_col(node) - 1, 0)
         maxcol = max_col(node)
         if mincol == maxcol:
             maxcol = find_next_break(line, mincol=mincol, lexer=self.parser.lexer)
         elif nlogical > 1:
             maxcol = None
         elif maxcol < len(line) and line[maxcol] == ";":
             pass
         else:
             maxcol += 1
     spline = subproc_toks(
         line,
         mincol=mincol,
         maxcol=maxcol,
         returnline=False,
         lexer=self.parser.lexer,
     )
     if spline is None or spline != "![{}]".format(line[mincol:maxcol].strip()):
         # failed to get something consistent, try greedy wrap
         spline = subproc_toks(
             line,
             mincol=mincol,
             maxcol=maxcol,
             returnline=False,
             lexer=self.parser.lexer,
             greedy=True,
         )
     if spline is None:
         return node
     try:
         newnode = self.parser.parse(
             spline,
             mode=self.mode,
             filename=self.filename,
             debug_level=(self.debug_level > 2),
         )
         newnode = newnode.body
         if not isinstance(newnode, AST):
             # take the first (and only) Expr
             newnode = newnode[0]
         increment_lineno(newnode, n=node.lineno - 1)
         newnode.col_offset = node.col_offset
         if self.debug_level > 1:
             msg = "{0}:{1}:{2}{3} - {4}\n" "{0}:{1}:{2}{3} + {5}"
             mstr = "" if maxcol is None else ":" + str(maxcol)
             msg = msg.format(self.filename, node.lineno, mincol, mstr, line, spline)
             print(msg, file=sys.stderr)
     except SyntaxError:
         newnode = node
     if strip_expr and isinstance(newnode, Expr):
         newnode = newnode.value
     return newnode
开发者ID:donnemartin,项目名称:gitsome,代码行数:59,代码来源:ast.py

示例2: try_subproc_toks

 def try_subproc_toks(self, node, strip_expr=False):
     """Tries to parse the line of the node as a subprocess."""
     line, nlogical, idx = get_logical_line(self.lines, node.lineno - 1)
     if self.mode == 'eval':
         mincol = len(line) - len(line.lstrip())
         maxcol = None
     else:
         mincol = max(min_col(node) - 1, 0)
         maxcol = max_col(node)
         if mincol == maxcol:
             maxcol = find_next_break(line, mincol=mincol,
                                      lexer=self.parser.lexer)
         elif nlogical > 1:
             maxcol = None
         elif maxcol < len(line) and line[maxcol] == ';':
             pass
         else:
             maxcol += 1
     spline = subproc_toks(line, mincol=mincol, maxcol=maxcol,
                           returnline=False, lexer=self.parser.lexer)
     if spline is None or len(spline) < len(line[mincol:maxcol]) + 2:
         # failed to get something consistent, try greedy wrap
         # The +2 comes from "![]" being length 3, minus 1 since maxcol
         # is one beyond the total length for slicing
         spline = subproc_toks(line, mincol=mincol, maxcol=maxcol,
                               returnline=False, lexer=self.parser.lexer,
                               greedy=True)
     if spline is None:
         return node
     try:
         newnode = self.parser.parse(spline, mode=self.mode,
                                     filename=self.filename,
                                     debug_level=(self.debug_level > 2))
         newnode = newnode.body
         if not isinstance(newnode, AST):
             # take the first (and only) Expr
             newnode = newnode[0]
         increment_lineno(newnode, n=node.lineno - 1)
         newnode.col_offset = node.col_offset
         if self.debug_level > 1:
             msg = ('{0}:{1}:{2}{3} - {4}\n'
                    '{0}:{1}:{2}{3} + {5}')
             mstr = '' if maxcol is None else ':' + str(maxcol)
             msg = msg.format(self.filename, node.lineno,
                              mincol, mstr, line, spline)
             print(msg, file=sys.stderr)
     except SyntaxError:
         newnode = node
     if strip_expr and isinstance(newnode, Expr):
         newnode = newnode.value
     return newnode
开发者ID:VHarisop,项目名称:xonsh,代码行数:51,代码来源:ast.py

示例3: try_subproc_toks

 def try_subproc_toks(self, node, strip_expr=False):
     """Tries to parse the line of the node as a subprocess."""
     line = self.lines[node.lineno - 1]
     if self.mode == 'eval':
         mincol = len(line) - len(line.lstrip())
         maxcol = None
     else:
         mincol = min_col(node)
         maxcol = max_col(node)
         if mincol == maxcol:
             maxcol = find_next_break(line, mincol=mincol,
                                      lexer=self.parser.lexer)
         else:
             maxcol += 1
     spline = subproc_toks(line,
                           mincol=mincol,
                           maxcol=maxcol,
                           returnline=False,
                           lexer=self.parser.lexer)
     if spline is None:
         return node
     try:
         newnode = self.parser.parse(spline, mode=self.mode)
         newnode = newnode.body
         if not isinstance(newnode, AST):
             # take the first (and only) Expr
             newnode = newnode[0]
         increment_lineno(newnode, n=node.lineno - 1)
         newnode.col_offset = node.col_offset
     except SyntaxError:
         newnode = node
     if strip_expr and isinstance(newnode, Expr):
         newnode = newnode.value
     return newnode
开发者ID:AndreaCrotti,项目名称:xonsh,代码行数:34,代码来源:ast.py

示例4: test_subproc_toks_hello_mom_second

def test_subproc_toks_hello_mom_second():
    fst = "echo 'hello'"
    sec = "echo 'mom'"
    s = "{0}; {1}".format(fst, sec)
    exp = "{0}; ![{1}]".format(fst, sec)
    obs = subproc_toks(s, lexer=LEXER, mincol=len(fst), returnline=True)
    assert exp == obs
开发者ID:mitnk,项目名称:xonsh,代码行数:7,代码来源:test_tools.py

示例5: test_subproc_toks_hello_mom_first

def test_subproc_toks_hello_mom_first():
    fst = "echo 'hello'"
    sec = "echo 'mom'"
    s = "{0}; {1}".format(fst, sec)
    exp = "![{0}]; {1}".format(fst, sec)
    obs = subproc_toks(s, lexer=LEXER, maxcol=len(fst) + 1, returnline=True)
    assert exp == obs
开发者ID:mitnk,项目名称:xonsh,代码行数:7,代码来源:test_tools.py

示例6: test_subproc_toks_ls_l_semi_ls_second

def test_subproc_toks_ls_l_semi_ls_second():
    lsdl = "ls -l"
    ls = "ls"
    s = "{0}; {1}".format(lsdl, ls)
    exp = "{0}; ![{1}]".format(lsdl, ls)
    obs = subproc_toks(s, lexer=LEXER, mincol=7, returnline=True)
    assert exp == obs
开发者ID:mitnk,项目名称:xonsh,代码行数:7,代码来源:test_tools.py

示例7: test_subproc_toks_ls_l_semi_ls_first

def test_subproc_toks_ls_l_semi_ls_first():
    lsdl = "ls -l"
    ls = "ls"
    s = "{0}; {1}".format(lsdl, ls)
    exp = "![{0}]; {1}".format(lsdl, ls)
    obs = subproc_toks(s, lexer=LEXER, maxcol=6, returnline=True)
    assert exp == obs
开发者ID:mitnk,项目名称:xonsh,代码行数:7,代码来源:test_tools.py

示例8: test_subproc_toks_indent_ls_str

def test_subproc_toks_indent_ls_str():
    ind = "    "
    s = 'ls "wakka"'
    com = "  # lets list"
    exp = "{0}![{1}]{2}".format(ind, s, com)
    obs = subproc_toks(ind + s + com, lexer=LEXER, returnline=True)
    assert exp == obs
开发者ID:mitnk,项目名称:xonsh,代码行数:7,代码来源:test_tools.py

示例9: test_subproc_toks_indent_ls_nl

def test_subproc_toks_indent_ls_nl():
    s = "ls -l"
    exp = INDENT + "![{0}]\n".format(s)
    obs = subproc_toks(
        INDENT + s + "\n", mincol=len(INDENT), lexer=LEXER, returnline=True
    )
    assert exp == obs
开发者ID:mitnk,项目名称:xonsh,代码行数:7,代码来源:test_tools.py

示例10: test_subproc_toks_indent_ls_comment

def test_subproc_toks_indent_ls_comment():
    ind = '    '
    s = 'ls -l'
    com = '  # lets list'
    exp = '{0}![{1}]{2}'.format(ind, s, com)
    obs = subproc_toks(ind + s + com, lexer=LEXER, returnline=True)
    assert (exp == obs)
开发者ID:BlaXpirit,项目名称:xonsh,代码行数:7,代码来源:test_tools.py

示例11: test_subproc_hello_mom_second

def test_subproc_hello_mom_second():
    fst = "echo 'hello'"
    sec = "echo 'mom'"
    s = '{0}; {1}'.format(fst, sec)
    exp = '{0}; $[{1}]'.format(fst, sec)
    obs = subproc_toks(s, lexer=LEXER, mincol=len(fst), returnline=True)
    assert_equal(exp, obs)
开发者ID:gforsyth,项目名称:xonsh,代码行数:7,代码来源:test_tools.py

示例12: test_subproc_hello_mom_first

def test_subproc_hello_mom_first():
    fst = "echo 'hello'"
    sec = "echo 'mom'"
    s = '{0}; {1}'.format(fst, sec)
    exp = '$[{0}]; {1}'.format(fst, sec)
    obs = subproc_toks(s, lexer=LEXER, maxcol=len(fst)+1, returnline=True)
    assert_equal(exp, obs)
开发者ID:gforsyth,项目名称:xonsh,代码行数:7,代码来源:test_tools.py

示例13: try_subproc_toks

 def try_subproc_toks(self, node):
     """Tries to parse the line of the node as a subprocess."""
     line = self.lines[node.lineno - 1]
     if self.mode == 'eval':
         mincol = len(line) - len(line.lstrip())
         maxcol = None
     else: 
         mincol = min_col(node)
         maxcol = max_col(node) + 1
     spline = subproc_toks(line,
                           mincol=mincol,
                           maxcol=maxcol,
                           returnline=False,
                           lexer=self.parser.lexer)
     try:
         newnode = self.parser.parse(spline, mode=self.mode)
         newnode = newnode.body
         if not isinstance(newnode, AST):
             # take the first (and only) Expr
             newnode = newnode[0]
         newnode.lineno = node.lineno
         newnode.col_offset = node.col_offset
     except SyntaxError:
         newnode = node
     return newnode
开发者ID:gitter-badger,项目名称:xonsh,代码行数:25,代码来源:ast.py

示例14: test_subproc_toks_ls_l_semi_ls_first

def test_subproc_toks_ls_l_semi_ls_first():
    lsdl = 'ls -l'
    ls = 'ls'
    s = '{0}; {1}'.format(lsdl, ls)
    exp = '$[{0}]; {1}'.format(lsdl, ls)
    obs = subproc_toks(s, lexer=LEXER, maxcol=6, returnline=True)
    assert_equal(exp, obs)
开发者ID:gforsyth,项目名称:xonsh,代码行数:7,代码来源:test_tools.py

示例15: test_subproc_toks_ls_l_semi_ls_second

def test_subproc_toks_ls_l_semi_ls_second():
    lsdl = 'ls -l'
    ls = 'ls'
    s = '{0}; {1}'.format(lsdl, ls)
    exp = '{0}; $[{1}]'.format(lsdl, ls)
    obs = subproc_toks(s, lexer=LEXER, mincol=7, returnline=True)
    assert_equal(exp, obs)
开发者ID:gforsyth,项目名称:xonsh,代码行数:7,代码来源:test_tools.py


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