HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/numpy/distutils/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/numpy/distutils/__pycache__/from_template.cpython-36.pyc
3

���h�@s�dZddgZddlZddlZddlZejdej�Zejdej�Zejdej�Z	dd	�Z
ejd
�Zejd�Zejd�Z
d
d�Zdd�Zejd�Zdd�Zdd�Zejd�Zdd�Zdd�Zejdej�Zdd�Zdd�Zed�Zdd �Zed!kr�e�dS)"a�

process_file(filename)

  takes templated file .xxx.src and produces .xxx file where .xxx
  is .pyf .f90 or .f using the following template rules:

  '<..>' denotes a template.

  All function and subroutine blocks in a source file with names that
  contain '<..>' will be replicated according to the rules in '<..>'.

  The number of comma-separated words in '<..>' will determine the number of
  replicates.

  '<..>' may have two different forms, named and short. For example,

  named:
   <p=d,s,z,c> where anywhere inside a block '<p>' will be replaced with
   'd', 's', 'z', and 'c' for each replicate of the block.

   <_c>  is already defined: <_c=s,d,c,z>
   <_t>  is already defined: <_t=real,double precision,complex,double complex>

  short:
   <s,d,c,z>, a short form of the named, useful when no <p> appears inside
   a block.

  In general, '<..>' contains a comma separated list of arbitrary
  expressions. If these expression must contain a comma|leftarrow|rightarrow,
  then prepend the comma|leftarrow|rightarrow with a backslash.

  If an expression matches '\<index>' then it will be replaced
  by <index>-th expression.

  Note that all '<..>' forms in a block must have the same number of
  comma-separated entries.

 Predefined named template rules:
  <prefix=s,d,c,z>
  <ftype=real,double precision,complex,double complex>
  <ftypereal=real,double precision,\0,\1>
  <ctype=float,double,complex_float,complex_double>
  <ctypereal=float,double,\0,\1>

�process_str�process_file�Nz2(\n|\A)((     (\$|\*))|)\s*(subroutine|function)\bz+\n\s*end\s*(subroutine|function)\b.*(\n|\Z)z\n     (\$|\*)\s*function\bcCs�g}d}x�tj||�}|dkr P|j�}tj|||j��rrx6|jd||�}|dkrTP|}|||d�dkr<Pq<W|d7}tj||j��}|r�|j�dp�t|�}}|j	||f�q
W|S)z� Return a list of tuples for each function or subroutine each
    tuple is the start and end of a subroutine or function to be
    expanded.
    rN�
��z
     $���)
�routine_start_re�search�start�function_start_re�match�end�rfind�routine_end_re�len�append)�astrZspanlist�ind�mr
�ir
�r�>/tmp/pip-build-5_djhm0z/numpy/numpy/distutils/from_template.py�parse_structure:s(rz<\s*(\w[\w\d]*)\s*>z<\s*(\w[\w\d]*)\s*=\s*(.*?)\s*>z<\s*((.*?))\s*>cCsTtj|�}i}x@|D]8}|dj�p*t|�}|djdd�}t|�}|||<qW|S)Nrrz\,z@comma@)�named_re�findall�strip�
unique_key�replace�conv)rZreps�names�rep�name�repl�thelistrrr�find_repl_patternsYs

r$cCs"t|�}tjtd|�d}||fS)N�r)r$�re�subnr)rrrrr�find_and_remove_repl_patternscsr(z\A\\(?P<index>\d+)\ZcCsd|jd�}dd�|D�}x@tt|��D]0}tj||�}|r&t|jd��}||||<q&Wdj|�S)N�,cSsg|]}|j��qSr)r)�.0�xrrr�
<listcomp>kszconv.<locals>.<listcomp>�index)�split�ranger�item_rer�int�group�join)r�b�lrr�jrrrris
rcCs@t|j��}d}d}x&|s:d|}||kr4|d7}qd}qW|S)z( Obtain a unique key given a dictionary.Frz__l%sT)�list�keys)�adictZallkeys�done�nZnewkeyrrrrss
rz\A\s*(\w[\w\d]*)\s*\Zcsv|jdd�}|jdd�}t|��tjd|�}�fdd�}tj||�}d}d}i�x�tj|�D]�}|�kr\�j||j|d��}|dkr�td|��||kr�|j	d	�r�|||<d
d�|j
d�D�}t|�}|dkr�|}|�|<|}q\||kr�|�|<q\td
|dj
�|�||f�q\W��s |S��fdd�}	d}
x&t|�D]�|
tj|	|�d7}
�q<W|
jdd�}
|
jdd�}
|
S)Nz\>z@rightarrow@z\<z@leftarrow@z<\1>csnt|jd�jdd��}tj|�r(d|Sd}x �j�D]}�||kr6|}q6W|dkrft��}|�|<d|S)Nrz\,z@comma@z<%s>)rr2r�template_name_rerr8r)�mobjr#r!�key)�lnamesrr�listrepl�s
zexpand_sub.<locals>.listreplzNo replicates found for <%s>�_cSsg|]}|jdd��qS)z@comma@r))r)r*rrrrr,�szexpand_sub.<locals>.<listcomp>r)zHMismatch in number of replacements (base <%s=%s>) for <%s=%s>. Ignoring.cs$|jd�}�j|�d|g��S)Nr)r2�get)r=r!)�k�rulesrr�namerepl�s
zexpand_sub.<locals>.namereplr%z

�>�<)rr$r�sub�list_re�template_rerrB�
ValueError�
startswithr.r�printr3r/)�substrrr@ZnumsubsZ	base_rule�rr#Zrule�numrE�newstrr)rCr?rDr�
expand_sub�sF

rRc	Cs�|}d}t|�}d}i}|jt�x\|D]T}t|||d��\}}||7}|j|�|t||d|d�|�7}|d}q(W|||d�7}|S)Nr%rr)r�update�_special_namesr(rR)	�allstrrQ�writestr�structZoldendrrHZ
cleanedstrZdefsrrrr�s


z9(\n|\A)\s*include\s*['\"](?P<name>[\w\d./\\]+[.]src)['\"]cCs�tjj|�}t|���}g}xz|D]r}tj|�}|r�|jd�}tjj|�sVtjj||�}tjj	|�r|t
d|�|jt|��q�|j
|�q |j
|�q WWdQRX|S)Nr!zIncluding file)�os�path�dirname�open�include_src_rerr2�isabsr3�isfilerM�extend�resolve_includesr)�source�d�fid�lines�liner�fnrrrr`�s




r`cCst|�}tdj|��S)Nr%)r`rr3)rardrrrr�sz�
<_c=s,d,c,z>
<_t=real,double precision,complex,double complex>
<prefix=s,d,c,z>
<ftype=real,double precision,complex,double complex>
<ctype=float,double,complex_float,complex_double>
<ftypereal=real,double precision,\0,\1>
<ctypereal=float,double,\0,\1>
cCsvytjd}Wn tk
r.tj}tj}Yn*Xt|d�}tjj|�\}}|}t|d�}|j	�}t
|�}|j|�dS)NrrO�w)�sys�argv�
IndexError�stdin�stdoutr[rXrY�splitext�readr�write)�filerc�outfile�base�extZnewnamerUrVrrr�main�s

rt�__main__)�__doc__�__all__rXrhr&�compile�IrrrrrJrrIr$r(r0rrr<rRrr\r`rrTrt�__name__rrrr�<module>/s6






<