ó
Ú6e]c           @` sq  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  ƒ 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 rm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   lib/python2.7/site-packages/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   lib/python2.7/site-packages/numpy/distutils/lib2def.pyt   getnm@   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   lib/python2.7/site-packages/numpy/distutils/lib2def.pyt   parse_nmI   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   lib/python2.7/site-packages/numpy/distutils/lib2def.pyt
   output_def_   s    
t   __main__t   w(!   t
   __future__R    R   R   t   reR   R   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   lib/python2.7/site-packages/numpy/distutils/lib2def.pyt   <module>   s.   
			