ó
ŘĆ÷Xc           @` s}  d  d l  m Z m Z m Z d  d l Z d  d l Z d  d l Z d  d l Z d Z d Z	 d e
 e j d   Z d Z d e Z e j d	 e e j  Z e j d
 e e j  Z d   Z d d d e g d  Z d   Z e j d  Z e d k ry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  n  d S(   i    (   t   divisiont   absolute_importt   print_functionNsÔ  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
s   0.1as   %d%di   s   nm -Cssr   LIBRARY         python%s.dll
;CODE           PRELOAD MOVEABLE DISCARDABLE
;DATA           PRELOAD SINGLE

EXPORTS
s   ^(.*) in python%s\.dlls   ^_imp__(.*) in python%s\.dllc          C` sD  t  t j  d k r´ t j d d d k rY t j d d d k rY t j d \ }  } q:t j d d d k r t j d d d k r t j d \ } }  q:t d  t d  n t  t j  d k r*t j d d d k rú t j d } d	 t }  q:t j d d d k r:d
 } t j d }  q:n d	 t }  d
 } |  | f S(   sB   Parses the command-line arguments.

libfile, deffile = parse_cmd()i   i   iü˙˙˙s   .libi   s   .defs4   I'm assuming that your first argument is the librarys   and the second is the DEF file.s   python%s.libN(   t   lent   syst   argvt   printt   py_vert   None(   t   libfilet   deffile(    (    s6   /tmp/pip-build-X4mzal/numpy/numpy/distutils/lib2def.pyt	   parse_cmd)   s"    ..

t   nms   -Css   python%s.libc         C` sD   t  j |  d t d t  j d t } | j j   } | j j   | S(   sV   Returns the output of nm_cmd via a pipe.

nm_output = getnam(nm_cmd = 'nm -Cs py_lib')t   shellt   stdoutt   universal_newlines(   t
   subprocesst   Popent   Truet   PIPER   t   readt   close(   t   nm_cmdt   ft	   nm_output(    (    s6   /tmp/pip-build-X4mzal/numpy/numpy/distutils/lib2def.pyt   getnmA   s    $c         C` sň   t  j |   } t j |   } g  } xZ | D]R } | | k r+ | d  d k sm | d  d k sm | d  d k r+ | j |  q+ q+ Wg  } xJ | D]B } | | k r | d  d k sŔ | d  d k r | j |  q q W| j   | j   | | f S(   s   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)i   t   Pyi   t   _Pyi   t   init(   t   DATA_REt   findallt   FUNC_REt   appendt   sort(   R   t   datat   funct   flistt   symt   dlist(    (    s6   /tmp/pip-build-X4mzal/numpy/numpy/distutils/lib2def.pyt   parse_nmJ   s    <,

c         C` sY   x |  D] } | d | } q W| d } x | D] } | d | } q0 W| j  |  d S(   so   Outputs the final DEF file to a file defaulting to stdout.

output_def(dlist, flist, header, file = sys.stdout)s	   	%s DATA
s   
s   	%s
N(   t   write(   R&   R$   t   headert   filet   data_symt   func_sym(    (    s6   /tmp/pip-build-X4mzal/numpy/numpy/distutils/lib2def.pyt
   output_def`   s    
t   __main__t   w("   t
   __future__R    R   R   t   reR   t   osR   t   __doc__t   __version__t   tuplet   version_infoR   t
   DEFAULT_NMt
   DEF_HEADERt   compilet	   MULTILINER   R   R   R   R'   R   R-   t   __name__R	   R
   R   t   opent   strR   R   R&   R$   (    (    (    s6   /tmp/pip-build-X4mzal/numpy/numpy/distutils/lib2def.pyt   <module>   s0   
			