Ñò
 pXJc           @   së   d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ	 d  d k
 Z
 d e f d „  ƒ  YZ d „  Z d	 „  Z h  h  d
 e i d „ Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿNt   ext_function_from_specsc           B   sk   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z RS(   c         C   s@   | |  _  t i | ƒ |  _ | |  _ d |  _ t i ƒ  |  _ d  S(   Nt    (	   t   namet	   base_spect   arg_spec_listt	   arg_specst
   code_blockt   compilert	   base_infot   custom_infot	   customize(   t   selfR   R   R   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   __init__   s
    			c         C   s   d  S(   N(    (   R   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   header_code   s    c         C   s   d } | |  i  S(   NsF   static PyObject* %s(PyObject*self, PyObject* args, PyObject* kywds)
{
(   R   (   R   t   code(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   function_declaration_code   s    c         C   s   d } | |  i  S(   NsX   template<class T>
static PyObject* %s(PyObject*self, PyObject* args, PyObject* kywds)
{
(   R   (   R   R   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   template_declaration_code   s    c         C   s|  d } |  i  i ƒ  d g } d i | ƒ } | o | d 7} n d | } d i |  i  i ƒ  ƒ } d i |  i  i ƒ  ƒ } d i |  i  i ƒ  ƒ } d i |  i  i ƒ  ƒ } | o< d | d	 }	 |	 d
 | d	 7}	 | d }
 |
 | d 7}
 n d }	 d }
 d i |  i  i ƒ  ƒ } | o | d 7} n d } d t |  i  ƒ d d |  i } d | | f } | d 7} | | |	 |
 | S(   s¸    Create code block for PyArg_ParseTuple.  Variable declarations
            for all PyObjects are done also.

            This code got a lot uglier when I added local_dict...
        sR   py::object return_val;
int exception_occured = 0;
PyObject *py_local_dict = NULL;
s   "local_dict"t   ,s#   static char *kwlist[] = {%s NULL};
s   , s   = s    = s	   PyObject s   ;
s   int s	    = NULL;
s    = 0;

R   s   , &py_local_dicts   &py_local_dictt   Os   |Ot   :s<   if(!PyArg_ParseTupleAndKeywords(args,kywds,"%s",kwlist,%s))
s      return NULL;
(	   R   t   variable_as_stringst   joint   py_pointerst
   init_flagst   py_variablest   py_referencest   lenR   (   R   t   declare_returnt   arg_string_listt   arg_stringst   declare_kwlistt
   py_objectsR   t   init_flags_initt   py_varst   declare_py_objectst   init_valuest
   ref_stringt   formatt   parse_tuple(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   parse_tuple_code%   s4     

"
c         C   sW   g  } x; |  i  D]0 } | i | i ƒ  ƒ | i | i ƒ  d ƒ q Wd i | ƒ } | S(   Ns    = 1;
R   (   R   t   appendt   declaration_codet	   init_flagR   (   R   R   t   argR   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   arg_declaration_codeS   s    
 c         C   s‰   g  } t  d „  |  i ƒ } xX | D]P } d | i ƒ  } | d 7} | t | i ƒ  d ƒ 7} | d 7} | i | ƒ q" Wd i | ƒ } | S(   Nc         S   s
   |  i  ƒ  S(    (   t   cleanup_code(   t   x(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   <lambda>]   s    s   if(%s)
s   {
i   s   }
R   (   t   filterR   R*   t   indentR-   R(   R   (   R   R   t   have_cleanupR+   R   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   arg_cleanup_code[   s     

c         C   s@   g  } x$ |  i  D] } | i | i ƒ  ƒ q Wd i | ƒ } | S(   NR   (   R   R(   t   local_dict_codeR   (   R   R   R+   R   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   arg_local_dict_codeg   s    
 c   
      C   sÛ   t  |  i ƒ  d ƒ } t  |  i ƒ  d ƒ } t  |  i d ƒ } t  |  i ƒ  d ƒ } d | d } d | d | t  | d ƒ d } d d } d	 | d
 } |  i ƒ  t  |  i ƒ  d ƒ t  | d ƒ t  | d ƒ | }	 |	 S(   Ni   sœ   if(py_local_dict)                                  
{                                                  
    py::dict local_dict = py::dict(py_local_dict); 
s4   }                                                  
sD   try                              
{                                
s"       /*<function call here>*/     
s#   
}                                
sD   catch(...)                       
{                                
sj       return_val =  py::object();      
    exception_occured = 1;       
}                                
s*       /*cleanup code*/                     
sþ       if(!(PyObject*)return_val && !exception_occured)
    {
                                  
        return_val = Py_None;            
    }
                                  
    return return_val.disown();           
}                                
(   R1   R,   R3   R   R5   R   R'   (
   R   t	   decl_codeR-   t   function_codeR4   t	   dict_codet   try_codet
   catch_codet   return_codet   all_code(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR7   n   s    
6c         C   s    |  i  |  i  f } d | } | S(   Ns5   {"%s",(PyCFunction)%s , METH_VARARGS|METH_KEYWORDS},
(   R   (   R   t   argst   function_decls(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   python_function_definition_code˜   s    c         C   s.   | |  _  x |  i D] } | i | ƒ q Wd  S(   N(   R   R   t   set_compiler(   R   R   R+   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR@   ž   s    	
 (   t   __name__t
   __module__R   R   R   R   R'   R,   R3   R5   R7   R?   R@   (    (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR    
   s   					.				*	t   ext_functionc           B   s   e  Z d d d  d d „ Z RS(   i   c   
      C   s   t  i ƒ  i } | d  j o | i } n | d  j o | i } n | d  j o t i } n t | | | | | ƒ }	 t	 i
 |  | | |	 ƒ d  S(   N(   t   syst	   _getframet   f_backt   Nonet   f_localst	   f_globalst
   converterst   defaultt   assign_variable_typesR    R   (
   R   R   R   R=   t
   local_dictt   global_dictt   auto_downcastt   type_converterst
   call_frameR   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR   ¥   s    N(   RA   RB   RG   R   (    (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyRC   ¤   s   t
   ext_modulec           B   s¶   e  Z d  d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z d  d d „ Z d „  Z d „  Z d d „ Z d d d d „ Z RS(   R   c         C   sI   t  i } | |  _ g  |  _ | |  _ t i ƒ  |  _ t i | ƒ |  _	 d  S(   N(
   RJ   t   standard_infoR   t	   functionsR   R   R	   R
   t	   info_listt   _build_information(   R   R   R   RS   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR   ·   s    				c         C   s   |  i  i | ƒ d  S(   N(   RT   R(   (   R   t   func(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   add_function¿   s    c      	   C   sO   d i  d |  i ƒ  |  i ƒ  |  i ƒ  |  i ƒ  |  i ƒ  |  i ƒ  d g ƒ } | S(   Ns   
s)   #ifdef __CPLUSPLUS__
extern "C" {
#endif
s   #ifdef __CPLUSCPLUS__
}
#endif
(   R   t   warning_codeR   t   support_codeR7   R?   t   module_init_code(   R   R   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   module_codeÁ   s    						c         C   s1   t  i ƒ  } x |  i D] } | | i 7} q W| S(   N(   R   R   RT   R   (   R   t   all_arg_specsRW   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR   Ö   s
    
 c         C   sl   |  i  |  i g |  i ƒ  i ƒ  } x! |  i D] } | i | i ƒ q- Wx | D] } | i |  i ƒ qN W| S(   N(   RV   R
   R   t   build_informationRT   R(   R@   R   (   R   t   infoRW   t   i(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR^   Ü   s    
  c         C   sD   |  i  ƒ  i ƒ  } d | j o! | i d ƒ | i d d ƒ n | S(   Ns   "blitz/array.h"i   (   R^   t   headerst   removet   insert(   R   t   all_headers(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   get_headersæ   s
    c         C   s9   |  i  ƒ  i ƒ  } t d „  | ƒ } d d i | ƒ d S(   Nc         S   s   d  |  S(   s   #pragma warning(%s)
(    (   R.   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR/   þ   s    s   #ifndef __GNUC__
R   s   
#endif(   R^   t   warningst   mapR   (   R   t   all_warningst   w(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyRY   ü   s    c         C   s/   |  i  ƒ  } t d „  | ƒ } d i | ƒ d S(   Nc         S   s   d  |  d S(   s	   #include s   
(    (   R.   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR/     s    R   s   
(   Re   Rg   R   (   R   t   h(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR     s    c         C   s#   |  i  ƒ  i ƒ  } d i | ƒ d S(   NR   s   
(   R^   RZ   R   (   R   R   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyRZ     s    c         C   s;   d } x! |  i  D] } | | i ƒ  7} q Wd i | ƒ d S(   NR   s   
(   RT   R7   R   (   R   t   all_function_codeRW   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR7   
  s
    
 c         C   sP   d } x! |  i  D] } | | i ƒ  7} q Wt d i | ƒ d ƒ } d } | | S(   NR   i   s\   static PyMethodDef compiled_methods[] = 
{
%s    {NULL,      NULL}        /* Sentinel */
};
(   RT   R?   R1   R   (   R   t   all_definition_codeRW   R   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR?     s    
 c         C   sG   |  i  ƒ  i ƒ  } t d i | ƒ d ƒ } d |  i | |  i f } | S(   NR   i   sT   PyMODINIT_FUNC init%s(void)
{
%s    (void) Py_InitModule("%s", compiled_methods);
}
(   R^   R[   R1   R   R   (   R   t   init_code_listt	   init_codeR   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR[     s
    t   .c         C   s@   |  i  ƒ  } | p |  i d } n t | | ƒ } t | | ƒ S(   Ns   .cpp(   R\   R   t   generate_file_namet   generate_module(   R   t	   file_namet   locationR   R   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   generate_file&  s
    c         C   sR   x! |  i  ƒ  D] } | i | ƒ q Wx |  i D] } | i | ƒ q. W| |  _ d  S(   N(   R^   R@   RT   R   (   R   R   R`   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR@   .  s     
 c   	      C   sG  |  i  ƒ  } |  i ƒ  } | i ƒ  } h  } x | D] } d  | | <q1 W| i ƒ  } | i d g  ƒ | i ƒ  | d <| i d g  ƒ | i ƒ  | d <| i d g  ƒ | i ƒ  | d <| i d g  ƒ | i	 ƒ  | d <| i d g  ƒ | i
 ƒ  | d <| i d g  ƒ | i ƒ  | d <| i d g  ƒ | | d <|  i d | ƒ } | | f S(	   Nt   define_macrost   include_dirst	   librariest   library_dirst   extra_compile_argst   extra_link_argst   sourcesRs   (   R   R^   R{   RG   t   keyst   getRu   Rv   Rw   Rx   Ry   Rz   Rt   (	   R   Rs   t   kwR   R_   t   _source_filest   source_filesR`   t   file(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   build_kw_and_file8  s(        c         K   s(   |  i  | | ƒ \ } } t i | |  S(   N(   R‚   t   build_toolst   create_extension(   R   Rs   R~   R   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   setup_extensionQ  s    i    c      	   K   sz   | d  j	 o | |  _ n |  i | | ƒ \ } } t i ƒ  } t i | d | d | d | | } | p t d ‚ n d  S(   Nt   temp_dirt   compiler_namet   verboses   Compilation failed(   RG   R   R‚   t   catalogt   intermediate_dirRƒ   t   build_extensiont   SystemError(   R   Rs   R   Rˆ   R~   R   t   tempt   success(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   compileU  s    	N(   RA   RB   R   RX   R\   R   R^   Re   RY   R   RZ   R7   R?   R[   Rt   R@   R‚   R…   RG   R   (    (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyRR   ¶   s"   				
							
	
	c         C   s%   t  i i | |  ƒ } t  i i | ƒ S(   N(   t   ost   pathR   t   abspath(   t   module_namet   module_locationt   module_file(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyRp   q  s    c         C   sŽ   d } t  i i | ƒ o@ t | d ƒ } | i ƒ  } | i ƒ  | |  j o
 d } qY n | o* t | d ƒ } | i |  ƒ | i ƒ  n | S(   sp    generate the source code file.  Only overwrite
        the existing file if the actual source has changed.
    i   t   ri    Ri   (   R   R‘   t   existst   opent   readt   closet   write(   t   module_stringR•   t   file_changedt   ft
   old_string(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyRq   u  s    
i   c         C   s,  h  } | i  | ƒ | i  | ƒ g  } h  } xÈ |  D]À } yj | | }	 d  }
 x5 | D]- } | i |	 ƒ o | i | |	 ƒ }
 PqS qS W|
 p
 t ‚ n | i |
 ƒ Wq3 t j
 o d d | d | | <q3 t j
 o d | d | | <q3 Xq3 W| o t t | ƒ ‚ n | o t	 | ƒ } n | S(   Ns*   The type and dimensionality specificationss   for variable 's   ' are missing.s   Unable to convert variable 's   ' to a C++ type.(
   t   updateRG   t
   type_matcht	   type_spect
   IndexErrorR(   t   KeyErrort	   TypeErrort   format_error_msgt   downcast(   t	   variablesRM   RN   RO   RP   t   incoming_varst   variable_specst   errorst   vart   example_typet   spect   factory(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyRL   †  s8     
 	
c         C   sÝ   g  } x2 |  D]* } t  | d ƒ o | i | i ƒ q q Wd | j p d | j o„ d | j p
 d | j oi xf |  D]Z } t  | d ƒ oD t | i t ƒ o d | _ qÑ t | i t ƒ o d | _ qÑ qw qw Wn |  S(   s#   Cast python scalars down to most common type of
         arrays used.

         Right now, focus on complex and float types. Ignore int types.
         Require all arrays to have same type before forcing downcasts.

         Note: var_specs are currently altered in place (horrors...!)
    t   numeric_typeRž   t   Ft   dt   D(   t   hasattrR(   R°   t
   issubclasst   complext   float(   t	   var_specst   numeric_typesR¬   (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR§   «  s    	  c         C   s=   d | } | |  i  d d | ƒ } t i d d | ƒ } | S(   Nt    s   
s    +$R   (   t   replacet   ret   sub(   t   stt   spacest	   indentiont   indented(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR1   Ç  s    
c         C   s>   d d  k  } d d  k } | i ƒ  } | i  |  | ƒ | i ƒ  S(   Niÿÿÿÿ(   t   pprintt	   cStringIOt   StringIOt   getvalue(   R«   RÂ   RÃ   t   msg(    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyR¦   Î  s    (   R   RD   R¼   R‰   Rƒ   RJ   R   t   objectR    RC   R   RR   Rp   Rq   RK   RL   R§   R1   R¦   (    (    (    sE   C:\graphics\Tools\Python26\Lib\site-packages\scipy\weave\ext_tools.pyt   <module>   s$   š»		#		