#NEWLINE# def _c_func_wrapper_factory( cdecl_text ) : #NEWLINE# #INDENT# def move_pointer_and_strip( type_def , name ) : #NEWLINE# #INDENT# if ( '*' in name ) : #NEWLINE# #INDENT# type_def += ( ' ' + name [ : ( name . rindex ( '*' ) + 1 ) ] ) #NEWLINE# name = name . rsplit ( '*' , 1 ) [ 1 ] #NEWLINE# #UNINDENT# return ( type_def . strip ( ) , name . strip ( ) ) #NEWLINE# #UNINDENT# def type_lookup( type_def ) : #NEWLINE# #INDENT# types = { #NEWLINE# #INDENT# 'void' : None , #NEWLINE# 'char *' : ctypes . c_char_p , #NEWLINE# 'int' : ctypes . c_int , #NEWLINE# 'int *' : ctypes . POINTER ( ctypes . c_int ) , #NEWLINE# 'void *' : ctypes . c_void_p , #NEWLINE# 'size_t' : ctypes . c_size_t , #NEWLINE# 'size_t *' : ctypes . POINTER ( ctypes . c_size_t ) , #NEWLINE# 'struct nn_msghdr *' : ctypes . c_void_p , #NEWLINE# #UNINDENT# } #NEWLINE# type_def_without_const = type_def . replace ( 'const ' , '' ) #NEWLINE# if ( type_def_without_const in types ) : #NEWLINE# #INDENT# return types [ type_def_without_const ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( type_def_without_const . endswith ( '*' ) and ( type_def_without_const [ : ( - 1 ) ] in types ) ) : #NEWLINE# #INDENT# return ctypes . POINTER ( types [ type_def_without_const [ : ( - 1 ) ] ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise KeyError ( type_def ) #NEWLINE# #UNINDENT# #UNINDENT# return types [ type_def . replace ( 'const ' , '' ) ] #NEWLINE# #UNINDENT# ( a , b ) = [ i . strip ( ) for i in cdecl_text . split ( '(' , 1 ) ] #NEWLINE# ( params , _ ) = b . rsplit ( ')' , 1 ) #NEWLINE# ( rtn_type , name ) = move_pointer_and_strip ( * a . rsplit ( ' ' , 1 ) ) #NEWLINE# param_spec = [ ] #NEWLINE# for param in params . split ( ',' ) : #NEWLINE# #INDENT# if ( param != 'void' ) : #NEWLINE# #INDENT# param_spec . append ( move_pointer_and_strip ( * param . rsplit ( ' ' , 1 ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# func = _functype ( type_lookup ( rtn_type ) , * [ type_lookup ( type_def ) for ( type_def , _ ) in param_spec ] ) ( ( name , _lib ) , tuple ( ( ( ( 2 if ( '**' in type_def ) else 1 ) , name ) for ( type_def , name ) in param_spec ) ) ) #NEWLINE# func . __name__ = name #NEWLINE# return func