
    G/Ph.                        d dl Z d dlZd dlZdZdZd eej        dd                   z  ZddgZdez  Z	 e j
        d	ez  e j                  Z e j
        d
ez  e j                  Zd Zdddez  gdfdZd Zej        fdZedk    r] e            \  ZZeej        Zn eed          Ze ee          gz   Z eed          Z ee          \  ZZ eeee	e           dS 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                     t          t          j                  dk    rt          j        d         dd         dk    r7t          j        d         dd         dk    rt          j        dd         \  } }n
t          j        d         dd         dk    r6t          j        d         dd         dk    rt          j        dd         \  }} nt          d           t          d	           nt          t          j                  dk    rnt          j        d         dd         dk    rt          j        d         }d
t          z  } n?t          j        d         dd         dk    rd}t          j        d         } nd
t          z  } 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deffiles     W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numpy/distutils/lib2def.py	parse_cmdr   &   sS    38}}8A;rssv%%#(1+bcc*:f*D*D"x|GWWXa[''CHQK,<,F,F"x|GWWHIII34444	SX!		8A;rssv%%hqkG$v-GGXa[''GhqkG 6)G    r	   Tc                     t          j        | |t           j        t           j        d          }|                                \  }}|j        dk    r)t          dd                    |           d|d          |S )zUReturns the output of nm_cmd via a pipe.

nm_output = getnm(nm_cmd = 'nm -Cs py_lib')T)shellstdoutstderrtextr   zfailed to run " z": "")
subprocessPopenPIPEcommunicate
returncodeRuntimeErrorjoin)nm_cmdr   p	nm_outputnm_errs        r   getnmr&   >   s     	uZ_ *d	< 	< 	<AIv|ql%(XXf%5%5%5%5vvv? @ @ 	@r   c                    t                               |           }t                              |           }g }|D ]E}||v r?|dd         dk    s|dd         dk    s|dd         dk    r|                    |           Fg }|D ]7}||vr1|dd         dk    s|dd         dk    r|                    |           8|                                 |                                 ||fS )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)Nr   Pyr   _Py   init)DATA_REfindallFUNC_REappendsort)r$   datafuncflistsymdlists         r   parse_nmr6   J   s   
 ??9%%D??9%%DE  $;;CGtOOs2A2w%/?/?3rr7fCTCTLLE  eRaRDCGu4D4DLL	JJLLL	JJLLL%<r   c                 n    | D ]
}|d|z  z   }|dz   }|D ]
}|d|z  z   }|                     |           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)r5   r3   headerfiledata_symfunc_syms         r   
output_defr>   `   se      3 3-(22d]F . .(X--JJvr   __main__wF)r   )rer   r   __doc____version__tupleversion_infor   
DEFAULT_NM
DEF_HEADERcompile	MULTILINEr.   r,   r   r&   r6   r   r>   __name__r   r   openstrr"   r$   r5   r3    r   r   <module>rN      s   				 



      	%%(!,--	-E]

 
 "*.7
F
F
"*4v=r|
L
L  0 ~67t 
 
 
 
  , -0J 	 	 	 	 z y{{GW*$w$$33w<<.(FfE***I8I&&LE5JueZ11111 r   