
    F\h)                         S r SSKrSSKrSSKJr  SSKJr  / SQr0 rSr	/ SQr
S rSS	 jrS
 rS r " S S5      rSS jr\\4S jrS rS r\S:X  a  \" 5         gg)zUtilities for comparing files and directories.

Classes:
    dircmp

Functions:
    cmp(f1, f2, shallow=True) -> int
    cmpfiles(a, b, common) -> ([], [], [])
    clear_cache()

    N)filterfalse)GenericAlias)clear_cachecmpdircmpcmpfilesDEFAULT_IGNORESi    )RCSCVStagsz.gitz.hgz.bzr_darcs__pycache__c                  ,    [         R                  5         g)zClear the filecmp cache.N)_cacheclear     /usr/lib/python3.13/filecmp.pyr   r      s    
LLNr   c                    [        [        R                  " U 5      5      n[        [        R                  " U5      5      nUS   [        R                  :w  d  US   [        R                  :w  a  gU(       a  X4:X  a  gUS   US   :w  a  g[        R                  XX445      nUc3  [        X5      n[        [        5      S:  a
  [        5         U[        XX44'   U$ )a  Compare two files.

Arguments:

f1 -- First file name

f2 -- Second file name

shallow -- treat files as identical if their stat signatures (type, size,
           mtime) are identical. Otherwise, files are considered different
           if their sizes or contents differ.  [default: True]

Return value:

True if the files are the same, False otherwise.

This function uses a cache for past comparisons and the results,
with cache entries invalidated if their stat information
changes.  The cache may be cleared by calling clear_cache().

r   FT   d   )	_sigosstatS_IFREGr   get_do_cmplenr   )f1f2shallows1s2outcomes         r   r   r      s    . 
bggbk	B	bggbk	B	!u1 528	!u1~jj"")*G"/v;M!(rr~Nr   c                 p    [         R                  " U R                  5      U R                  U R                  4$ N)r   S_IFMTst_modest_sizest_mtime)sts    r   r   r   F   s*    KK

#JJKK r   c                 B   [         n[        U S5       n[        US5       n UR                  U5      nUR                  U5      nXV:w  a   S S S 5        S S S 5        gU(       d   S S S 5        S S S 5        gMT  ! , (       d  f       O= fS S S 5        g ! , (       d  f       g = f)NrbTF)BUFSIZEopenread)r   r    bufsizefp1fp2b1b2s          r   r   r   K   so    G	b$3R#'"B'"Bx !/  !/ !/s4   B*A6
BA6#B4A66
B	 B
Bc                       \ rS rSrSrSSS.S jjrS rS rS	 rS
 r	S r
S rS rS rS r\" \
\	\	\	\\\\\\\\S9rS r\" \5      rSrg)r   X   a  A class that manages the comparison of 2 directories.

dircmp(a, b, ignore=None, hide=None, *, shallow=True)
  A and B are directories.
  IGNORE is a list of names to ignore,
    defaults to DEFAULT_IGNORES.
  HIDE is a list of names to hide,
    defaults to [os.curdir, os.pardir].
  SHALLOW specifies whether to just check the stat signature (do not read
    the files).
    defaults to True.

High level usage:
  x = dircmp(dir1, dir2)
  x.report() -> prints a report on the differences between dir1 and dir2
   or
  x.report_partial_closure() -> prints report on differences between dir1
        and dir2, and reports on common immediate subdirectories.
  x.report_full_closure() -> like report_partial_closure,
        but fully recursive.

Attributes:
 left_list, right_list: The files in dir1 and dir2,
    filtered by hide and ignore.
 common: a list of names in both dir1 and dir2.
 left_only, right_only: names only in dir1, dir2.
 common_dirs: subdirectories in both dir1 and dir2.
 common_files: files in both dir1 and dir2.
 common_funny: names in both dir1 and dir2 where the type differs between
    dir1 and dir2, or the name is not stat-able.
 same_files: list of identical files.
 diff_files: list of filenames which differ.
 funny_files: list of files which could not be compared.
 subdirs: a dictionary of dircmp instances (or MyDirCmp instances if this
   object is of type MyDirCmp, a subclass of dircmp), keyed by names
   in common_dirs.
 NTr!   c                    Xl         X l        Uc&  [        R                  [        R                  /U l        OX@l        Uc  [        U l        OX0l        XPl        g r&   )	leftrightr   curdirpardirhider	   ignorer!   )selfabr?   r>   r!   s         r   __init__dircmp.__init__   s@    	
<BII.DII>)DK Kr   c                    [        [        R                  " U R                  5      U R                  U R
                  -   5      U l        [        [        R                  " U R                  5      U R                  U R
                  -   5      U l        U R                  R                  5         U R                  R                  5         g r&   )
_filterr   listdirr:   r>   r?   	left_listr;   
right_listsortr@   s    r   phase0dircmp.phase0   sx     DII!6!%4;;!68!"**TZZ"8"&))DKK"79r   c           	         [        [        [        [        R                  R
                  U R                  5      U R                  5      5      n[        [        [        [        R                  R
                  U R                  5      U R                  5      5      n[        [        UR                  [        UR                  U5      5      5      U l        [        [        UR                  [        UR                  U5      5      5      U l        [        [        UR                  [        UR                  U5      5      5      U l        g r&   )dictzipmapr   pathnormcaserH   rI   list__getitem__filter__contains__commonr   	left_only
right_only)r@   rA   rB   s      r   phase1dircmp.phase1   s    S))4>>:DNNKLS))4??;T__MN3q}}fQ^^Q.GHIc!--Q^^Q1OPQs1==+anna2PQRr   c                    / U l         / U l        / U l        U R                   GH  n[        R
                  R                  U R                  U5      n[        R
                  R                  U R                  U5      nSn [        R                  " U5      n [        R                  " U5      nU(       a  [        R                  " WR                  5      n[        R                  " WR                  5      nXx:w  a  U R                  R                  U5        M  [        R                  " U5      (       a  U R                   R                  U5        GM*  [        R                   " U5      (       a  U R                  R                  U5        GMc  U R                  R                  U5        GM  U R                  R                  U5        GM     g ! [        [        4 a    Sn GNFf = f! [        [        4 a    Sn GNHf = f)NTF)common_dirscommon_filescommon_funnyrX   r   rR   joinr:   r;   r   OSError
ValueErrorr'   r(   appendS_ISDIRS_ISREG)	r@   xa_pathb_pathoka_statb_stata_typeb_types	            r   phase2dircmp.phase2   si   AWW\\$))Q/FWW\\$**a0FB
 V^^4V^^4#%%,,Q/\\&))$$++A.\\&))%%,,Q/%%,,Q/!!((+=  Z(  	 Z( s$   =GGGGG32G3c                     [        U R                  U R                  U R                  U R                  5      nUu  U l        U l        U l        g r&   )r   r:   r;   r_   r!   
same_files
diff_filesfunny_files)r@   xxs     r   phase3dircmp.phase3   s7    diiT->->M=?:$*:r   c           	      Z   0 U l         U R                   H  n[        R                  R	                  U R
                  U5      n[        R                  R	                  U R                  U5      nU R                  X#U R                  U R                  U R                  S9U R                   U'   M     g )Nr8   )subdirsr^   r   rR   ra   r:   r;   	__class__r?   r>   r!   )r@   rg   a_xb_xs       r   phase4dircmp.phase4   s|    
 !!A'',,tyy!,C'',,tzz1-C#~~cTYY6:ll  .  DDLLO "r   c                     U R                  5         U R                  R                  5        H  nUR                  5         M     g r&   )r}   ry   valuesphase4_closurer@   sds     r   r   dircmp.phase4_closure   s.    ,,%%'B (r   c                    [        SU R                  U R                  5        U R                  (       a<  U R                  R	                  5         [        SU R                  SU R                  5        U R
                  (       a<  U R
                  R	                  5         [        SU R                  SU R
                  5        U R                  (       a0  U R                  R	                  5         [        SU R                  5        U R                  (       a0  U R                  R	                  5         [        SU R                  5        U R                  (       a0  U R                  R	                  5         [        SU R                  5        U R                  (       a0  U R                  R	                  5         [        SU R                  5        U R                  (       a1  U R                  R	                  5         [        SU R                  5        g g )	NdiffzOnly in:zIdentical files :zDiffering files :zTrouble with common files :zCommon subdirectories :zCommon funny cases :)printr:   r;   rY   rJ   rZ   rr   rs   rt   r^   r`   rK   s    r   reportdircmp.report   sE   fdii,>>NN!)TYYT^^<??OO  ")TZZdoo>??OO  "%t7??OO  "%t7!!#/1A1AB!!#+T-=-=>""$($*;*;< r   c                     U R                  5         U R                  R                  5        H  n[        5         UR                  5         M     g r&   )r   ry   r   r   r   s     r   report_partial_closuredircmp.report_partial_closure   s0    ,,%%'BGIIK (r   c                     U R                  5         U R                  R                  5        H  n[        5         UR	                  5         M     g r&   )r   ry   r   r   report_full_closurer   s     r   r   dircmp.report_full_closure   s3    ,,%%'BG""$ (r   )ry   rr   rs   rt   r^   r_   r`   rX   rY   rZ   rH   rI   c                 v    XR                   ;  a  [        U5      eU R                   U   " U 5        [        X5      $ r&   )	methodmapAttributeErrorgetattr)r@   attrs     r   __getattr__dircmp.__getattr__   s3    ~~% &&tT"t""r   )rX   r^   r_   r`   rs   rt   r>   r?   r:   rH   rY   r;   rI   rZ   rr   r!   ry   )NN)__name__
__module____qualname____firstlineno____doc__rC   rL   r[   ro   rv   r}   r   r   r   r   rO   r   r   classmethodr   __class_getitem____static_attributes__r   r   r   r   r   X   s    $	L S#,J@
D 
=2% V &6v!'f6"f%&	:I# $L1r   r   c                     / / / 4nU H_  n[         R                  R                  X5      n[         R                  R                  X5      nU[        XgU5         R	                  U5        Ma     U$ )a=  Compare common files in two directories.

a, b -- directory names
common -- list of file names found in both directories
shallow -- if true, do comparison based solely on stat() information

Returns a tuple of three lists:
  files that compare equal
  files that are different
  filenames that aren't regular files.

)r   rR   ra   _cmprd   )rA   rB   rX   r!   resrg   axbxs           r   r   r   	  s^     r2,CWW\\!WW\\!D!"))!,  Jr   c                 X     U" U" XU5      5      (       + $ ! [         [        4 a     gf = f)N   )rb   rc   )rA   rB   shabsr   s        r   r   r   $  s2    s1}%%%Z  s    ))c                 @    [        [        UR                  U 5      5      $ r&   )rT   r   rW   )flistskips     r   rF   rF   -  s    D--u566r   c                  
   SS K n SS KnUR                  U R                  SS  S5      u  p#[        U5      S:w  a  UR	                  SS 5      e[        US   US   5      nSU;   a  UR                  5         g UR                  5         g )Nr   r   rr   zneed exactly two args)z-r )sysgetoptargvr   GetoptErrorr   r   r   )r   r   optionsargsdds        r   demor   3  st    MM#((12,4MG
4yA~  !8$??	Qa	!BW
 
		r   __main__)T)r   r   r   	itertoolsr   typesr   __all__r   r.   r	   r   r   r   r   r   r   r   r   rF   r   r   r   r   r   <module>r      s   
 
  ! 
I	
J&P
	n2 n2b6  7
 zF r   