ó 2ÄÈ[c@`s`dZddlmZmZmZddgZddlZddlZddlZddl m Z iZ dZ d„Z d „Zejd ƒZejd ƒZd „Zejd ƒZejdƒZejdƒZejdƒZd„ZejdƒZd„Zd„ZejdejƒZd„Zd„Zd„Zd„Z e!dkr\e ƒndS(sX 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 i(tdivisiontabsolute_importtprint_functiont process_strt process_fileN(t get_exceptionsE /* ***************************************************************************** ** This file was autogenerated from a template DO NOT EDIT!!!! ** ** Changes should be made to the original source (.src) file ** ***************************************************************************** */ c C`s*|dkrd}d}nd|}d|}d}d}g}xØtr|j||ƒ}|dkrlPn|jd|ƒ}|jd|ƒ}|j||ƒ} |jd| ƒ} ||jd||d ƒ7}|j||d | | d |fƒ||jd|d | ƒ7}| }qDW|jƒ|S( s‡ The returned line number is from the beginning of the string, starting at zero. Returns an empty list if no loops found. is/**begin repeats/**end repeat**/s/**begin repeat%ds/**end repeat%d**/iÿÿÿÿs*/s i(tTruetfindtcounttappendtsort( tastrtleveltloopbegtloopendtindtlinetspanlisttstarttstart2tfini1tfini2((s</tmp/pip-build-fiC0ax/numpy/numpy/distutils/conv_template.pytparse_structureks,      $  cC`s8|jdƒ}|jdƒ}dj|gt|ƒƒS(Niit,(tgrouptjointint(tobjttoreptnumrep((s</tmp/pip-build-fiC0ax/numpy/numpy/distutils/conv_template.pyt paren_repl‹ss[(]([^)]*)[)]\*(\d+)s([^*]+)\*(\d+)cC`s\tjt|ƒ}djg|jdƒD]}tjt|jƒƒ^q(ƒ}|jdƒS(NR(tparenreptsubRRtsplittplainreptstrip(R tx((s</tmp/pip-build-fiC0ax/numpy/numpy/distutils/conv_template.pyt parse_values’s 4s\n\s*\*?s#\s*(\w*)\s*=([^#]*)#s (\w*)=(\w*)s :exclude:cC`s¦tjd|ƒ}g}tj|ƒ}d}x|D]…}|d}t|dƒ}t|ƒ}|dkru|}n1||kr¦d}t|||||fƒ‚n|j||fƒq4Wg} xlt j |ƒD][} | j ƒ} |j d| dƒ} || d| !} t j| ƒ}| jt|ƒƒqÓWg}|dkrStdƒ‚nxLt|ƒD]>}i}x"|D]\}}||||[\w\d./\\]+[.]src)['\"]cC`sãtjj|ƒ}t|ƒ}g}x®|D]¦}tj|ƒ}|rÄ|jdƒ}tjj|ƒstjj||ƒ}ntjj |ƒr´t d|ƒ|j t |ƒƒqÑ|j |ƒq+|j |ƒq+W|jƒ|S(NR8sIncluding file(tostpathtdirnametopentinclude_src_reRERtisabsRtisfiletprintRLtresolve_includesR tclose(tsourcetdtfidtlinesRtmtfn((s</tmp/pip-build-fiC0ax/numpy/numpy/distutils/conv_template.pyRes     cC`s„t|ƒ}tjj|ƒjddƒ}ytdj|ƒƒ}Wn0tk rutƒ}td||fƒ‚nXd||fS(Ns\s\\R&sIn "%s" loop at %ss#line 1 "%s" %s( ReR]R^tnormcaseRHRRR,R(RgRjt sourcefileRNRW((s</tmp/pip-build-fiC0ax/numpy/numpy/distutils/conv_template.pyR"s   cC`stt|jƒƒ}t}d}xO|sodjg|D]}|| ^q4ƒ}||krf|d7}q!t}q!W|S(NiR&(tlisttkeystFalseRR(tadicttallkeystdonetnR$tnewkey((s</tmp/pip-build-fiC0ax/numpy/numpy/distutils/conv_template.pyt unique_key-s &   c C`sÓytjd}Wn#tk r6tj}tj}n=Xt|dƒ}tjj|ƒ\}}|}t|dƒ}|j ƒ}yt |ƒ}Wn0t k rÁt ƒ}t d||fƒ‚nX|j |ƒdS(NitrtwsIn %s loop at %s(tsystargvt IndexErrortstdintstdoutR`R]R^tsplitexttreadRR,Rtwrite( tfileRitoutfiletbasetexttnewnametallstrtwritestrRW((s</tmp/pip-build-fiC0ax/numpy/numpy/distutils/conv_template.pytmain>s       t__main__("t__doc__t __future__RRRt__all__R]Rztretnumpy.distutils.compatRR\R[RRtcompileRR"R%R'R(R0R-RCRIRKRtIRaReRRwR‰t__name__(((s</tmp/pip-build-fiC0ax/numpy/numpy/distutils/conv_template.pytPs:        6 ,