� zfc@sldZddlmZddlZddlZddlZddlZddlZddlZddl Z e ej d�r�dZ ndZ ej dZej dZej d Zej d ZeefZejZejZd �ZiZd �ZiZd �Zdfd��YZdfd��YZd�Zedkrhy e�ZWnek rddGHnXndS(s3Find modules used by a script, using introspection.i����(t generatorsNtnewlinestUtrt LOAD_CONSTt IMPORT_NAMEt STORE_NAMEt STORE_GLOBALccs�d}t|�}d}x�||kr�t||�}|}|d}d}|tkr�t||�t||d�d|}d}|d}|tkr�|d}q�n|||fVqWdS(Niiiii(tlentordtNonet HAVE_ARGUMENTt EXTENDED_ARG(tcodet extended_argtntitoptoffsettarg((s$/usr/lib64/python2.7/modulefinder.pyt_unpack_opargss   *  cCs-tj|g�}|j|�|t| Noneisdetermine_parent ->t.srelative importpath too deep( R>R?R R!R#R1tAssertionErrortcountt ImportErrortjoinRLtrfind(R'RVR:tpnameRXR((s$/usr/lib64/python2.7/modulefinder.pyRR�sB             cCs/|jdd||�d|krL|jd�}|| }||d}n |}d}|rtd|j|f}n|}|j|||�}|r�|jdd||f�||fS|r |}d}|j|||�}|r |jdd||f�||fSn|jdd|�td |�dS( NiRSR\iRAs%s.%ssfind_head_package ->s"raise ImportError: No module namedsNo module named (R>tfindR!t import_moduleR?R R_(R'RXR(RtheadRZtqnameRY((s$/usr/lib64/python2.7/modulefinder.pyRS�s.    cCs�|jdd||�|}x�|r�|jd�}|dkrOt|�}n|| ||d}}d|j|f}|j|||�}|s|jdd|�td|�qqW|jdd |�|S( NiRTR\iis%s.%ss"raise ImportError: No module namedsNo module named s load_tail ->(R>RcRR!RdR?R_(R'RYRZR[RRetmname((s$/usr/lib64/python2.7/modulefinder.pyRT�s  cCs�|jdd|||�x�|D]�}|dkri|s�|j|�}|rf|j||d�qfq�q t||�s d|j|f}|j|||�}|s�td|�q�q q WdS(NiRUt*is%s.%ssNo module named (R=tfind_all_submodulesRUthasattrR!RdR_(R'R[RWt recursivetsubtalltsubnametsubmod((s$/usr/lib64/python2.7/modulefinder.pyRU�s  c Cs|js dSi}g}x%tj�D]}|j|d�q&Wx�|jD]�}ytj|�}Wn*tjk r�|jdd|�qKnXxp|D]h}d}x:|D]2} t | �} || | kr�|| }Pq�q�W|r�|dkr�|||simport_module -> None( R>R1tKeyErrorR?R2R R#t find_moduleR_RGtclosetsetattr(R'tpartnametfqnameRXR[RIRHRJ((s$/usr/lib64/python2.7/modulefinder.pyRds6  " c Csr|\}}}|jdd||o'd|�|tjkrf|j||�}|jdd|�|S|tjkr�t|j�d|d�} nr|tjkr|jd�tj �kr�|jdd|�t d |�n|jd�t j |�} nd} |j|�}||_| r[|jr?|j| �} n| |_|j| |�n|jdd|�|S( NiRGRIsload_module ->s texecis#raise ImportError: Bad magic numbersBad magic number in %s(R>REt PKG_DIRECTORYt load_packageR?RFtcompiletreadt PY_COMPILEDt get_magicR_tmarshaltloadR t add_moduleR"R6treplace_paths_in_codeR$t scan_code( R'R~RIRHt file_infotsuffixtmodettypeR[tco((s$/usr/lib64/python2.7/modulefinder.pyRG-s0    cCsQ||jkri|j|( R>RRR�R"R#RRzRGR?R{(R'R~RHRR[RItbufRJ((s$/usr/lib64/python2.7/modulefinder.pyR��s    cCs5||jkr|j|St|�|j|<}|S(N(R1R (R'R~R[((s$/usr/lib64/python2.7/modulefinder.pyR��s cCs�|dk r |jd|}n|}||jkrT|jdd|�t|�n|dkr�|tjkr�ddddtjffS|j }ntj ||�S(NR\isfind_module -> ExcludedRA( R R!R5R?R_R0tbuiltin_module_namesREt C_BUILTINRRz(R'R(RRXR�((s$/usr/lib64/python2.7/modulefinder.pyRz�s    cCs<HddGHddGH|jj�}|j�xE|D]=}|j|}|jrVdGndGd|G|jpndGHq3W|j�\}}|r�Hd GHxH|D]=}|j|j�}|j�d G|Gd Gd j|�GHq�Wn|r8Hd GdGHxH|D]=}|j|j�}|j�d G|Gd Gd j|�GHq�WndS(s�Print a report to stdout, listing the found modules with their paths, as well as modules that are missing, or seem to be missing. s %-25s %stNametFiles----tPR[s%-25sRAsMissing modules:t?s imported froms, s7Submodules that appear to be missing, but could also bes#global names in the parent package:N(R�R�(s----s----(R1RstsortR#R"tany_missing_maybeR2R`(R'RstkeyR[tmissingtmaybeR(tmods((s$/usr/lib64/python2.7/modulefinder.pytreport�s6        !  cCs|j�\}}||S(s�Return a list of modules that appear to be missing. Use any_missing_maybe() if you want to know which modules are certain to be missing, and which *may* be missing. (R�(R'R�R�((s$/usr/lib64/python2.7/modulefinder.pyt any_missingscCs"g}g}x�|jD]�}||jkr1qn|jd�}|dkr_|j|�qn||d}|| }|jj|�}|dk r�||j|kr�|j|�q||jkr�q|jr�|j|�q|j|�q|j|�qW|j �|j �||fS(s�Return two lists, one with modules that are certainly missing and one with modules that *may* be missing. The latter names could either be submodules *or* just global names in the package. The reason it can't always be determined is that it's impossible to tell which names are imported when "from module import *" is done with an extension module, short of actually importing it. R\iiN( R2R5RaRR1RR R%R&R�(R'R�R�R(RRntpkgnametpkg((s$/usr/lib64/python2.7/modulefinder.pyR�s0        cCs�tjj|j�}}x>|jD]3\}}|j|�r#||t|�}Pq#q#W|jr�||jkr�||kr�|j dd||f�n|j dd|f�|jj |�nt |j �}xMt t|��D]9}t||t|��r�|j||�||R?R@RPRQRRRSRTRURiRdRGR�R�tstructR�R�R�R�R�R�RzR�R�R�R�(((s$/usr/lib64/python2.7/modulefinder.pyR/^s4     #          6    %  .cCs"ddl}y#|jtjdd�\}}Wn|jk rM}|GHdSXd}d}g}g}x�|D]�\}} |dkr�|d}n|dkr�d}n|dkr�|| jtj�}n|dkr�d}n|d krm|j| �qmqmW|sd } n |d} tj} tjj | �| d<|| } |dkrxd GHx | D]} d Gt | �GHq\Wnt | ||�} xz|dD]n}|dkr�d}q�n|r�|d dkr�| j |d ddg�q| j |�q�| j|�q�W| j| �| j�| S(Ni����isdmp:qx:is-ds-ms-ps-qs-xshello.pyspath:s i����s.*Rh(tgetoptR0targvRrRLRKtpathsepRRtdirnameR9R/RQR RPR@R�(R�toptsR<R=R3tdomodstaddpathtexcludetotatscriptRtitemtmfR((s$/usr/lib64/python2.7/modulefinder.pyttesthsX #                 RBs [interrupt]( t__doc__t __future__RtdisRER�RKR0R�R�Rjt __stdout__RDtopmapRRRRR�R R RRRRRR R/R�R!R�tKeyboardInterrupt(((s$/usr/lib64/python2.7/modulefinder.pytsB                  �� ;