#NEWLINE# def _parse_sig( sig , arg_names , validate = False ) : #NEWLINE# #INDENT# "\n    Parses signatures into a ``OrderedDict`` of paramName => type.\n    Numerically-indexed arguments that do not correspond to an argument\n    name in python (ie: it takes a variable number of arguments) will be\n    keyed as the stringified version of it's index.\n\n      sig         the signature to be parsed\n      arg_names   a list of argument names extracted from python source\n\n    Returns a tuple of (method name, types dict, return type)\n    " #NEWLINE# d = SIG_RE . match ( sig ) #NEWLINE# if ( not d ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Invalid method signature %s' % sig ) ) #NEWLINE# #UNINDENT# d = d . groupdict ( ) #NEWLINE# ret = [ ( n , Any ) for n in arg_names ] #NEWLINE# if ( ( 'args_sig' in d ) and ( type ( d [ 'args_sig' ] ) is str ) and d [ 'args_sig' ] . strip ( ) ) : #NEWLINE# #INDENT# for ( i , arg ) in enumerate ( d [ 'args_sig' ] . strip ( ) . split ( ',' ) ) : #NEWLINE# #INDENT# _type_checking_available ( sig , validate ) #NEWLINE# if ( '=' in arg ) : #NEWLINE# #INDENT# if ( not ( type ( ret ) is OrderedDict ) ) : #NEWLINE# #INDENT# ret = OrderedDict ( ret ) #NEWLINE# #UNINDENT# dk = KWARG_RE . match ( arg ) #NEWLINE# if ( not dk ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Could not parse arg type %s in %s' % ( arg , sig ) ) ) #NEWLINE# #UNINDENT# dk = dk . groupdict ( ) #NEWLINE# if ( not sum ( [ ( ( k in dk ) and ( type ( dk [ k ] ) is str ) and bool ( dk [ k ] . strip ( ) ) ) for k in ( 'arg_name' , 'arg_type' ) ] ) ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Invalid kwarg value %s in %s' % ( arg , sig ) ) ) #NEWLINE# #UNINDENT# ret [ dk [ 'arg_name' ] ] = _eval_arg_type ( dk [ 'arg_type' ] , None , arg , sig ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( type ( ret ) is OrderedDict ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Positional arguments must occur before keyword arguments in %s' % sig ) ) #NEWLINE# #UNINDENT# if ( len ( ret ) < ( i + 1 ) ) : #NEWLINE# #INDENT# ret . append ( ( str ( i ) , _eval_arg_type ( arg , None , arg , sig ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ i ] = ( ret [ i ] [ 0 ] , _eval_arg_type ( arg , None , arg , sig ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( not ( type ( ret ) is OrderedDict ) ) : #NEWLINE# #INDENT# ret = OrderedDict ( ret ) #NEWLINE# #UNINDENT# return ( d [ 'method_name' ] , ret , ( _eval_arg_type ( d [ 'return_sig' ] , Any , 'return' , sig ) if d [ 'return_sig' ] else Any ) )