U ã€C^® ã@sddlmZmZmZddlZddlZddlZdZdZde ej dd…ƒZ dZ de Z e d e ej¡Ze d e ej¡Zd d „Zd dde gfdd„Zdd„Zejfdd„Zedk�reƒ\ZZedkrÒejZn eedƒZee ƒeeƒgZeeƒZeeƒ\ZZeeee eƒdS)é)ÚdivisionÚabsolute_importÚprint_functionNaÔThis 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%déznm -CszrLIBRARY python%s.dll ;CODE PRELOAD MOVEABLE DISCARDABLE ;DATA PRELOAD SINGLE EXPORTS z^(.*) in python%s\.dllz^_imp__(.*) in python%s\.dllcCsttjƒdkr tjddd…dkrNtjddd…dkrNtjdd…\}}nPtjddd…dkrŽtjddd…dkrŽtjdd…\}}ntdƒtd ƒnjttjƒdkrþtjddd…dkrØtjd}d t}n$tjddd…dkrüd}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)ÚlenÚsysÚargvÚprintÚpy_ver)ÚlibfileÚdeffile©rú:/tmp/pip-install-6_kvzl1k/numpy/numpy/distutils/lib2def.pyÚ parse_cmd(s",,    rÚnmz-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)ÚshellÚstdoutÚuniversal_newlines)Ú subprocessÚPopenÚPIPErÚreadÚclose)Únm_cmdÚfÚ nm_outputrrrÚgetnm@s  r cCs¼t |¡}t |¡}g}|D]F}||kr|dd…dksX|dd…dksX|dd…dkr| |¡qg}|D]6}||krl|dd…dks˜|dd…dkrl| |¡ql| ¡| ¡||fS)zŒReturns 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_PyéÚinit)ÚDATA_REÚfindallÚFUNC_REÚappendÚsort)rÚdataÚfuncÚflistÚsymÚdlistrrrÚparse_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*ÚheaderÚfileZdata_symZfunc_symrrrÚ output_def_s r2Ú__main__Úw) Ú __future__rrrÚrer rÚ__doc__Ú __version__ÚtupleÚ version_inforZ DEFAULT_NMZ DEF_HEADERÚcompileÚ MULTILINEr%r#rr r-rr2Ú__name__rrÚopenÚstrrrr,r*rrrrÚs2û