
    dgm*                        S SK Jr  S SKJrJr  S SKrS SKrS SKrS SKrS SK	r	S SK
r
S SKJr  S SKJr  S SKJr   " S S\5      r " S	 S
5      r " S S5      rg)    )annotations)AnycastN)debug)_)ChangelogEntryc                      \ rS rSrSrg)DbError)    N)__name__
__module____qualname____firstlineno____static_attributes__r       ;/usr/lib/python3/dist-packages/apt_listchanges/ALCSeenDb.pyr
   r
   )   s    r   r
   c                  d    \ rS rSrSrSS jrSS jrSS jr\S 5       r	SS jr
\SS j5       rS	rg
)DbStore-   
db_versionsimilarexactpackagesc                <    SU l         0 U l        0 U l        0 U l        g )N   r   selfs    r   __init__DbStore.__init__0   s     4624
(*r   c                   U R                   UR                   :w  a  [        S5      e[        5       n[        R                  " U R
                  5      Ul        [        R                  " U R                  5      Ul        [        R                  " U R                  5      Ul        UR
                  R                  5        H0  u  p4UR
                  R                  U0 5      R                  U5        M2     UR                  R                  5        H0  u  p4UR                  R                  U0 5      R                  U5        M2     UR                  R                  UR                  5        U$ Nz'Can only add DbStore to another DbStore)	__class__
ValueErrorr   copydeepcopyr   r   r   items
setdefaultupdate)r   otheraddedpath	checksumss        r   __add__DbStore.__add__6   s    >>U__,FGG	dll3mmDJJ/t}}5$}}224ODMM$$T2.55i@  5${{002ODKK""4,33I>  3enn-r   c                   U R                   UR                   :w  a  [        S5      eUR                  R                  5        H0  u  p#U R                  R	                  U0 5      R                  U5        M2     UR                  R                  5        H0  u  p#U R                  R	                  U0 5      R                  U5        M2     U R                  R                  UR                  5        U $ r#   )r$   r%   r   r(   r)   r*   r   r   )r   r+   r-   r.   s       r   __iadd__DbStore.__iadd__H   s    >>U__,FGG$}}224ODLL##D"-44Y?  5${{002ODJJ!!$+229=  3U^^,r   c                p    U R                   =(       d    U R                  =(       d    U R                  (       + $ N)r   r   r   r   s    r   emptyDbStore.emptyT   s!    LL?DJJ?$--@@r   c                   [        [        R                  " 5       S-
  5      nU R                  U R                  U5        [	        U R
                  R                  5       5       H9  u  p#U R                  X15        U R
                  U   (       a  M,  U R
                  U	 M;     [	        U R                  R                  5       5       H9  u  p#U R                  X15        U R                  U   (       a  M,  U R                  U	 M;     g )Ng     @)inttime_expire_dictr   listr   r(   r   )r   three_years_agor-   r.   s       r   
expire_oldDbStore.expire_oldX   s     diikJ67$--9#DLL$6$6$89ODi9<<%%LL&  :  $DJJ$4$4$67ODi9::d##JJt$  8r   c                \    [        U R                  5       5       H  nX   U:  d  M  X	 M     g r5   )r<   keys)dctcutoffkeys      r   r;   DbStore._expire_dictk   s(     
#Cx& H $r   )r   r   r   r   NreturnNone)r+   r   rG   r   )rB   zdict[Any, int]rC   r9   rG   rH   )r   r   r   r   	__slots__r    r/   r2   propertyr6   r>   staticmethodr;   r   r   r   r   r   r   -   sE    >I+$
 A A%&  r   r   c                      \ rS rSrSr SSS jjrSS jrSSS jjr S   SS jjr S   SS jjr	SS	 jr
SS
 jrSS jr\SSS jj5       rSS jrSSS jjrSS jr\SS j5       rSS jrSrg) SeenDbs   )r-   _changes_dNc                    Xl         [        5       U l        U(       d  [        5       U l        gU R	                  5       U l        g)zInitialize seen DB, possibly from disk
If path is None or does not exist on disk then an empty DB is
initialized. Otherwise content is loaded from disk.N)r-   r   rO   rP   read_database)r   r-   s     r   r    SeenDb.__init__{   s1     		iDG$$&r   c                2   U R                   (       d   e [        U R                   S5      n [	        [        [
        R                  " U5      5      n[        U[        5      (       a3  [        SU R                    S35        [        5       UR                  5         $ UUR                  5         $ ! [         a    [        5       s $ f = f! [         a3  n[        [        S5      U R                   [        U5      S.-  5      UeS nAff = f! UR                  5         f = f)Nrbz	Database z  has obsolete format, discardingz*Database %(db)s failed to load: %(errmsg)s)dberrmsg)r-   openFileNotFoundErrorr   r   pickleload
isinstancedictr   close	Exceptionr
   r   str)r   frV   exs       r   rR   SeenDb.read_database   s    yyy	TYY%A	gv{{1~.B"d## 	$)),LMNy GGI 
 GGI% ! 	9	  	J!HI#'99B@A BGIJ	J GGIs;   B* AC C *C C
D.C<<DD Dc                    U(       a  U R                   R                  OU R                   R                  nU R                  X5      nXCR	                  UR
                  0 5      ;   $ )z3True if the entry has been seen in this path before)rP   r   r   	_checksumgetr-   r   entryr   indexchecksums        r   	seen_hereSeenDb.seen_here   sA    !&DGGOO>>%/99UZZ444r   c                   ^^ U(       a  U R                   R                  OU R                   R                  nU R                  TU5      m[	        UU4S jUR                  5        5       5      $ )z:True if the entry has been seen in a different path beforec              3  V   >#    U  H  u  pUTR                   :w  d  M  TU;   v   M      g 7fr5   )r-   ).0r-   r.   rj   rh   s      r   	<genexpr>(SeenDb.seen_elsewhere.<locals>.<genexpr>   s-      **7tejj( )8y(*7s   ))rP   r   r   re   anyr(   rg   s    `  @r   seen_elsewhereSeenDb.seen_elsewhere   sN     "'DGGOO>>%/ **/++-* * 	*r   c                   ^ U(       a  U R                   R                  OU R                   R                  nU R                  X5      m[	        U4S jUR                  5        5       5      $ )z2True if the entry has been seen in any path beforec              3  2   >#    U  H  u  pTU;   v   M     g 7fr5   r   )ro   r-   r.   rj   s      r   rp   'SeenDb.seen_anywhere.<locals>.<genexpr>   s      9*7t y(*7s   rr   rg   s       @r   seen_anywhereSeenDb.seen_anywhere   sL     "'DGGOO>>%/ 9*/++-9 9 	9r   c                2    XR                   R                  ;   $ )z2True if the specified package has been seen before)rP   r   )r   packages     r   has_packageSeenDb.has_package   s    ''****r   c                    XR                   R                  ;   a  g[        [        R                  " 5       5      nX R                   R                  U'   X R                  R                  U'   g)z>Add the specified package to the database if not already thereN)rP   r   r9   r:   rO   )r   r|   nows      r   add_packageSeenDb.add_package   sI    gg&&&$))+$'!*-w'r   c                z   U R                  U5      (       a  g[        [        R                  " 5       5      nU R                  UR                  5        U R                  U5      nX R                  R                  R                  UR                  0 5      U'   X R                  R                  R                  UR                  0 5      U'   U R                  US5      nX R                  R                  R                  UR                  0 5      U'   X R                  R                  R                  UR                  0 5      U'   g)z<Add the specified entry to the database if not already thereNF)rk   r9   r:   r   r|   re   rP   r   r)   r-   rO   r   )r   rh   r   rj   s       r   add
SeenDb.add   s    >>%  $))+'>>%(=@  R0:CF&&uzz26x@>>%/?B""5::r28<EH((R8Br   c                    U(       a  [        U 5      OU R                  U R                  -   n[        R                  " UR                  5       R                  5       5      R                  5       $ r5   )r`   contenttrailerhashlibmd5stripencodedigest)rh   r   r   s      r   re   SeenDb._checksum   sC     %#e*EMMEMM,I{{7==?1134;;==r   c                8    U R                   R                  5         g r5   )rP   r>   r   s    r   _expire_oldSeenDb._expire_old   s    r   c                    [        X(       a  SOS5       nU R                  U R                  -   nUR                  5         [        R
                  " XC5        SSS5        g! , (       d  f       g= f)z|Save database to specified path rather than default location
Raises an exception if file already exists unless force is TruewbxbN)rX   rP   rO   r>   rZ   dump)r   r-   forcera   rV   s        r   save_asSeenDb.save_as   sG     $40A4==(BMMOKK 100s   A A
A,c                
   U R                   (       d  g U R                  R                  (       a  g U R                    S3nU R                    S3n[        R                   R	                  U R                   5      n[        U R                   S5       nUR                  S5        [        R                  " UR                  5       [        R                  S5        U(       a  U R                  5       U l        O[        5       U l        U =R                  U R                  -  sl        [        5       U l        U R                  5         [        US5       n[        R                  " U R                  U5        S S S 5         [        R                   " U5        [        R$                  " U R                   U5        [        R&                  " X R                   5        S S S 5        g ! , (       d  f       No= f! ["         a     Ngf = f! , (       d  f       g = f)Nz-oldz-newabr   r   )r-   rO   r6   osexistsrX   seeklockffilenoF_LOCKrR   rP   r   r   rZ   r   unlinkrY   linkrename)r   oldnamenewname	reread_dblockablera   s         r   apply_changesSeenDb.apply_changes   sQ   yy==YYKt$YYKt$GGNN499-	$))T"hMM!HHX__&		15,,.!)GGt}}$G#IDMgt$DGGQ' %		'" GGDIIw'IIgyy)% #" %$ %  #"sJ   B<G4"G*G43G$	AG4
G!	G4$
G1.G40G11G44
Hc                    [        U[        5      (       a  SR                  S U 5       5      nU  U SU S[        R                  R	                  U5      R                  S5       S3$ )N c              3  0   #    U  H  oS S S3 v   M     g7f)0r   xNr   )ro   cs     r   rp   $SeenDb._dump_line.<locals>.<genexpr>  s     5A!AvY<s    z (z%F))r\   bytesjoindatetimefromtimestampstrftime)prefixrD   stamps      r   
_dump_lineSeenDb._dump_line   sg    c5!!''556C(3%q (%%33E:CCDIJ!M 	Nr   c           	        [        S5        [        U R                  R                  R	                  5       5       H   u  p[        U R                  SX5      5        M"     [        S5        [        U R                  R                  R	                  5       5       HQ  u  p4[        SU S35        [        UR	                  5       5       H   u  pR[        U R                  SXR5      5        M"     MS     [        S5        [        U R                  R                  R	                  5       5       HQ  u  p4[        SU S35        [        UR	                  5       5       H   u  pR[        U R                  SXR5      5        M"     MS     g )Nz	packages:z  zexact checksums::z    zsimilar checksums:)printsortedrP   r   r(   r   r   r   )r   r|   r   r-   r.   rj   s         r   r   SeenDb.dump  s   k$TWW%5%5%;%;%=>NG$//$78 ? 	 !%dggmm&9&9&;<ODBtfA,#))//*;#<doofh>? $=  =
 	"#%dggoo&;&;&=>ODBtfA,#))//*;#<doofh>? $=  ?r   )rO   rP   r-   r5   )r-   z
str | NonerG   rH   )rG   r   )T)rh   r   r   boolrG   r   )r|   r`   rG   r   )r|   r`   rG   rH   )rh   r   rG   rH   )rh   r   r   r   rG   r   rF   )F)r-   r`   r   r   rG   rH   )r   r`   rD   zstr | bytesr   r9   rG   r`   )r   r   r   r   rI   r    rR   rk   rt   ry   r}   r   r   rK   re   r   r   r   r   r   r   r   r   r   rM   rM   s   s    *I
	'25 &**"*.2* %)9!9-19+.I" > >*: N N@r   rM   )
__future__r   typingr   r   r&   r   r   r   rZ   r:   apt_listchanges.ALCLogr   apt_listchanges.ALChacksr   apt_listchanges.DebianFilesr   r_   r
   r   rM   r   r   r   <module>r      sO   4 #     	   ( & 6	i 	C CLc@ c@r   