ó
¹å½\c           @   s}   d  d l  Z  d  d l Z y e Wn e k
 r9 e Z n Xd „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d S(	   iÿÿÿÿNc         C   s    d d l  m } | |  ƒ ‚ d  S(   Niÿÿÿÿ(   t   DistutilsSetupError(   t   distutils.errorsR    (   t   msgR    (    (    s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyt   error
   s    c         B   sK   e  |  ƒ  } | j ƒ  } Wd  QX| d 7} e | |  d ƒ } | | | Ud  S(   Ns   
t   exec(   t   opent   readt   compile(   t   filenamet   globt   ft   srct   code(    (    s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyt   execfile   s
    
c         C   s/  d d l  m } t | t ƒ s< t d t | ƒ j f ƒ n  t | ƒ } y | j d ƒ \ } } Wn" t	 k
 r… t d | f ƒ n Xt
 j j | ƒ sõ d } | j d d ƒ d	 } t
 j j | ƒ rÞ d
 | d | f } n  t d | | f ƒ n  i d d 6| d 6} t | | ƒ y | | } Wn% t k
 rKt d | | f ƒ n Xt | | ƒ sg| ƒ  } n  t | | ƒ s–t d | t | ƒ j f ƒ n  t | d ƒ s¹t d | f ƒ n  | j \ }	 }
 } } | j ró| j ƒ  } | j | ƒ n  |
 d  k rt |  | |	 ƒ n t |  | |	 |
 | | ƒ d  S(   Niÿÿÿÿ(   t   FFIsE   argument to 'cffi_modules=...' must be a str or a list of str, not %rt   :s3   %r must be of the form 'path/build.py:ffi_variable't    t   .t   /s   .pys    (rewrite cffi_modules to [%r])s#   %r does not name an existing file%st   __cffi__t   __name__t   __file__s!   %r: object %r not found in modules"   %r is not an FFI instance (got %r)t   _assigned_sources*   %r: the set_source() method was not called(   t   cffi.apiR   t
   isinstancet
   basestringR   t   typeR   t   strt   splitt
   ValueErrort   ost   patht   existst   replaceR   t   KeyErrort   hasattrR   t   _windows_unicodet   copyt   _apply_windows_unicodet   Nonet   _add_py_modulet   _add_c_module(   t   distt   mod_specR   t   build_file_namet   ffi_var_namet   extt	   rewrittent   mod_varst   ffit   module_namet   sourcet   source_extensiont   kwds(    (    s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyt   add_cffi_module   sL    			c         C   s•   d | k r‘ t  t d ƒ r‘ t j d k r‘ d d l } y9 t | j j d ƒ d ƒ } | d k ro t | d <n  Wq‘ t k
 r t | d <q‘ Xn  | S(	   s  
    Add py_limited_api to kwds if setuptools >= 26 is in use.
    Do not alter the setting if it already exists.
    Setuptools takes care of ignoring the flag on Python 2 and PyPy.

    CPython itself should ignore the flag in a debugging version
    (by not listing .abi3.so in the extensions it supports), but
    it doesn't so far, creating troubles.  That's why we check
    for "not hasattr(sys, 'gettotalrefcount')" (the 2.7 compatible equivalent
    of 'd' not in sys.abiflags). (http://bugs.python.org/issue28401)

    On Windows, with CPython <= 3.4, it's better not to use py_limited_api
    because virtualenv *still* doesn't copy PYTHON3.DLL on these versions.
    For now we'll skip py_limited_api on all Windows versions to avoid an
    inconsistent mess.
    t   py_limited_apit   gettotalrefcountt   win32iÿÿÿÿNR   i    i   (	   R#   t   syst   platformt
   setuptoolst   intt   __version__t	   partitiont   TrueR   (   t	   ExtensionR5   R<   t   setuptools_major_version(    (    s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyt   _set_py_limited_apiI   s    c   
   	      s3  d d l  m } d d l m } d d l m ‰ d d l m ‰ d d l m	 ‰ d g } | j
 | j d g  ƒ ƒ t | | ƒ } | d	 ˆ d | |  ‰ d  ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡	 f d
 † ‰ |  j d  k rÛ g  |  _ n  |  j j ˆ ƒ |  j j d | ƒ ‰  d ˆ  f ‡  ‡ ‡ f d †  ƒ  Y}	 |	 |  j d <d  S(   Niÿÿÿÿ(   RA   (   t	   build_ext(   t   mkpath(   t   log(   t
   recompilers   $PLACEHOLDERt   sourcest   namec            s‚   t  j j |  ˆ ˆ ƒ } ˆ j d | ƒ ˆ |  ƒ | d  k	 rP | ˆ  ˆ ƒ n  ˆ j ˆ ˆ ˆ | ƒ } | s~ ˆ j d ƒ n  | S(   Ns   generating cffi module %rs   already up-to-date(   R   R   t   joint   infoR'   t   make_c_source(   t   tmpdirt   pre_runt   c_filet   updated(   R.   R1   RF   RE   R2   RG   R3   R4   (    s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyt   make_modu   s    
RD   t   build_ext_make_modc              s   e  Z ‡  ‡ ‡ f d  †  Z RS(   c            sR   ˆ j  d d k rA t |  d d  ƒ } ˆ |  j | ƒ ˆ j  d <n  ˆ  j |  ƒ d  S(   Ni    s   $PLACEHOLDERRN   (   RH   t   getattrR'   t
   build_tempt   run(   t   selfRN   (   t
   base_classR.   RQ   (    s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyRU   Š   s    (   R   t
   __module__RU   (    (   RW   R.   RQ   (    s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyRR   ‰   s   (   t   distutils.coreRA   t   setuptools.command.build_extRD   t   distutils.dir_utilRE   t	   distutilsRF   t   cffiRG   t   extendt   popRC   R'   t   ext_modulest   appendt   cmdclasst   get(
   R*   R1   R2   R3   R4   R5   RA   RD   t
   allsourcesRR   (    (
   RW   R.   R1   RF   RQ   RE   R2   RG   R3   R4   s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyR)   h   s     	'"c            s"  d d l  m ‰ d d l m } d d l m } d d l m ‰ d d l m	 ‰ ‡ ‡ ‡ ‡ ‡ f d †  ‰ |  j
 j d | ƒ ‰  d	 ˆ  f ‡  ‡ ‡ f d
 †  ƒ  Y} | |  j
 d <|  j d  k rÊ g  |  _ n  |  j j ˆ ƒ |  j
 j d | ƒ ‰ d ˆ f ‡ ‡ ‡ f d †  ƒ  Y} | |  j
 d <d  S(   Niÿÿÿÿ(   RE   (   t   build_py(   RD   (   RF   (   RG   c            sV   ˆ j  d |  ƒ ˆ t j j |  ƒ ƒ ˆ j ˆ  ˆ |  ƒ } | sR ˆ j  d ƒ n  d  S(   Ns   generating cffi module %rs   already up-to-date(   RK   R   R   t   dirnamet   make_py_source(   t   py_fileRP   (   R1   RF   RE   R2   RG   (    s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyt   generate_mod   s
    Re   t   build_py_make_modc              s/   e  Z ‡  ‡ ‡ f d  †  Z ‡  ‡ f d †  Z RS(   c            sL   ˆ  j  |  ƒ ˆ j d ƒ } | d c d 7<ˆ t j j |  j | Œ ƒ d  S(   NR   iÿÿÿÿs   .py(   RU   R   R   R   RJ   t	   build_lib(   RV   t   module_path(   RW   Ri   R2   (    s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyRU   ¦   s    c            s\   |  j  } zB | r= g  | D] } | ˆ k r | ^ q |  _  n  ˆ  j |  ƒ SWd  | |  _  Xd  S(   N(   t
   py_modulest   get_source_files(   RV   t   saved_py_modulest   m(   RW   R2   (    s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyRn   «   s    	(   R   RX   RU   Rn   (    (   RW   Ri   R2   (    s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyRj   ¥   s   RD   RR   c              s   e  Z ‡  ‡ ‡ f d  †  Z RS(   c            s„   ˆ  j  |  ƒ |  j r€ ˆ j d ƒ } d j | d  ƒ } |  j d ƒ } | j | ƒ } | d d } ˆ t j j | | ƒ ƒ n  d  S(   NR   iÿÿÿÿRe   s   .py(   RU   t   inplaceR   RJ   t   get_finalized_commandt   get_package_dirR   R   (   RV   Rl   t   packageRe   t   package_dirt	   file_name(   t   base_class_2Ri   R2   (    s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyRU   Ç   s    	(   R   RX   RU   (    (   Rw   Ri   R2   (    s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyRR   Æ   s   (   R[   RE   t   setuptools.command.build_pyRe   RZ   RD   R\   RF   R]   RG   Rb   Rc   Rm   R'   Ra   (   R*   R1   R2   Re   RD   Rj   RR   (    (   RW   Rw   R1   Ri   RF   RE   R2   RG   s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyR(   –   s    "
"c         C   sO   | d k s t  ‚ t | t ƒ r- | g } n  x | D] } t |  | ƒ q4 Wd  S(   Nt   cffi_modules(   t   AssertionErrorR   R   R6   (   R*   t   attrt   valuet   cffi_module(    (    s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyRy   Ó   s
    (   R   R:   R   t	   NameErrorR   R   R   R6   RC   R)   R(   Ry   (    (    (    s2   lib/python2.7/site-packages/cffi/setuptools_ext.pyt   <module>   s   
			-		.	=