U ã€C^&ã@sdZddlmZmZmZddgZddlZddlZddlZddl m Z iZ dZ dd „Z d d „Ze d ¡Ze d ¡Zdd„Ze d¡Ze d¡Ze d¡Ze d¡Zdd„Ze d¡Zdd„Zdd„Ze dej¡Zdd„Zdd„Zdd„Zd d!„Z e!d"krþe ƒdS)#aX takes templated file .xxx.src and produces .xxx file where .xxx is .i or .c or .h, using the following template rules /**begin repeat -- on a line by itself marks the start of a repeated code segment /**end repeat**/ -- on a line by itself marks it's end After the /**begin repeat and before the */, all the named templates are placed these should all have the same number of replacements Repeat blocks can be nested, with each nested block labeled with its depth, i.e. /**begin repeat1 *.... */ /**end repeat1**/ When using nested loops, you can optionally exclude particular combinations of the variables using (inside the comment portion of the inner loop): :exclude: var1=value1, var2=value2, ... This will exclude the pattern where var1 is value1 and var2 is value2 when the result is being generated. In the main body each replace will use one entry from the list of named replacements Note that all #..# forms in a block must have the same number of comma-separated entries. Example: An input file containing /**begin repeat * #a = 1,2,3# * #b = 1,2,3# */ /**begin repeat1 * #c = ted, jim# */ @a@, @b@, @c@ /**end repeat1**/ /**end repeat**/ produces line 1 "template.c.src" /* ********************************************************************* ** This file was autogenerated from a template DO NOT EDIT!!** ** Changes should be made to the original source (.src) file ** ********************************************************************* */ #line 9 1, 1, ted #line 9 1, 1, jim #line 9 2, 2, ted #line 9 2, 2, jim #line 9 3, 3, ted #line 9 3, 3, jim é)ÚdivisionÚabsolute_importÚprint_functionÚ process_strÚ process_fileN)Ú get_exceptionaE /* ***************************************************************************** ** This file was autogenerated from a template DO NOT EDIT!!!! ** ** Changes should be made to the original source (.src) file ** ***************************************************************************** */ c CsÎ|dkrd}d}nd|}d|}d}d}g}| ||¡}|dkrDqÂ| d|¡}| d|¡}| ||¡} | d| ¡} || d||d ¡7}| ||d | | d |f¡|| d|d | ¡7}| }q.| ¡|S) z‡ The returned line number is from the beginning of the string, starting at zero. Returns an empty list if no loops found. rz/**begin repeatz/**end repeat**/z/**begin repeat%dz/**end repeat%d**/éÿÿÿÿz*/Ú é)ÚfindÚcountÚappendÚsort) ÚastrÚlevelZloopbegZloopendÚindÚlineZspanlistÚstartZstart2Zfini1Zfini2©rú@/tmp/pip-install-6_kvzl1k/numpy/numpy/distutils/conv_template.pyÚparse_structureks*     rcCs(| d¡}| d¡}d |gt|ƒ¡S)Nr éú,)ÚgroupÚjoinÚint)ÚobjZtorepZnumreprrrÚ paren_repl‹s  rz[(]([^)]*)[)]\*(\d+)z([^*]+)\*(\d+)cCs0t t|¡}d dd„| d¡Dƒ¡}| d¡S)NrcSsg|]}t t| ¡¡‘qSr)ÚplainrepÚsubrÚstrip©Ú.0ÚxrrrÚ ™sÿz parse_values..)ÚparenreprrrÚsplit)rrrrÚ parse_values’s   ÿr'z\n\s*\*?z#\s*(\w*)\s*=([^#]*)#z (\w*)=(\w*)z :exclude:cst d|¡}g}t |¡}d}|D]\}|d}t|dƒ}t|ƒ}|dkrP|}n ||krpd}t|||||fƒ‚| ||f¡q"g} t  |¡D]D} |   ¡} |  d| d¡} || d| …} t  | ¡}|  t |ƒ¡qŽg}|dkrètdƒ‚t|ƒD] ‰‡fdd „|Dƒ}| |¡qð|S) a˜Find all named replacements in the header Returns a list of dictionaries, one for each loop iteration, where each key is a name to be substituted and the corresponding value is the replacement string. Also return a list of exclusions. The exclusions are dictionaries of key value pairs. There can be more than one exclusion. [{'var1':'value1', 'var2', 'value2'[,...]}, ...] ÚNrr z.Mismatch in number of values, %d != %d %s = %sr zNo substitution variables foundcsi|]\}}||ˆ“qSrr)r"ÚnameÚvals©ÚirrÚ Òsz%parse_loop_header..)ÚstripastrÚnamed_reÚfindallr'ÚlenÚ ValueErrorr Ú exclude_reÚfinditerÚspanr Úexclude_vars_reÚdictÚrange)ZloopheadÚnamesZrepsÚnsubÚrepr)r*ÚsizeÚmsgZexcludesrr5ÚendlineÚsubstrZex_namesZdlistÚtmprr+rÚparse_loop_header¢s8      rAz @([\w]+)@c sNdˆ}‡‡fdd„}|g}t||ƒ}|�r(d}|d} |D]Ê} ||| d…} || d| d…} || d| d…} | d}ˆ| d}| t || ¡¡z t| ƒ}Wn.tk rØtƒ}d ||f}t|ƒ‚YnX|D]&}| ˆ¡t| || |ƒ}|  |¡qÞq<||d…}| t ||¡¡n| t ||¡¡| d ¡d   |¡S) Nz #line %d csD| d¡}z ˆ|}Wn(tk r>dˆ|f}t|ƒ‚YnX|S)Nr z"line %d: no definition of key "%s")rÚKeyErrorr2)Úmatchr)Úvalr=©ÚenvrrrÚreplaceÛs   zparse_string..replacerr rééz line %d: %sr r() rr Ú replace_rerrAr2rÚupdateÚ parse_stringÚextendr)rrFrrÚlinenorGÚcodeÚstructZoldendÚnewlevelrZprefÚheadÚtextÚnewlineZenvlistÚer=ZnewenvZnewcodeÚsuffrrErrL×s:        rLcCs$tg}| t|tddƒ¡d |¡S)Nrr r()ÚheaderrMrLÚ global_namesr)rrOrrrrsz7(\n|\A)#include\s*['\"](?P[\w\d./\\]+[.]src)['\"]c Cs tj |¡}t|ƒ�‚}g}|D]r}t |¡}|r†| d¡}tj |¡sTtj ||¡}tj  |¡rzt d|ƒ|  t |ƒ¡q�|  |¡q|  |¡qW5QRX|S)Nr)zIncluding file)ÚosÚpathÚdirnameÚopenÚinclude_src_rerCrÚisabsrÚisfileÚprintrMÚresolve_includesr )ÚsourceÚdÚfidÚlinesrÚmÚfnrrrra s        racCsft|ƒ}tj |¡ dd¡}ztd |¡ƒ}Wn*tk rXtƒ}td||fƒ‚YnXd||fS)Nú\z\\r(zIn "%s" loop at %sz#line 1 "%s" %s) rarYrZÚnormcaserGrrr2r)rbreZ sourcefilerOrUrrrrscsLt| ¡ƒ}d}d‰|sHd ‡fdd„|Dƒ¡}||krBˆd7‰qd}q|S)NFr r(csg|]}|dˆ…‘qS)Nrr!©Únrrr$3szunique_key..T)ÚlistÚkeysr)ÚadictZallkeysÚdoneZnewkeyrrjrÚ unique_key*s  rpc Cs¦ztjd}Wn tk r.tj}tj}Yn*Xt|dƒ}tj |¡\}}|}t|dƒ}|  ¡}z t |ƒ}Wn*t k r–t ƒ}t d||fƒ‚YnX|  |¡dS)Nr ÚrÚwzIn %s loop at %s)ÚsysÚargvÚ IndexErrorÚstdinÚstdoutr\rYrZÚsplitextÚreadrr2rÚwrite) ÚfilerdÚoutfileÚbaseÚextZnewnameZallstrÚwritestrrUrrrÚmain;s     r€Ú__main__)"Ú__doc__Ú __future__rrrÚ__all__rYrsÚreZnumpy.distutils.compatrrXrWrrÚcompiler%rr'r.r/r6r3rArJrLrÚIr]rarrpr€Ú__name__rrrrÚs>O ÿ        4 ,ÿ