Ñò PhEc@sdZddkTddklZddkZddkiZddkiZddk Z ddk Z ddk Z ddk Z e ed„dddgƒƒZe ed „d gƒƒZhd d 6Zheid 6eid6eid6eid6Zddd„ƒYZdS(s£ Middle tier between a Lexer and an ObjectGenerator. receives parse events from Lexer and constructs a parse tree, then calls an ObjectGenerator to generate an object file from the parse tree. the parse tree structure is language-neutral and contains no python code. Compiler is currently stateful and is not thread-safe. the clone() method can be used to create copies of this object for use in multiple threads. iÿÿÿÿ(t*(t exceptionNcCs |tgS((tTrue(tx((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyt stoncetsharedt threadoncecCs |tgS((R(R((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR#stinheritt python_blocktpythontrequestt subrequesttdynamict componenttCompilerc BsbeZdZdd3d„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZd efd „ƒYZd efd „ƒYZd efd„ƒYZ defd„ƒYZ defd„ƒYZ dd4d„ƒYZ eƒZ eƒZeƒZeƒZeƒZe ƒZe ƒZe ƒZd5d5d5d5d5geged„ Zd„Zd„Zd„Zdd6d„ƒYZd5d„Zd5d„Zd„Zd„Z 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+„Z-d,„Z.d-„Z/eed.„Z0d/„Z1d0„Z2d1„Z3d2„Z4RS(7itBlockFlyweightcBs;eZdZd„Zd„Zd„Zd„Zd„ZRS(sûan object that represents a construct in the original source file. maintains a reference to a list of source file items and uses a context to act upon the list entry in question, so that very few objects need to be created cCsdS(N((tself((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyt__init__=scCs |idS(Ni(tentry(Rtcontext((s3/usr/lib/python2.6/site-packages/myghty/compiler.pytget_line?scCs |idS(Ni(R(RR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pytget_line_numberBscCs|i|||gƒdS(N(tappend(Rtlisttlinet linenumber((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyREscCs t‚dS(N(tNotImplementedError(RtvisitorR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pytaccept_visitorHs(t__name__t __module__t__doc__RRRRR(((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR8s     t CodeBlockcBs eZdZd„Zd„ZRS(srepresents a <%python> sectioncCs#|id}tid|ƒ}|S(Nis\n(Rtretsplit(RRtblocktlines((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyt get_linesLs cCs|i||ƒdS(N(tvisit_code_block(RRR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyRQs(RRR R&R(((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR!Js t SubstitutioncBs)eZdZd„Zd„Zd„ZRS(srepresents a <% %> line cCs|i||ƒdS(N(tvisit_substitution(RRR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyRVscCs|i||||gƒdS(N(R(RRRtescapeR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyRYscCs |idS(Ni(R(RR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyt get_escapes\s(RRR RRR+(((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR(Ts  tTextLinecBseZdZd„ZRS(s represents a line of plain textcCs|i||ƒdS(N(tvisit_text_line(RRR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyRas(RRR R(((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR,_stCodeSingleLinecBseZdZd„ZRS(s represents a % line cCs|i||ƒdS(N(tvisit_code_single_line(RRR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyRfs(RRR R(((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR.dst ComponentCallcBs2eZdZd„Zd„Zd„Zd„ZRS(s2 represents a component call without content <& &>cCs|i||||gƒdS(N(R(RRRtargsR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyRkscCs |idS(Ni(R(RR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyt get_componentnscCs |idS(Ni(R(RR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pytget_argsqscCs|i||ƒdS(N(tvisit_component_call(RRR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyRts(RRR RR2R3R(((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR0is    tComponentContentCallcBseZdZd„ZRS(s0 represents a component call with content <&| &>cCs|i||ƒdS(N(tvisit_component_content_call(RRR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyRys(RRR R(((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR5wstComponentContentCallEndcBseZdZd„ZRS(s6 represents a component call with content end tag cCs|i||ƒdS(N(t visit_component_content_call_end(RRR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR~s(RRR R(((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR7|stClosurecBs#eZd„Zd„Zd„ZRS(cCs|i|||gƒdS(N(R(RRtcompiledR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR‚scCs |idS(Ni(R(RR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyt get_compiled…scCs|i||ƒdS(N(tvisit_closure_block(RRR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyRˆs(RRRR;R(((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR9s  tBlockFlyweightIteratorcBs)eZdZd„Zd„Zd„ZRS(s¦an iterator that loops through an array of BlockFlyweight references and their associated data, and acts as the context to send to their get() methodscCs||_d|_d|_dS(Niÿÿÿÿ(RtindextNoneR(RR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyRs  cCs|S(N((R((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyt__iter__”scCsS|id7_|it|iƒjo tƒ‚n|i|i|_|idS(Nii(R>tlenRt StopIterationR(R((s3/usr/lib/python2.6/site-packages/myghty/compiler.pytnext—s  (RRR RR@RC(((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR=‹s  c Ksžd|_|o ||_ntii| |_|o ||_ntiƒ|_||_||_ ||_ ||_ ||_ ||_ t| ƒ|_dS(N(R?tcurrent_compiletlexertmyghtytLexert generatortobjgentPythonGeneratortdefault_escape_flagstpython_pre_processortpython_post_processorttext_post_processortuse_source_line_numberst allow_globalstbooltdisable_unicode( RRLRMRNRERHRKRORPRRtparams((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR§s         cCs&d|iiƒdt|iƒƒfS(s9identification string placed at the top of compiled filess%s|%s|%ssMyghty.Compiler(REt get_object_idtreprtget_magic_number(R((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyRTÆscCstih|id6fS(NRR(Rt MAGIC_NUMBERRR(R((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyRVÌscKs?|iiƒ|d<|iiƒ|dscCst|i|ƒdjS(Ni(RARm(RRf((s3/usr/lib/python2.6/site-packages/myghty/compiler.pytblock_has_codeAscCs|i|ƒ}ti|ƒS(N(RƒRR=(RRfR$((s3/usr/lib/python2.6/site-packages/myghty/compiler.pytget_block_iteratorDscCsR|idj o|ii|tƒn(|io|iidƒn ||_dS(Ns!multiple file encoding specifiers(RdR?t set_encodingtignore_if_already_setRoRERu(RRo((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR†Hs    cCs%|idj o|iiƒS|iS(N(RdR?t get_encodingRo(R((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyRˆQscCs |iƒS(N(t _to_string(R((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyt__str__Vstc Csêg}|idj o|id|iƒn|idƒx9|iiƒD](}|i|dt|i|ƒƒqKW|idƒx±dD]©}|i|ƒ}|djo|id |ƒn|id ƒti|ƒ}x$|D]}|i|i |ƒƒqåW|djo|id |ƒq‹|id ƒq‹Wx—|i i ƒD]†\}} xw|i i ƒD]f\}} |d} |i| d||fƒ|i| i | dƒƒ|i| d||fƒqdWqHW|ti|d|ƒS(sbdumps out the structure attempting to recreate the original source file, more or less.s# -*- encoding: %s -*-s<%args>s = sRR_RR`R]s<%%%s>s# body code begins s# body code end s s <%%%s %s>s s N(soncesinitssharedsbodyscleanup(RoR?RR1tkeysRURƒRR=RRlt iteritemst def_blocksR‰tstringtjoin( RtindentRtargtkeyR$titertcodet blocknameRmR|tind((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR‰Ys< &       #N(RRR RR?RRRyR}R~RRR‚RƒR„R…R†RˆRŠR‰(((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyRZÛs ,        cCs–tid|d|ddƒ|_|ioAy|i|ƒ}Wqltj o}ti|iƒ‚qlXn|ii||||ƒ|i |ƒdS(sÞcompiles a source file. source - a string representing the source of the file name - a name to give to the compiled object file - a file object that the compiled output will be streamed to.RcRgRht top_levelN( RRZRDRLt ExceptionRR1REtlextcompiled_component(RtsourceRhtfilet input_filete((s3/usr/lib/python2.6/site-packages/myghty/compiler.pytcompile„s! cCs¡|i}ti|ƒo#|i o|iid|ƒn|ii|ƒo|iiƒ|i| tag s:Cannot define a %s section inside a method or subcomponents"Cannot nest a %s inside a %s blockN( RDttop_level_only_blockRtReRERuRnt line_numberRjtc(RRft attributesR ((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyt start_blockšs  !cCsG|i}|i|jo!|iid||ifƒnd|_dS(s+called by Lexer to indicate a tags'End of %s encountered while in %s blockN(RDRjRERuR?(RRfR ((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyt end_block«s !cKs/tii|iidƒ||iiƒƒdS(NR`(RttextlineRRDRƒRER¢(RR$RS((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyt text_blockµscKsdS(N((RRS((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyt doc_blockºscKs|ii|ƒdS(s,A magic -*- encoding: foo -*- style comment.N(RDR†(RRoRS((s3/usr/lib/python2.6/site-packages/myghty/compiler.pytmagic_encoding_comment¼scCsQ|io?y|i|ƒSWqMtj o}ti|iƒ‚qMXn|SdS(N(RNR™RRR1(RR•RŸ((s3/usr/lib/python2.6/site-packages/myghty/compiler.pytpost_process_textÁs  cCsQ|io?y|i|ƒSWqMtj o}ti|iƒ‚qMXn|SdS(N(RMR™RRR1(RR•RŸ((s3/usr/lib/python2.6/site-packages/myghty/compiler.pytpost_process_pythonËs  cKsmti|dƒo"t|d}t||ƒ|Stii|ii|dƒ|d|ii ƒƒdS(NRfR$( tBLOCKSRttgetattrRt codeblockRRDRƒRER¢(RRSR\((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyt raw_blockÔscCsK|djo|iid|ƒn|ii|||iiƒ|ƒdS(sZInserts a variable declaration from the C<< <%args> >> section into the component.R1s-Variable Declaration called inside a %s blockN(RERuRDRyR¢(RRfRhRsRx((s3/usr/lib/python2.6/site-packages/myghty/compiler.pytvariable_declarationás cCsÂy—h|iid6|iid6|}|i|ƒo|iid||fƒn|||<|djo*|djo|iit|hƒƒnWn$tj ot i d|ƒnXdS(NRaRbs%s %s already definedRos'key_value_pair called inside a %s block( RDRaRbRtRERuR†tevalRwRR(RRfR“R|tdict((s3/usr/lib/python2.6/site-packages/myghty/compiler.pytkey_value_pairës$ !cCs,tii|iiƒ||iiƒƒdS(N(RtcodesinglelineRRDR‚RER¢(RR((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyt python_lineþscKs,tii|iiƒ||iiƒƒdS(N(RR¯RRDR‚RER¢(RR$RS((s3/usr/lib/python2.6/site-packages/myghty/compiler.pyR sc Csõ|pt|iƒo©tƒ}|o1tid|ƒ}x|D]}d||s   0!