۶eTc@sdZddlZddlZddlZddlZddlZddlmZddl Z ddl Z ddlZddl m Z ddl mZddlmZddlmZeagadZd efd YZdd Zd Zedkr endS(s Provides some import hooks to allow Cheetah's .tmpl files to be imported directly like Python .py modules. To use these: import Cheetah.ImportHooks Cheetah.ImportHooks.install() iN(tRLock(t ImportManager(tDirOwner(tCompiler(tconvertTmplPathToModuleNamecCstj|dS(N(t _cacheDirtappend(tcacheDir((sB/opt/freeware/lib64/python2.7/site-packages/Cheetah/ImportHooks.pyt setCacheDir!stCheetahDirOwnercBs;eZeZejZejZdZdZ dZ RS(s.tmplcCs|jztj||}|r)|Sx|jD]}tjj|j||}tjj|r3y|j||SWqt j }ddj|j }t dt qXq3q3WdSWd|jXdS(Ns s sVError while compiling Cheetah module %(name)s, original traceback follows: %(exc_txt)s(t _acquireLockRtgetmodttemplateFileExtensionstostpathtjointexistst_compilet tracebackt format_exct splitlinest ImportErrortlocalstNonet _releaseLock(tselftnametmodtextttmplPathtexc_txt((sB/opt/freeware/lib64/python2.7/site-packages/Cheetah/ImportHooks.pyR /s$  cCsttd|d|d|}trtjjtdt|d}yt|dj|Wqt k rt j dt j |}qXn|}t|d|d}tj|}|j|_tr||_n||_|S( Ntfilet moduleNamet mainClassNameis.pytws texec(tstrRRR RRRtopentwritetOSErrorRt print_exctsyststderrtcompilettypest ModuleTypet co_filenamet__file__t __orig_file__t__co__(RRRtcodeR/tcoR((sB/opt/freeware/lib64/python2.7/site-packages/Cheetah/ImportHooks.pyRHs$      (s.tmpl( t__name__t __module__Rt_locktacquireR treleaseRR R R(((sB/opt/freeware/lib64/python2.7/site-packages/Cheetah/ImportHooks.pyR (s     s.tmplcCsvtsr|t_ddl}t|jtjrr|jat j j dtt j a t j t jqrndS(s Install the Cheetah Import HooksiNi(t _installedR R t __builtin__t isinstancet __import__R,tBuiltinFunctionTypet __oldimport__Rt_globalOwnerTypestinsertt_managert setThreadedtinstall(R R:((sB/opt/freeware/lib64/python2.7/site-packages/Cheetah/ImportHooks.pyRCes     cCs=ts9ddl}t|jtjr9t|_bq9ndS(s"Uninstall the Cheetah Import HooksiN(R9R:R;R<R,t MethodTypeR>RA(R:((sB/opt/freeware/lib64/python2.7/site-packages/Cheetah/ImportHooks.pyt uninstallvs   t__main__(s.tmpl(t__doc__R)tos.pathR R,R:timpt threadingRtstringRtCheetahRtCheetah.ImportManagerRtCheetah.CompilerRt#Cheetah.convertTmplPathToModuleNameRtFalseR9RRR RCRER4(((sB/opt/freeware/lib64/python2.7/site-packages/Cheetah/ImportHooks.pyt s*         =