nfc@s{dZddlZddlZddlmZyddlmZWn!ek reddlmZnXddgZdefdYZ d efd YZ dddddd Z dddddd Z d ZdZdZedZddedZdZdZdddZedkrweejdkrYejdIJqwejd=eejdndS(sZrunpy.py - locating and running Python code using the module namespace Provides support for locating and running Python scripts using the Python module namespace instead of the native filesystem. This allows Python code to play nicely with non-filesystem based PEP 302 importers when locating support scripts as well as when importing modules. iN(t read_code(t get_loadert run_moduletrun_patht _TempModulecBs)eZdZdZdZdZRS(sCTemporarily replace a module in sys.modules with an empty namespacecCs(||_tj||_g|_dS(N(tmod_nametimpt new_moduletmodulet _saved_module(tselfR((s/usr/lib64/python2.7/runpy.pyt__init__s cCsL|j}y|jjtj|Wntk r7nX|jtj|<|S(N(RR tappendtsystmodulestKeyErrorR(R R((s/usr/lib64/python2.7/runpy.pyt __enter__s  cGs=|jr#|jdtj|js cCsZt|B}t|-|jj}t|||||||WdQXWdQX|jS(s5Helper to run code in new namespace with sys modifiedN(RRRt__dict__R(tcopy(R"R$RR%R&R't temp_modulet mod_globals((s/usr/lib64/python2.7/runpy.pyt_run_module_codeKs    cCs=x6dD].}t||d}|dk r||SqWdS(Nt get_filenamet _get_filename(s get_filenames _get_filename(tgetattrR (tloaderRtattrtmeth((s/usr/lib64/python2.7/runpy.pyR/\s   cCst|}|dkr+td|n|j|r|dksU|jdrdtdny|d}t|SWqtk r}tdd||fqXn|j|}|dkrtd|nt||}||||fS(NsNo module named %st__main__s .__main__s%Cannot use package as __main__ modules%s; %r is a package and cannot sbe directly executedsNo code object available for %s(RR t ImportErrort is_packagetendswitht_get_module_detailstget_codeR/(RR1t pkg_main_nameteR"tfilename((s/usr/lib64/python2.7/runpy.pyR8ds"    cCscd}yt|SWnHtk r^}|t|krXtd|tjdfnnXdS(NR4scan't find %r module in %ri(R8R5tstrR tpath(t main_nametexc((s/usr/lib64/python2.7/runpy.pyt_get_main_module_detailsxsc CsyF|s|dkr0t|\}}}}nt\}}}}Wn9tk r}dtjt|f}tj|nX|jdd}tjdj }|r|tj diR4Nt(R RTt isinstanceRROR\R-R R>tinsertRRARRRR)R(R*tremovet ValueError( RPR$RKRRR"R?t saved_mainRR1RGR'R+R,((s/usr/lib64/python2.7/runpy.pyRs0         & R4is!No module specified for executioni(RR RtpkgutilRRR5t__all__RRRR R(R-R/R8RAtTrueRJtFalseRRTR\RRtlenRtstderr(((s/usr/lib64/python2.7/runpy.pyts<           1