o 6a<@sddlZddlZddlZdZdZdeejddZddgZdeZ e d eej Z e d eej Z d d Zddd egdfddZddZejfddZedkre\ZZeduraejZneedZeeegZeeddZee\ZZeeee edSdS)NaThis module generates a DEF file from the symbols in an MSVC-compiled DLL import library. It correctly discriminates between data and functions. The data is collected from the output of the program nm(1). Usage: python lib2def.py [libname.lib] [output.def] or python lib2def.py [libname.lib] > output.def libname.lib defaults to python.lib and output.def defaults to stdout Author: Robert Kern Last Update: April 30, 1999 z0.1az%d%dnmz-CszrLIBRARY python%s.dll ;CODE PRELOAD MOVEABLE DISCARDABLE ;DATA PRELOAD SINGLE EXPORTS z^(.*) in python%s\.dllz^_imp__(.*) in python%s\.dllcCs0ttjdkrYtjddddkr*tjddddkr*tjdd\}}||fStjddddkrMtjddddkrMtjdd\}}||fStdtd ||fSttjdkrtjddddkrxtjd}d t}||fStjddddkrd}tjd}||fSd t}d}||fS) zBParses the command-line arguments. libfile, deffile = parse_cmd()Nz.librz.defz4I'm assuming that your first argument is the libraryzand the second is the DEF file. python%s.lib)lensysargvprintpy_ver)libfiledeffiler9/usr/lib/python3/dist-packages/numpy/distutils/lib2def.py parse_cmd&s,,,   rrTcCsHtj||tjtjdd}|\}}|jdkr"tdd||f|S)zUReturns the output of nm_cmd via a pipe. nm_output = getnm(nm_cmd = 'nm -Cs py_lib')T)shellstdoutstderruniversal_newlinesrzfailed to run "%s": "%s" ) subprocessPopenPIPE communicate returncode RuntimeErrorjoin)nm_cmdrp nm_outputnm_errrrrgetnm>s    r"cCst|}t|}g}|D]#}||vr1|dddks,|dddks,|dddkr1||qg}|D]}||vrQ|dddksL|dddkrQ||q6||||fS)zReturns a tuple of lists: dlist for the list of data symbols and flist for the list of function symbols. dlist, flist = parse_nm(nm_output)NrPyr_Pyinit)DATA_REfindallFUNC_REappendsort)r datafuncflistsymdlistrrrparse_nmJs  8 ( r1cCsB|D]}|d|}q|d}|D]}|d|}q||dS)zoOutputs the final DEF file to a file defaulting to stdout. output_def(dlist, flist, header, file = sys.stdout)z %s DATA  z %s N)write)r0r.headerfiledata_symfunc_symrrr output_def`s r8__main__wF)r)rer r__doc__ __version__tuple version_infor DEFAULT_NM DEF_HEADERcompile MULTILINEr)r'rr"r1rr8__name__r ropenstrrr r0r.rrrrs4