Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def p_atom_expr_await(self, p):
"""atom_expr : await_tok atom trailer_list_opt"""
p0 = self.apply_trailers(p[2], p[3])
p1 = p[1]
p0 = ast.Await(value=p0, ctx=ast.Load(), lineno=p1.lineno, col_offset=p1.lexpos)
p[0] = p0
if isinstance(trailer, tuple):
trailer, arglist = trailer
margs = [leader, trailer, gblcall, loccall]
p0 = xonsh_call("__xonsh__.call_macro", margs, lineno=l, col=c)
elif isinstance(trailer, str):
if trailer == "?":
p0 = xonsh_help(leader, lineno=leader.lineno, col=leader.col_offset)
elif trailer == "??":
p0 = xonsh_superhelp(
leader, lineno=leader.lineno, col=leader.col_offset
)
else:
p0 = ast.Attribute(
value=leader,
attr=trailer,
ctx=ast.Load(),
lineno=leader.lineno,
col_offset=leader.col_offset,
)
else:
assert False
leader = p0
return p0
def p_atom_lparen(self, p):
"""atom : lparen_tok yield_expr_or_testlist_comp_opt RPAREN"""
p1, p2 = p[1], p[2]
p1, p1_tok = p1.value, p1
if p2 is None:
# empty container atom
p0 = ast.Tuple(
elts=[], ctx=ast.Load(), lineno=self.lineno, col_offset=self.col
)
p0._real_tuple = True
elif isinstance(p2, ast.AST):
p0 = p2
p0._lopen_lineno, p0._lopen_col = p1_tok.lineno, p1_tok.lexpos
p0._real_tuple = True
elif len(p2) == 1 and isinstance(p2[0], ast.AST):
p0 = p2[0]
p0._lopen_lineno, p0._lopen_col = p1_tok.lineno, p1_tok.lexpos
else:
self.p_error(p)
p[0] = p0
if p2:
begins.extend([(x[0], x[1] + 1) for x in p2])
ends = p2 + ends
elts = []
for beg, end in zip(begins, ends):
s = self.source_slice(beg, end).strip()
if not s:
if len(begins) == 1:
break
else:
msg = "empty macro arguments not allowed"
self._parse_error(msg, self.currloc(*beg))
node = ast.Str(s=s, lineno=beg[0], col_offset=beg[1])
elts.append(node)
p0 = ast.Tuple(
elts=elts, ctx=ast.Load(), lineno=p1.lineno, col_offset=p1.lexpos
)
p[0] = [p0]
def p_atom_name(self, p):
"""atom : name_tok"""
p1 = p[1]
p[0] = ast.Name(
id=p1.value, ctx=ast.Load(), lineno=p1.lineno, col_offset=p1.lexpos
)
def _envvar_getter_by_name(self, var, lineno=None, col=None):
xenv = load_attribute_chain("__xonsh__.env", lineno=lineno, col=col)
func = ast.Attribute(
value=xenv, attr="get", ctx=ast.Load(), lineno=lineno, col_offset=col
)
return ast.Call(
func=func,
args=[
ast.Str(s=var, lineno=lineno, col_offset=col),
ast.Str(s="", lineno=lineno, col_offset=col),
],
keywords=[],
starargs=None,
kwargs=None,
lineno=lineno,
col_offset=col,
)
def call_split_lines(x, lineno=None, col=None):
"""Creates the AST node for calling the 'splitlines' attribute of an
object, nominally a string.
"""
return ast.Call(
func=ast.Attribute(
value=x, attr="splitlines", ctx=ast.Load(), lineno=lineno, col_offset=col
),
args=[],
keywords=[],
starargs=None,
kwargs=None,
lineno=lineno,
col_offset=col,
)
def _envvar_by_name(self, var, lineno=None, col=None):
"""Looks up a xonsh variable by name."""
xenv = load_attribute_chain("__xonsh__.env", lineno=lineno, col=col)
idx = ast.Index(value=ast.Str(s=var, lineno=lineno, col_offset=col))
return ast.Subscript(
value=xenv, slice=idx, ctx=ast.Load(), lineno=lineno, col_offset=col
)
if p2 is None:
p0 = [p1]
elif p2 == ",":
p0 = [
ast.Tuple(
elts=[p1],
ctx=ast.Load(),
lineno=p1.lineno,
col_offset=p1.col_offset,
)
]
else:
p0 = [
ast.Tuple(
elts=[p1] + p2,
ctx=ast.Load(),
lineno=p1.lineno,
col_offset=p1.col_offset,
)
]
p[0] = p0