#NEWLINE# def parse_argument_spec( spec ) : #NEWLINE# #INDENT# 'Take a function argument spec (e.g. "x, y=3") and parse it into a\n    structure. Raises SyntaxError if the spec is invalid.\n    Do not include the parentheses in the spec.\n    This relies on the Python mechanism in ast.parse.\n    \n    The defaults and kw_defaults arrays in the result contain ast nodes.\n    The caller should immediately evaluate these (self.execcode_expr).\n    (The tests and code both assume that spec.defaults and spec.kw_defaults\n    are reassignable.)\n    ' #NEWLINE# if ( not spec ) : #NEWLINE# #INDENT# spec = '' #NEWLINE# #UNINDENT# val = ( 'lambda %s : None' % ( spec , ) ) #NEWLINE# tree = ast . parse ( val ) #NEWLINE# assert ( type ( tree ) is ast . Module ) #NEWLINE# if ( len ( tree . body ) != 1 ) : #NEWLINE# #INDENT# raise SyntaxError ( 'apparent Bobby Tables in argument spec' ) #NEWLINE# #UNINDENT# nod = tree . body [ 0 ] #NEWLINE# assert ( type ( nod ) is ast . Expr ) #NEWLINE# nod = nod . value #NEWLINE# assert ( type ( nod ) is ast . Lambda ) #NEWLINE# res = nod . args #NEWLINE# argset = set ( ) #NEWLINE# for arg in res . args : #NEWLINE# #INDENT# if ( arg . arg in argset ) : #NEWLINE# #INDENT# raise SyntaxError ( ( 'duplicate argument %s in function definition' % ( res . arg , ) ) ) #NEWLINE# #UNINDENT# argset . add ( arg . arg ) #NEWLINE# #UNINDENT# for arg in res . kwonlyargs : #NEWLINE# #INDENT# if ( arg . arg in argset ) : #NEWLINE# #INDENT# raise SyntaxError ( ( 'duplicate argument %s in function definition' % ( arg . arg , ) ) ) #NEWLINE# #UNINDENT# argset . add ( arg . arg ) #NEWLINE# #UNINDENT# if ( res . vararg is not None ) : #NEWLINE# #INDENT# if ( res . vararg in argset ) : #NEWLINE# #INDENT# raise SyntaxError ( ( 'duplicate argument %s in function definition' % ( res . vararg , ) ) ) #NEWLINE# #UNINDENT# argset . add ( res . vararg ) #NEWLINE# #UNINDENT# if ( res . kwarg is not None ) : #NEWLINE# #INDENT# if ( res . kwarg in argset ) : #NEWLINE# #INDENT# raise SyntaxError ( ( 'duplicate argument %s in function definition' % ( res . kwarg , ) ) ) #NEWLINE# #UNINDENT# argset . add ( res . kwarg ) #NEWLINE# #UNINDENT# return res