3
/*^%                 @   s   d dl mZ d dlZd dlZd dlZd dlZdZdefd  ZdZd dlm	Z	 d dl
mZmZ d dlmZ d	d
 Zdd Zedkre  dS )    )print_functionN
uncompyle6a  
Usage:
  %s [OPTIONS]... [ FILE | DIR]...
  %s [--help | -h | --V | --version]

Examples:
  %s      foo.pyc bar.pyc       # decompile foo.pyc, bar.pyc to stdout
  %s -o . foo.pyc bar.pyc       # decompile to ./foo.pyc_dis and ./bar.pyc_dis
  %s -o /tmp /usr/lib/python1.5 # decompile whole library

Options:
  -o <path>     output decompiled files to this path:
                if multiple input files are decompiled, the common prefix
                is stripped from these names and the remainder appended to
                <path>
                  uncompyle6 -o /tmp bla/fasel.pyc bla/foo.pyc
                    -> /tmp/fasel.pyc_dis, /tmp/foo.pyc_dis
                  uncompyle6 -o /tmp bla/fasel.pyc bar/foo.pyc
                    -> /tmp/bla/fasel.pyc_dis, /tmp/bar/foo.pyc_dis
                  uncompyle6 -o /tmp /usr/lib/python1.5
                    -> /tmp/smtplib.pyc_dis ... /tmp/lib-tk/FixTk.pyc_dis
  --compile | -c <python-file>
                attempts a decompilation after compiling <python-file>
  -d            print timestamps
  -p <integer>  use <integer> number of processes
  -r            recurse directories looking for .pyc and .pyo files
  --fragments   use fragments deparser
  --verify      compare generated source with input byte-code
  --verify-run  compile generated source, run it and check exit code
  --syntax-verify compile generated source
  --linemaps    generated line number correspondencies between byte-code
                and generated source output
  --encoding  <encoding>
                use <encoding> in generated source according to pep-0263
  --help        show this message

Debugging Options:
  --asm     | -a        include byte-code       (disables --verify)
  --grammar | -g        show matching grammar
  --tree={before|after}
  -t {before|after}     include syntax before (or after) tree transformation
                        (disables --verify)
  --tree++ | -T         add template rules to --tree=before when possible

Extensions of generated files:
  '.pyc_dis' '.pyo_dis'   successfully decompiled (and verified if --verify)
    + '_unverified'       successfully decompile but --verify failed
    + '_failed'           decompile failed (contact author for enhancement)
   )verify)main
status_msg)VERSIONc               C   s   t t tjd d S )N   )print__doc__sysexit r   r   U/home/psgendb/BIRCHDEV/python/lib/python3.6/site-packages/uncompyle6/bin/uncompile.pyusageD   s    r   c           *      sv  t jdd dTkr.td
t t jd t jdU d } }d}dd g }d}d}y&tjt jdd  ddjd\}}W nT tj	k
 r } z4tdt
jjt jd |f t jd t jdV W Y d d }~X nX i x|D ]\}	}
|	dWkr tt t jd  q|	dXkr(tdttf  t jd  q|	dkr>dd<  q|	dkrTdd<  q|	dkrjdd<  q|	d krd!d<  q|	d"krdd#<  q|	dYkrd&d'< d d<  q|	dZkrd*kri d*< |
d+krdd* |
< n$|
d&kr dd* |
< ndd* d+< d d< n|	d[krHd*kr2i d*< dd* d.< d d< n|	d\kr\dd1< n|	d2krl|
nr|	d]kr|d}nb|	d^kr|j|
 nL|	d7krt|
}n8|	d_krd}n(|	d:kr|
d;< nt|	t jd t   qW |rhg }xt|D ]l}t
jj|rxVt
j|D ]H\}}}x:|D ]2}|jd<s>|jd=r"|jt
jj|| q"W qW qW |}t
jj|		d`d  t
jkrt
jj			rtt
jj	d>fd?d@|D }| r| rtdAt jd t  dkrd n:rt
jjrd nr,t|dkr,d |r@ttj| |dkryVt	||f}t|jdd g }t|dkrt| f| }tdB|  W n. t k
r   Y n t!j"k
r    Y nX nddCl#m$m%} yddDl%m&  W n" t'k
r   ddDl(m&  Y nX |t|| x|D ]}j)| q.W xt*|D ]}j)d  qLW || 	fdEdFyfdGd@t*|D }x|D ]}|j+  qW x|D ]}|j  qW yJda\}}}}x8jd\}}}}||7 }||7 }||7 }||7 }qW W n  k
r*   Y nX tdH||||f  W n t t,fk
r\   Y nX |rrttj| d S )bNr               r	      r      z!Error: %s requires Python 2.6-3.8)fileF-z# %Y.%m.%d %H:%M:%S %Zzhac:gtTdrVo:p:zhelp asm compile= grammar linemaps recurse timestamp tree= tree+ fragments verify verify-run version syntax-verify showgrammar encoding= z%s: %s-h--help-V	--versionz%s %sz--verifyZstrong	do_verifyz--syntax-verifyZweakz--fragmentsTZdo_fragmentsz--verify-runz
verify-runz
--linemapsZdo_linemaps--asm-aafterZshowasm--tree-tZshowastbefore--tree+-TZFull	--grammar-gZshowgrammarz-o--timestamp-d	--compile-cz-p	--recurse-rz
--encodingZsource_encodingz.pycz.pyo c                s   g | ]}| d  qS )Nr   ).0f)sb_lenr   r   
<listcomp>   s    zmain_bin.<locals>.<listcomp>z!No input files given to decompilez# )ProcessQueue)Emptyc                 s   yfd\} }}}xTj  }|d kr"P t|gd f\}}}}| |7 } ||7 }||7 }||7 }qW W n  tfk
r~   Y nX j| |||f j  d S )Nr   )r   r   r   r   )getr   KeyboardInterruptputclose)	tot_files
okay_filesfailed_filesverify_failed_filesr1   tov)r6   fqueueoptionsout_baseoutfilerqueuesrc_baser   r   process_func   s    zmain_bin.<locals>.process_funcc                s   g | ]} d qS ))targetr   )r0   i)r4   rH   r   r   r3      s    z;# decompiled %i files: %i okay, %i failed, %i verify failedr   r   r   r   r   r   r   r	   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   )r   r   )r   r   )r   r    )r"   r#   )r%   r&   )r'   r(   )r)   r*   )r+   r,   )r-   r.   rV   )r   r   r   r   )-r   version_infor
   programstderrr   getoptargvsplitGetoptErrorospathbasenamer   r   appendintr   isdirwalkendswithjoincommonprefixsepdirnamelentimestrftimer   listr7   r   r8   r   ZVerifyCmpErrormultiprocessingr4   r5   r6   ImportErrorqueuer9   rangestartOSError)r   Zrecurse_dirsZnumprocZsource_paths	timestampZtimestampfmtoptsZ	pyc_pathseoptvalZexpanded_filesr1   root_Z	dir_filesdfresultmessr5   rJ   Zprocspr;   r<   r=   r>   r?   r@   rA   r   )
r6   r4   rB   rC   rD   rE   rH   rF   r2   rG   r   main_binI   s(     

$



























&
  



r   __main__)
__future__r   r   r^   rZ   rk   rX   r   r   r   Zuncompyle6.mainr   r   Zuncompyle6.versionr   r   r   __name__r   r   r   r   <module>   s    2 @