a
    hÝEb<  ã                   @   s  d dl Z d dlZd dlZdZdZdeejdd… ƒ ZddgZde Z	e  
d	e e j¡Ze  
d
e e j¡Zdd„ Zddde gdfdd„Zdd„ Zejfdd„Zedk�reƒ \ZZedu rÄejZn
eedƒZeeeƒg Zeedd�Zeeƒ\ZZeeee	eƒ dS )é    NaÔ  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<py_ver>.lib and output.def defaults to stdout

Author: Robert Kern <kernr@mail.ncifcrf.gov>
Last Update: April 30, 1999
z0.1az%d%dé   Únmz-CszrLIBRARY         python%s.dll
;CODE           PRELOAD MOVEABLE DISCARDABLE
;DATA           PRELOAD SINGLE

EXPORTS
z^(.*) in python%s\.dllz^_imp__(.*) in python%s\.dllc                  C   s  t tjƒdkr tjd dd… dkrNtjd dd… dkrNtjdd… \} }nPtjd dd… dkrŽtjd dd… dkrŽtjdd… \}} ntdƒ td	ƒ njt tjƒdkrþtjd dd… dkrØtjd }d
t } n$tjd dd… dkrüd}tjd } nd
t } d}| |fS )zBParses the command-line arguments.

libfile, deffile = parse_cmd()é   é   éüÿÿÿNz.libr   z.defz4I'm assuming that your first argument is the libraryzand the second is the DEF file.úpython%s.lib)ÚlenÚsysÚargvÚprintÚpy_ver)ÚlibfileÚdeffile© r   úW/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/numpy/distutils/lib2def.pyÚ	parse_cmd&   s"    ,,


r   r   Tc                 C   sH   t j| |t jt jdd�}| ¡ \}}|jdkrDtdd | ¡|f ƒ‚|S )zUReturns the output of nm_cmd via a pipe.

nm_output = getnm(nm_cmd = 'nm -Cs py_lib')T)ÚshellÚstdoutÚstderrÚuniversal_newlinesr   zfailed to run "%s": "%s"ú )Ú
subprocessÚPopenÚPIPEÚcommunicateÚ
returncodeÚRuntimeErrorÚjoin)Únm_cmdr   ÚpÚ	nm_outputZnm_errr   r   r   Úgetnm>   s    ÿ

ÿr!   c                 C   s¼   t  | ¡}t | ¡}g }|D ]F}||v r|dd… dksX|dd… dksX|dd… dkr| |¡ qg }|D ]6}||vrl|dd… dks˜|dd… dkrl| |¡ ql| ¡  | ¡  ||fS )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)Nr   ZPyr   Z_Pyé   Úinit)ÚDATA_REÚfindallÚFUNC_REÚappendÚsort)r    ÚdataÚfuncÚflistÚsymÚdlistr   r   r   Úparse_nmJ   s    

8(r.   c                 C   sB   | D ]}|d|  }q|d }|D ]}|d|  }q"|  |¡ dS )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ÚfileZdata_symZfunc_symr   r   r   Ú
output_def`   s    r3   Ú__main__ÚwF)r   )Úrer	   r   Ú__doc__Ú__version__ÚtupleÚversion_infor   Z
DEFAULT_NMZ
DEF_HEADERÚcompileÚ	MULTILINEr&   r$   r   r!   r.   r   r3   Ú__name__r   r   ÚopenÚstrr   r    r-   r+   r   r   r   r   Ú<module>   s0   û


