Python token.DOUBLESTAR Examples
The following are 30
code examples of token.DOUBLESTAR().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
token
, or try the search function
.
Example #1
Source File: transformer.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def power(self, nodelist): # power: atom trailer* ('**' factor)* node = self.com_node(nodelist[0]) for i in range(1, len(nodelist)): elt = nodelist[i] if elt[0] == token.DOUBLESTAR: return Power([node, self.com_node(nodelist[i+1])], lineno=elt[2]) node = self.com_apply_trailer(node, elt) return node
Example #2
Source File: transformer.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def power(self, nodelist): # power: atom trailer* ('**' factor)* node = self.com_node(nodelist[0]) for i in range(1, len(nodelist)): elt = nodelist[i] if elt[0] == token.DOUBLESTAR: return Power([node, self.com_node(nodelist[i+1])], lineno=elt[2]) node = self.com_apply_trailer(node, elt) return node
Example #3
Source File: transformer.py From ironpython2 with Apache License 2.0 | 5 votes |
def com_call_function(self, primaryNode, nodelist): if nodelist[0] == token.RPAR: return CallFunc(primaryNode, [], lineno=extractLineNo(nodelist)) args = [] kw = 0 star_node = dstar_node = None len_nodelist = len(nodelist) i = 1 while i < len_nodelist: node = nodelist[i] if node[0]==token.STAR: if star_node is not None: raise SyntaxError, 'already have the varargs indentifier' star_node = self.com_node(nodelist[i+1]) i = i + 3 continue elif node[0]==token.DOUBLESTAR: if dstar_node is not None: raise SyntaxError, 'already have the kwargs indentifier' dstar_node = self.com_node(nodelist[i+1]) i = i + 3 continue # positional or named parameters kw, result = self.com_argument(node, kw, star_node) if len_nodelist != 2 and isinstance(result, GenExpr) \ and len(node) == 3 and node[2][0] == symbol.comp_for: # allow f(x for x in y), but reject f(x for x in y, 1) # should use f((x for x in y), 1) instead of f(x for x in y, 1) raise SyntaxError, 'generator expression needs parenthesis' args.append(result) i = i + 2 return CallFunc(primaryNode, args, star_node, dstar_node, lineno=extractLineNo(nodelist))
Example #4
Source File: transformer.py From BinderFilter with MIT License | 5 votes |
def power(self, nodelist): # power: atom trailer* ('**' factor)* node = self.com_node(nodelist[0]) for i in range(1, len(nodelist)): elt = nodelist[i] if elt[0] == token.DOUBLESTAR: return Power([node, self.com_node(nodelist[i+1])], lineno=elt[2]) node = self.com_apply_trailer(node, elt) return node
Example #5
Source File: transformer.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def power(self, nodelist): # power: atom trailer* ('**' factor)* node = self.com_node(nodelist[0]) for i in range(1, len(nodelist)): elt = nodelist[i] if elt[0] == token.DOUBLESTAR: return Power([node, self.com_node(nodelist[i+1])], lineno=elt[2]) node = self.com_apply_trailer(node, elt) return node
Example #6
Source File: transformer.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def power(self, nodelist): # power: atom trailer* ('**' factor)* node = self.com_node(nodelist[0]) for i in range(1, len(nodelist)): elt = nodelist[i] if elt[0] == token.DOUBLESTAR: return Power([node, self.com_node(nodelist[i+1])], lineno=elt[2]) node = self.com_apply_trailer(node, elt) return node
Example #7
Source File: transformer.py From BinderFilter with MIT License | 5 votes |
def com_call_function(self, primaryNode, nodelist): if nodelist[0] == token.RPAR: return CallFunc(primaryNode, [], lineno=extractLineNo(nodelist)) args = [] kw = 0 star_node = dstar_node = None len_nodelist = len(nodelist) i = 1 while i < len_nodelist: node = nodelist[i] if node[0]==token.STAR: if star_node is not None: raise SyntaxError, 'already have the varargs indentifier' star_node = self.com_node(nodelist[i+1]) i = i + 3 continue elif node[0]==token.DOUBLESTAR: if dstar_node is not None: raise SyntaxError, 'already have the kwargs indentifier' dstar_node = self.com_node(nodelist[i+1]) i = i + 3 continue # positional or named parameters kw, result = self.com_argument(node, kw, star_node) if len_nodelist != 2 and isinstance(result, GenExpr) \ and len(node) == 3 and node[2][0] == symbol.comp_for: # allow f(x for x in y), but reject f(x for x in y, 1) # should use f((x for x in y), 1) instead of f(x for x in y, 1) raise SyntaxError, 'generator expression needs parenthesis' args.append(result) i = i + 2 return CallFunc(primaryNode, args, star_node, dstar_node, lineno=extractLineNo(nodelist))
Example #8
Source File: transformer.py From oss-ftp with MIT License | 5 votes |
def power(self, nodelist): # power: atom trailer* ('**' factor)* node = self.com_node(nodelist[0]) for i in range(1, len(nodelist)): elt = nodelist[i] if elt[0] == token.DOUBLESTAR: return Power([node, self.com_node(nodelist[i+1])], lineno=elt[2]) node = self.com_apply_trailer(node, elt) return node
Example #9
Source File: transformer.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def com_call_function(self, primaryNode, nodelist): if nodelist[0] == token.RPAR: return CallFunc(primaryNode, [], lineno=extractLineNo(nodelist)) args = [] kw = 0 star_node = dstar_node = None len_nodelist = len(nodelist) i = 1 while i < len_nodelist: node = nodelist[i] if node[0]==token.STAR: if star_node is not None: raise SyntaxError, 'already have the varargs indentifier' star_node = self.com_node(nodelist[i+1]) i = i + 3 continue elif node[0]==token.DOUBLESTAR: if dstar_node is not None: raise SyntaxError, 'already have the kwargs indentifier' dstar_node = self.com_node(nodelist[i+1]) i = i + 3 continue # positional or named parameters kw, result = self.com_argument(node, kw, star_node) if len_nodelist != 2 and isinstance(result, GenExpr) \ and len(node) == 3 and node[2][0] == symbol.comp_for: # allow f(x for x in y), but reject f(x for x in y, 1) # should use f((x for x in y), 1) instead of f(x for x in y, 1) raise SyntaxError, 'generator expression needs parenthesis' args.append(result) i = i + 2 return CallFunc(primaryNode, args, star_node, dstar_node, lineno=extractLineNo(nodelist))
Example #10
Source File: transformer.py From medicare-demo with Apache License 2.0 | 5 votes |
def power(self, nodelist): # power: atom trailer* ('**' factor)* node = self.com_node(nodelist[0]) for i in range(1, len(nodelist)): elt = nodelist[i] if elt[0] == token.DOUBLESTAR: return Power([node, self.com_node(nodelist[i+1])], lineno=elt[2]) node = self.com_apply_trailer(node, elt) return node
Example #11
Source File: transformer.py From oss-ftp with MIT License | 5 votes |
def com_call_function(self, primaryNode, nodelist): if nodelist[0] == token.RPAR: return CallFunc(primaryNode, [], lineno=extractLineNo(nodelist)) args = [] kw = 0 star_node = dstar_node = None len_nodelist = len(nodelist) i = 1 while i < len_nodelist: node = nodelist[i] if node[0]==token.STAR: if star_node is not None: raise SyntaxError, 'already have the varargs indentifier' star_node = self.com_node(nodelist[i+1]) i = i + 3 continue elif node[0]==token.DOUBLESTAR: if dstar_node is not None: raise SyntaxError, 'already have the kwargs indentifier' dstar_node = self.com_node(nodelist[i+1]) i = i + 3 continue # positional or named parameters kw, result = self.com_argument(node, kw, star_node) if len_nodelist != 2 and isinstance(result, GenExpr) \ and len(node) == 3 and node[2][0] == symbol.comp_for: # allow f(x for x in y), but reject f(x for x in y, 1) # should use f((x for x in y), 1) instead of f(x for x in y, 1) raise SyntaxError, 'generator expression needs parenthesis' args.append(result) i = i + 2 return CallFunc(primaryNode, args, star_node, dstar_node, lineno=extractLineNo(nodelist))
Example #12
Source File: transformer.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def power(self, nodelist): # power: atom trailer* ('**' factor)* node = self.com_node(nodelist[0]) for i in range(1, len(nodelist)): elt = nodelist[i] if elt[0] == token.DOUBLESTAR: return Power([node, self.com_node(nodelist[i+1])], lineno=elt[2]) node = self.com_apply_trailer(node, elt) return node
Example #13
Source File: transformer.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def com_call_function(self, primaryNode, nodelist): if nodelist[0] == token.RPAR: return CallFunc(primaryNode, [], lineno=extractLineNo(nodelist)) args = [] kw = 0 star_node = dstar_node = None len_nodelist = len(nodelist) i = 1 while i < len_nodelist: node = nodelist[i] if node[0]==token.STAR: if star_node is not None: raise SyntaxError, 'already have the varargs indentifier' star_node = self.com_node(nodelist[i+1]) i = i + 3 continue elif node[0]==token.DOUBLESTAR: if dstar_node is not None: raise SyntaxError, 'already have the kwargs indentifier' dstar_node = self.com_node(nodelist[i+1]) i = i + 3 continue # positional or named parameters kw, result = self.com_argument(node, kw, star_node) if len_nodelist != 2 and isinstance(result, GenExpr) \ and len(node) == 3 and node[2][0] == symbol.comp_for: # allow f(x for x in y), but reject f(x for x in y, 1) # should use f((x for x in y), 1) instead of f(x for x in y, 1) raise SyntaxError, 'generator expression needs parenthesis' args.append(result) i = i + 2 return CallFunc(primaryNode, args, star_node, dstar_node, lineno=extractLineNo(nodelist))
Example #14
Source File: transformer.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def power(self, nodelist): # power: atom trailer* ('**' factor)* node = self.com_node(nodelist[0]) for i in range(1, len(nodelist)): elt = nodelist[i] if elt[0] == token.DOUBLESTAR: return Power([node, self.com_node(nodelist[i+1])], lineno=elt[2]) node = self.com_apply_trailer(node, elt) return node
Example #15
Source File: transformer.py From ironpython2 with Apache License 2.0 | 5 votes |
def power(self, nodelist): # power: atom trailer* ('**' factor)* node = self.com_node(nodelist[0]) for i in range(1, len(nodelist)): elt = nodelist[i] if elt[0] == token.DOUBLESTAR: return Power([node, self.com_node(nodelist[i+1])], lineno=elt[2]) node = self.com_apply_trailer(node, elt) return node
Example #16
Source File: transformer.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 4 votes |
def com_assign(self, node, assigning): # return a node suitable for use as an "lvalue" # loop to avoid trivial recursion while 1: t = node[0] if t in (symbol.exprlist, symbol.testlist, symbol.testlist_safe, symbol.testlist_gexp): if len(node) > 2: return self.com_assign_tuple(node, assigning) node = node[1] elif t in _assign_types: if len(node) > 2: raise SyntaxError, "can't assign to operator" node = node[1] elif t == symbol.power: if node[1][0] != symbol.atom: raise SyntaxError, "can't assign to operator" if len(node) > 2: primary = self.com_node(node[1]) for i in range(2, len(node)-1): ch = node[i] if ch[0] == token.DOUBLESTAR: raise SyntaxError, "can't assign to operator" primary = self.com_apply_trailer(primary, ch) return self.com_assign_trailer(primary, node[-1], assigning) node = node[1] elif t == symbol.atom: t = node[1][0] if t == token.LPAR: node = node[2] if node[0] == token.RPAR: raise SyntaxError, "can't assign to ()" elif t == token.LSQB: node = node[2] if node[0] == token.RSQB: raise SyntaxError, "can't assign to []" return self.com_assign_list(node, assigning) elif t == token.NAME: return self.com_assign_name(node[1], assigning) else: raise SyntaxError, "can't assign to literal" else: raise SyntaxError, "bad assignment (%s)" % t
Example #17
Source File: transformer.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 4 votes |
def com_call_function(self, primaryNode, nodelist): if nodelist[0] == token.RPAR: return CallFunc(primaryNode, [], lineno=extractLineNo(nodelist)) args = [] kw = 0 len_nodelist = len(nodelist) for i in range(1, len_nodelist, 2): node = nodelist[i] if node[0] == token.STAR or node[0] == token.DOUBLESTAR: break kw, result = self.com_argument(node, kw) if len_nodelist != 2 and isinstance(result, GenExpr) \ and len(node) == 3 and node[2][0] == symbol.gen_for: # allow f(x for x in y), but reject f(x for x in y, 1) # should use f((x for x in y), 1) instead of f(x for x in y, 1) raise SyntaxError, 'generator expression needs parenthesis' args.append(result) else: # No broken by star arg, so skip the last one we processed. i = i + 1 if i < len_nodelist and nodelist[i][0] == token.COMMA: # need to accept an application that looks like "f(a, b,)" i = i + 1 star_node = dstar_node = None while i < len_nodelist: tok = nodelist[i] ch = nodelist[i+1] i = i + 3 if tok[0]==token.STAR: if star_node is not None: raise SyntaxError, 'already have the varargs indentifier' star_node = self.com_node(ch) elif tok[0]==token.DOUBLESTAR: if dstar_node is not None: raise SyntaxError, 'already have the kwargs indentifier' dstar_node = self.com_node(ch) else: raise SyntaxError, 'unknown node type: %s' % tok return CallFunc(primaryNode, args, star_node, dstar_node, lineno=extractLineNo(nodelist))
Example #18
Source File: transformer.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 4 votes |
def com_call_function(self, primaryNode, nodelist): if nodelist[0] == token.RPAR: return CallFunc(primaryNode, [], lineno=extractLineNo(nodelist)) args = [] kw = 0 len_nodelist = len(nodelist) for i in range(1, len_nodelist, 2): node = nodelist[i] if node[0] == token.STAR or node[0] == token.DOUBLESTAR: break kw, result = self.com_argument(node, kw) if len_nodelist != 2 and isinstance(result, GenExpr) \ and len(node) == 3 and node[2][0] == symbol.gen_for: # allow f(x for x in y), but reject f(x for x in y, 1) # should use f((x for x in y), 1) instead of f(x for x in y, 1) raise SyntaxError, 'generator expression needs parenthesis' args.append(result) else: # No broken by star arg, so skip the last one we processed. i = i + 1 if i < len_nodelist and nodelist[i][0] == token.COMMA: # need to accept an application that looks like "f(a, b,)" i = i + 1 star_node = dstar_node = None while i < len_nodelist: tok = nodelist[i] ch = nodelist[i+1] i = i + 3 if tok[0]==token.STAR: if star_node is not None: raise SyntaxError, 'already have the varargs indentifier' star_node = self.com_node(ch) elif tok[0]==token.DOUBLESTAR: if dstar_node is not None: raise SyntaxError, 'already have the kwargs indentifier' dstar_node = self.com_node(ch) else: raise SyntaxError, 'unknown node type: %s' % tok return CallFunc(primaryNode, args, star_node, dstar_node, lineno=extractLineNo(nodelist))
Example #19
Source File: transformer.py From medicare-demo with Apache License 2.0 | 4 votes |
def com_arglist(self, nodelist): # varargslist: # (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME] | '**' NAME) # | fpdef ['=' test] (',' fpdef ['=' test])* [','] # fpdef: NAME | '(' fplist ')' # fplist: fpdef (',' fpdef)* [','] names = [] defaults = [] flags = 0 i = 0 while i < len(nodelist): node = nodelist[i] if node[0] == token.STAR or node[0] == token.DOUBLESTAR: if node[0] == token.STAR: node = nodelist[i+1] if node[0] == token.NAME: names.append(node[1]) flags = flags | CO_VARARGS i = i + 3 if i < len(nodelist): # should be DOUBLESTAR t = nodelist[i][0] if t == token.DOUBLESTAR: node = nodelist[i+1] else: raise ValueError, "unexpected token: %s" % t names.append(node[1]) flags = flags | CO_VARKEYWORDS break # fpdef: NAME | '(' fplist ')' names.append(self.com_fpdef(node)) i = i + 1 if i < len(nodelist) and nodelist[i][0] == token.EQUAL: defaults.append(self.com_node(nodelist[i + 1])) i = i + 2 elif len(defaults): # we have already seen an argument with default, but here # came one without raise SyntaxError, "non-default argument follows default argument" # skip the comma i = i + 1 return names, defaults, flags
Example #20
Source File: transformer.py From PokemonGo-DesktopMap with MIT License | 4 votes |
def com_arglist(self, nodelist): # varargslist: # (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME] | '**' NAME) # | fpdef ['=' test] (',' fpdef ['=' test])* [','] # fpdef: NAME | '(' fplist ')' # fplist: fpdef (',' fpdef)* [','] names = [] defaults = [] flags = 0 i = 0 while i < len(nodelist): node = nodelist[i] if node[0] == token.STAR or node[0] == token.DOUBLESTAR: if node[0] == token.STAR: node = nodelist[i+1] if node[0] == token.NAME: names.append(node[1]) flags = flags | CO_VARARGS i = i + 3 if i < len(nodelist): # should be DOUBLESTAR t = nodelist[i][0] if t == token.DOUBLESTAR: node = nodelist[i+1] else: raise ValueError, "unexpected token: %s" % t names.append(node[1]) flags = flags | CO_VARKEYWORDS break # fpdef: NAME | '(' fplist ')' names.append(self.com_fpdef(node)) i = i + 1 if i < len(nodelist) and nodelist[i][0] == token.EQUAL: defaults.append(self.com_node(nodelist[i + 1])) i = i + 2 elif len(defaults): # we have already seen an argument with default, but here # came one without raise SyntaxError, "non-default argument follows default argument" # skip the comma i = i + 1 return names, defaults, flags
Example #21
Source File: transformer.py From PokemonGo-DesktopMap with MIT License | 4 votes |
def com_assign(self, node, assigning): # return a node suitable for use as an "lvalue" # loop to avoid trivial recursion while 1: t = node[0] if t in (symbol.exprlist, symbol.testlist, symbol.testlist_safe, symbol.testlist_comp): if len(node) > 2: return self.com_assign_tuple(node, assigning) node = node[1] elif t in _assign_types: if len(node) > 2: raise SyntaxError, "can't assign to operator" node = node[1] elif t == symbol.power: if node[1][0] != symbol.atom: raise SyntaxError, "can't assign to operator" if len(node) > 2: primary = self.com_node(node[1]) for i in range(2, len(node)-1): ch = node[i] if ch[0] == token.DOUBLESTAR: raise SyntaxError, "can't assign to operator" primary = self.com_apply_trailer(primary, ch) return self.com_assign_trailer(primary, node[-1], assigning) node = node[1] elif t == symbol.atom: t = node[1][0] if t == token.LPAR: node = node[2] if node[0] == token.RPAR: raise SyntaxError, "can't assign to ()" elif t == token.LSQB: node = node[2] if node[0] == token.RSQB: raise SyntaxError, "can't assign to []" return self.com_assign_list(node, assigning) elif t == token.NAME: return self.com_assign_name(node[1], assigning) else: raise SyntaxError, "can't assign to literal" else: raise SyntaxError, "bad assignment (%s)" % t
Example #22
Source File: transformer.py From CTFCrackTools with GNU General Public License v3.0 | 4 votes |
def com_arglist(self, nodelist): # varargslist: # (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME] | '**' NAME) # | fpdef ['=' test] (',' fpdef ['=' test])* [','] # fpdef: NAME | '(' fplist ')' # fplist: fpdef (',' fpdef)* [','] names = [] defaults = [] flags = 0 i = 0 while i < len(nodelist): node = nodelist[i] if node[0] == token.STAR or node[0] == token.DOUBLESTAR: if node[0] == token.STAR: node = nodelist[i+1] if node[0] == token.NAME: names.append(node[1]) flags = flags | CO_VARARGS i = i + 3 if i < len(nodelist): # should be DOUBLESTAR t = nodelist[i][0] if t == token.DOUBLESTAR: node = nodelist[i+1] else: raise ValueError, "unexpected token: %s" % t names.append(node[1]) flags = flags | CO_VARKEYWORDS break # fpdef: NAME | '(' fplist ')' names.append(self.com_fpdef(node)) i = i + 1 if i < len(nodelist) and nodelist[i][0] == token.EQUAL: defaults.append(self.com_node(nodelist[i + 1])) i = i + 2 elif len(defaults): # we have already seen an argument with default, but here # came one without raise SyntaxError, "non-default argument follows default argument" # skip the comma i = i + 1 return names, defaults, flags
Example #23
Source File: transformer.py From CTFCrackTools with GNU General Public License v3.0 | 4 votes |
def com_assign(self, node, assigning): # return a node suitable for use as an "lvalue" # loop to avoid trivial recursion while 1: t = node[0] if t in (symbol.exprlist, symbol.testlist, symbol.testlist_safe, symbol.testlist_gexp): if len(node) > 2: return self.com_assign_tuple(node, assigning) node = node[1] elif t in _assign_types: if len(node) > 2: raise SyntaxError, "can't assign to operator" node = node[1] elif t == symbol.power: if node[1][0] != symbol.atom: raise SyntaxError, "can't assign to operator" if len(node) > 2: primary = self.com_node(node[1]) for i in range(2, len(node)-1): ch = node[i] if ch[0] == token.DOUBLESTAR: raise SyntaxError, "can't assign to operator" primary = self.com_apply_trailer(primary, ch) return self.com_assign_trailer(primary, node[-1], assigning) node = node[1] elif t == symbol.atom: t = node[1][0] if t == token.LPAR: node = node[2] if node[0] == token.RPAR: raise SyntaxError, "can't assign to ()" elif t == token.LSQB: node = node[2] if node[0] == token.RSQB: raise SyntaxError, "can't assign to []" return self.com_assign_list(node, assigning) elif t == token.NAME: return self.com_assign_name(node[1], assigning) else: raise SyntaxError, "can't assign to literal" else: raise SyntaxError, "bad assignment (%s)" % t
Example #24
Source File: transformer.py From CTFCrackTools with GNU General Public License v3.0 | 4 votes |
def com_call_function(self, primaryNode, nodelist): if nodelist[0] == token.RPAR: return CallFunc(primaryNode, [], lineno=extractLineNo(nodelist)) args = [] kw = 0 len_nodelist = len(nodelist) for i in range(1, len_nodelist, 2): node = nodelist[i] if node[0] == token.STAR or node[0] == token.DOUBLESTAR: break kw, result = self.com_argument(node, kw) if len_nodelist != 2 and isinstance(result, GenExpr) \ and len(node) == 3 and node[2][0] == symbol.gen_for: # allow f(x for x in y), but reject f(x for x in y, 1) # should use f((x for x in y), 1) instead of f(x for x in y, 1) raise SyntaxError, 'generator expression needs parenthesis' args.append(result) else: # No broken by star arg, so skip the last one we processed. i = i + 1 if i < len_nodelist and nodelist[i][0] == token.COMMA: # need to accept an application that looks like "f(a, b,)" i = i + 1 star_node = dstar_node = None while i < len_nodelist: tok = nodelist[i] ch = nodelist[i+1] i = i + 3 if tok[0]==token.STAR: if star_node is not None: raise SyntaxError, 'already have the varargs indentifier' star_node = self.com_node(ch) elif tok[0]==token.DOUBLESTAR: if dstar_node is not None: raise SyntaxError, 'already have the kwargs indentifier' dstar_node = self.com_node(ch) else: raise SyntaxError, 'unknown node type: %s' % tok return CallFunc(primaryNode, args, star_node, dstar_node, lineno=extractLineNo(nodelist))
Example #25
Source File: transformer.py From CTFCrackTools with GNU General Public License v3.0 | 4 votes |
def com_assign(self, node, assigning): # return a node suitable for use as an "lvalue" # loop to avoid trivial recursion while 1: t = node[0] if t in (symbol.exprlist, symbol.testlist, symbol.testlist_safe, symbol.testlist_gexp): if len(node) > 2: return self.com_assign_tuple(node, assigning) node = node[1] elif t in _assign_types: if len(node) > 2: raise SyntaxError, "can't assign to operator" node = node[1] elif t == symbol.power: if node[1][0] != symbol.atom: raise SyntaxError, "can't assign to operator" if len(node) > 2: primary = self.com_node(node[1]) for i in range(2, len(node)-1): ch = node[i] if ch[0] == token.DOUBLESTAR: raise SyntaxError, "can't assign to operator" primary = self.com_apply_trailer(primary, ch) return self.com_assign_trailer(primary, node[-1], assigning) node = node[1] elif t == symbol.atom: t = node[1][0] if t == token.LPAR: node = node[2] if node[0] == token.RPAR: raise SyntaxError, "can't assign to ()" elif t == token.LSQB: node = node[2] if node[0] == token.RSQB: raise SyntaxError, "can't assign to []" return self.com_assign_list(node, assigning) elif t == token.NAME: return self.com_assign_name(node[1], assigning) else: raise SyntaxError, "can't assign to literal" else: raise SyntaxError, "bad assignment (%s)" % t
Example #26
Source File: transformer.py From CTFCrackTools with GNU General Public License v3.0 | 4 votes |
def com_call_function(self, primaryNode, nodelist): if nodelist[0] == token.RPAR: return CallFunc(primaryNode, [], lineno=extractLineNo(nodelist)) args = [] kw = 0 len_nodelist = len(nodelist) for i in range(1, len_nodelist, 2): node = nodelist[i] if node[0] == token.STAR or node[0] == token.DOUBLESTAR: break kw, result = self.com_argument(node, kw) if len_nodelist != 2 and isinstance(result, GenExpr) \ and len(node) == 3 and node[2][0] == symbol.gen_for: # allow f(x for x in y), but reject f(x for x in y, 1) # should use f((x for x in y), 1) instead of f(x for x in y, 1) raise SyntaxError, 'generator expression needs parenthesis' args.append(result) else: # No broken by star arg, so skip the last one we processed. i = i + 1 if i < len_nodelist and nodelist[i][0] == token.COMMA: # need to accept an application that looks like "f(a, b,)" i = i + 1 star_node = dstar_node = None while i < len_nodelist: tok = nodelist[i] ch = nodelist[i+1] i = i + 3 if tok[0]==token.STAR: if star_node is not None: raise SyntaxError, 'already have the varargs indentifier' star_node = self.com_node(ch) elif tok[0]==token.DOUBLESTAR: if dstar_node is not None: raise SyntaxError, 'already have the kwargs indentifier' dstar_node = self.com_node(ch) else: raise SyntaxError, 'unknown node type: %s' % tok return CallFunc(primaryNode, args, star_node, dstar_node, lineno=extractLineNo(nodelist))
Example #27
Source File: transformer.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 4 votes |
def com_assign(self, node, assigning): # return a node suitable for use as an "lvalue" # loop to avoid trivial recursion while 1: t = node[0] if t in (symbol.exprlist, symbol.testlist, symbol.testlist_safe, symbol.testlist_gexp): if len(node) > 2: return self.com_assign_tuple(node, assigning) node = node[1] elif t in _assign_types: if len(node) > 2: raise SyntaxError, "can't assign to operator" node = node[1] elif t == symbol.power: if node[1][0] != symbol.atom: raise SyntaxError, "can't assign to operator" if len(node) > 2: primary = self.com_node(node[1]) for i in range(2, len(node)-1): ch = node[i] if ch[0] == token.DOUBLESTAR: raise SyntaxError, "can't assign to operator" primary = self.com_apply_trailer(primary, ch) return self.com_assign_trailer(primary, node[-1], assigning) node = node[1] elif t == symbol.atom: t = node[1][0] if t == token.LPAR: node = node[2] if node[0] == token.RPAR: raise SyntaxError, "can't assign to ()" elif t == token.LSQB: node = node[2] if node[0] == token.RSQB: raise SyntaxError, "can't assign to []" return self.com_assign_list(node, assigning) elif t == token.NAME: return self.com_assign_name(node[1], assigning) else: raise SyntaxError, "can't assign to literal" else: raise SyntaxError, "bad assignment (%s)" % t
Example #28
Source File: transformer.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 4 votes |
def com_arglist(self, nodelist): # varargslist: # (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME] | '**' NAME) # | fpdef ['=' test] (',' fpdef ['=' test])* [','] # fpdef: NAME | '(' fplist ')' # fplist: fpdef (',' fpdef)* [','] names = [] defaults = [] flags = 0 i = 0 while i < len(nodelist): node = nodelist[i] if node[0] == token.STAR or node[0] == token.DOUBLESTAR: if node[0] == token.STAR: node = nodelist[i+1] if node[0] == token.NAME: names.append(node[1]) flags = flags | CO_VARARGS i = i + 3 if i < len(nodelist): # should be DOUBLESTAR t = nodelist[i][0] if t == token.DOUBLESTAR: node = nodelist[i+1] else: raise ValueError, "unexpected token: %s" % t names.append(node[1]) flags = flags | CO_VARKEYWORDS break # fpdef: NAME | '(' fplist ')' names.append(self.com_fpdef(node)) i = i + 1 if i < len(nodelist) and nodelist[i][0] == token.EQUAL: defaults.append(self.com_node(nodelist[i + 1])) i = i + 2 elif len(defaults): # we have already seen an argument with default, but here # came one without raise SyntaxError, "non-default argument follows default argument" # skip the comma i = i + 1 return names, defaults, flags
Example #29
Source File: transformer.py From medicare-demo with Apache License 2.0 | 4 votes |
def com_call_function(self, primaryNode, nodelist): if nodelist[0] == token.RPAR: return CallFunc(primaryNode, [], lineno=extractLineNo(nodelist)) args = [] kw = 0 len_nodelist = len(nodelist) for i in range(1, len_nodelist, 2): node = nodelist[i] if node[0] == token.STAR or node[0] == token.DOUBLESTAR: break kw, result = self.com_argument(node, kw) if len_nodelist != 2 and isinstance(result, GenExpr) \ and len(node) == 3 and node[2][0] == symbol.gen_for: # allow f(x for x in y), but reject f(x for x in y, 1) # should use f((x for x in y), 1) instead of f(x for x in y, 1) raise SyntaxError, 'generator expression needs parenthesis' args.append(result) else: # No broken by star arg, so skip the last one we processed. i = i + 1 if i < len_nodelist and nodelist[i][0] == token.COMMA: # need to accept an application that looks like "f(a, b,)" i = i + 1 star_node = dstar_node = None while i < len_nodelist: tok = nodelist[i] ch = nodelist[i+1] i = i + 3 if tok[0]==token.STAR: if star_node is not None: raise SyntaxError, 'already have the varargs indentifier' star_node = self.com_node(ch) elif tok[0]==token.DOUBLESTAR: if dstar_node is not None: raise SyntaxError, 'already have the kwargs indentifier' dstar_node = self.com_node(ch) else: raise SyntaxError, 'unknown node type: %s' % tok return CallFunc(primaryNode, args, star_node, dstar_node, lineno=extractLineNo(nodelist))
Example #30
Source File: transformer.py From medicare-demo with Apache License 2.0 | 4 votes |
def com_assign(self, node, assigning): # return a node suitable for use as an "lvalue" # loop to avoid trivial recursion while 1: t = node[0] if t in (symbol.exprlist, symbol.testlist, symbol.testlist_safe, symbol.testlist_gexp): if len(node) > 2: return self.com_assign_tuple(node, assigning) node = node[1] elif t in _assign_types: if len(node) > 2: raise SyntaxError, "can't assign to operator" node = node[1] elif t == symbol.power: if node[1][0] != symbol.atom: raise SyntaxError, "can't assign to operator" if len(node) > 2: primary = self.com_node(node[1]) for i in range(2, len(node)-1): ch = node[i] if ch[0] == token.DOUBLESTAR: raise SyntaxError, "can't assign to operator" primary = self.com_apply_trailer(primary, ch) return self.com_assign_trailer(primary, node[-1], assigning) node = node[1] elif t == symbol.atom: t = node[1][0] if t == token.LPAR: node = node[2] if node[0] == token.RPAR: raise SyntaxError, "can't assign to ()" elif t == token.LSQB: node = node[2] if node[0] == token.RSQB: raise SyntaxError, "can't assign to []" return self.com_assign_list(node, assigning) elif t == token.NAME: return self.com_assign_name(node[1], assigning) else: raise SyntaxError, "can't assign to literal" else: raise SyntaxError, "bad assignment (%s)" % t