U C^ @sddlmZmZmZddlZddlZddlZdZdZde ej ddZ dZ de Z ed e ejZed e ejZd d Zd dde gfddZddZejfddZedkre\ZZedkrejZn eedZee eegZeeZee\ZZeeee edS))divisionabsolute_importprint_functionNaThis 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%dznm -CszrLIBRARY python%s.dll ;CODE PRELOAD MOVEABLE DISCARDABLE ;DATA PRELOAD SINGLE EXPORTS z^(.*) in python%s\.dllz^_imp__(.*) in python%s\.dllcCsttjdkrtjddddkrNtjddddkrNtjdd\}}nPtjddddkrtjddddkrtjdd\}}ntdtd njttjdkrtjddddkrtjd}d t}n$tjddddkrd}tjd}n d 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)libfiledeffiler:/tmp/pip-install-6_kvzl1k/numpy/numpy/distutils/lib2def.py parse_cmd(s",,    rnmz-Csr cCs,tj|dtjdd}|j}|j|S)zVReturns the output of nm_cmd via a pipe. nm_output = getnam(nm_cmd = 'nm -Cs py_lib')T)shellstdoutuniversal_newlines) subprocessPopenPIPErreadclose)nm_cmdf nm_outputrrrgetnm@s  r cCst|}t|}g}|D]F}||kr|dddksX|dddksX|dddkr||qg}|D]6}||krl|dddks|dddkrl||ql||||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)NrZPyrZ_Pyinit)DATA_REfindallFUNC_REappendsort)rdatafuncflistsymdlistrrrparse_nmIs  8 ( r-cCsB|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)r,r*headerfileZdata_symZfunc_symrrr output_def_s r2__main__w) __future__rrrrer r__doc__ __version__tuple version_inforZ DEFAULT_NMZ DEF_HEADERcompile MULTILINEr%r#rr r-rr2__name__rropenstrrrr,r*rrrrs2