
;>"^                 @   s  d  d l  m Z m Z m Z d  d l Z d  d l Z d  d l Z d Z d Z d e	 e j
 d d   Z d Z d e Z e j d	 e e j  Z e j d
 e e j  Z d d   Z d d d e g d d  Z d d   Z e j d d  Z e d k r|e   \ Z Z e d k r$e j Z n e e d  Z e e  e e  g Z e e  Z e e  \ Z Z e e e e e  d S)    )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<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   znm -CszrLIBRARY         python%s.dll
;CODE           PRELOAD MOVEABLE DISCARDABLE
;DATA           PRELOAD SINGLE

EXPORTS
z^(.*) in python%s\.dllz^_imp__(.*) in python%s\.dllc              C   sq  t  t j  d k r t j d d d  d k rk t j d d d  d k rk t j d d  \ }  } qgt j d d d  d k r t j d d d  d k r t j d d  \ } }  qgt d  t d	  n t  t j  d k rWt j d d d  d k r$t j d } d
 t }  qgt j d d d  d k rg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.zpython%s.libr	   r	   r	   r	   r	   )lensysargvprintpy_ver)libfiledeffile r   I/home/birch/.local/lib/python3.5/site-packages/numpy/distutils/lib2def.py	parse_cmd(   s"    ::

r   nmz-Cszpython%s.libc             C   sD   t  j |  d d d t  j d d } | j j   } | j j   | S)zVReturns the output of nm_cmd via a pipe.

nm_output = getnam(nm_cmd = 'nm -Cs py_lib')shellTstdoutuniversal_newlines)
subprocessPopenPIPEr   readclose)nm_cmdf	nm_outputr   r   r   getnm@   s    $r    c             C   s
  t  j |   } t j |   } g  } xi | D]a } | | k r+ | d d  d k s | d d  d k s | d d  d k r+ | j |  q+ Wg  } xS | D]K } | | k r | d d  d k s | d d  d k r | j |  q W| j   | j   | | 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   ZPyr   Z_Pyr   init)DATA_REfindallFUNC_REappendsort)r   datafuncflistsymdlistr   r   r   parse_nmI   s    N8

r,   c             C   sY   x |  D] } | d | } q W| d } x | D] } | d | } q0 W| j  |  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    
r1   __main__w) 
__future__r   r   r   rer   r   __doc____version__tupleversion_infor   
DEFAULT_NM
DEF_HEADERcompile	MULTILINEr$   r"   r   r    r,   r   r1   __name__r   r   openstrr   r   r+   r)   r   r   r   r   <module>   s.   
	