
    8.g                        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rS SKrS SK	r	S SK
JrJrJr  S SKJrJrJrJrJr  S SKrSSKJr  SSKJrJr  \" S5      r/ SQrS	\S
\S\4S jrS\\   S\\   4S jr  " S S\!5      r" " S S\!5      r# " S S\!\\   5      r$S\S\4S jr%S+S jr& " S S5      r' " S S5      r( " S S5      r)\\)\'4   r*\\)\'\(4   r+ " S S5      r, " S  S!5      r- " S" S#5      r.\/S$:X  a  \R`                  " 5         \-" 5       r1\1 H&  r2\Rf                  " S%\2R9                  5       -  5        M(     \" S&S'5      r4\Rf                  " S(\4-  5        \Rf                  " \" S)S'5      5        \Rf                  " \" S&S*5      5        gg),    N)CallableIterableIterator)AnyGenericOptionalTypeVarUnion   )_deb822)DistInfoTemplateT)	is_mirrorDeb822SourceEntrySourceEntryNullMatcherSourcesListSourceEntryMatcher
master_uricompare_urireturnc                    UR                  S5      nU R                  S5      n X:X  a  g UR                  S5      S   nU R                  S5      S   nSU;   a  X"R                  S5      S-   S U:X  a  gg! [         a     gf = f)zcheck if the given add_url is idential or a mirror of orig_uri e.g.:
master_uri = archive.ubuntu.com
compare_uri = de.archive.ubuntu.com
-> True
z/ Tz//r   F.N)rstripsplit
IndexErrorindex)r   r   compare_srv
master_srvs       8/usr/lib/python3/dist-packages/aptsources/sourceslist.pyr   r   ;   s     $$T*K""4(J !''-a0%%d+A.
 kk*;*;C*@1*D*FG:U  s   (A4 4
B Bsc                 *    [        [        U 5      5      $ )a  simple and efficient way to return uniq collection

This is not intended for use with a SourceList. It is provided
for internal use only. It does not have a leading underscore to
not break any old code that uses it; but it should not be used
in new code (and is not listed in __all__).)listset)r"   s    r!   uniqr&   X   s     A<    c                   p    \ rS rSrS\S\4S jr SS\S   S\S-  S	\S-  4S
 jjrSSS\S-  S	S4S jr	Sr
g)SingleValuePropertyb   keydocc                     Xl         X l        g Nr+   __doc__selfr+   r,   s      r!   __init__SingleValueProperty.__init__c       r'   Nobjr   objtyper   c                 X    Uc  U $ UR                   R                  U R                  S 5      $ r.   )sectiongetr+   r2   r6   r7   s      r!   __get__SingleValueProperty.__get__g   s'     ;K{{txx..r'   valuec                 j    Uc  UR                   U R                  	 g X!R                   U R                  '   g r.   )r9   r+   r2   r6   r>   s      r!   __set__SingleValueProperty.__set__n   s'    =DHH%$)KK!r'   r0   r+   r.   )__name__
__module____qualname____firstlineno__strr3   r   typer<   rA   __static_attributes__ r'   r!   r)   r)   b   sf    C c 
 JN//0/;?$;/	t/*. *sTz *d *r'   r)   c                   p    \ rS rSrS\S\4S jr SS\S   S\S-  S	\\   4S
 jjr	SSS\\   S	S4S jr
Srg)MultiValuePropertyu   r+   r,   c                     Xl         X l        g r.   r/   r1   s      r!   r3   MultiValueProperty.__init__v   r5   r'   Nr6   r   r7   r   c                 ~    Uc  U $ [         R                  UR                  R                  U R                  S5      5      $ )N )r   mysplitr9   r:   r+   r;   s      r!   r<   MultiValueProperty.__get__z   s2     ;K""3;;??488R#@AAr'   valuesc                 T    SR                  U5      UR                  U R                  '   g )N )joinr9   r+   )r2   r6   rU   s      r!   rA   MultiValueProperty.__set__   s     # 0DHHr'   rC   r.   )rD   rE   rF   rG   rH   r3   r   rI   r$   r<   rA   rJ   rK   r'   r!   rM   rM   u   sj    C c 
 JNB/0B;?$;B	cB1. 1S	 1d 1r'   rM   c                   `    \ rS rSrS\4S jr SS\S   S\S-  S\4S	 jjrSSS
\SS4S jr	Sr
g)ExplodedEntryProperty   parentc                     Xl         g r.   r]   r2   r]   s     r!   r3   ExplodedEntryProperty.__init__   s    r'   Nr6   ExplodedDeb822SourceEntryr7   r   c                 V    Uc  U $ U R                   R                  UR                   5      $ r.   )r]   r<   r;   s      r!   r<   ExplodedEntryProperty.__get__   s'     ;K{{""3::..r'   r>   c                 p    UR                  5         U R                  R                  UR                  U5        g r.   )	split_outr]   rA   r@   s      r!   rA   ExplodedEntryProperty.__set__   s#    CJJ.r'   r_   r.   )rD   rE   rF   rG   r   r3   r   rI   r<   rA   rJ   rK   r'   r!   r[   r[      sW    q  RV/78/CG$;/	
//6 /q /T /r'   r[   propc                     U $ r.   rK   )rh   s    r!   DeprecatedPropertyrj      s    Kr'   c                      g)z3Behaves like an expired weakref.ref, returning NoneNrK   rK   r'   r!   _null_weakrefrl      s    r'   c                   z   \ rS rSr S'S\R
                  \-  S-  S\S\S   4S jjrS\	S	\	4S
 jr
\" SS5      r\" SS5      r\" \" SS5      5      r\" SS5      r\" \" SS5      5      r\" SS5      r\" \" SS5      5      r\" SS5      r\S	\4S j5       r\R0                  S\S	S4S j5       r\S	\S-  4S j5       r\R0                  S\S-  S	S4S j5       r\S	\4S j5       r\R0                  S\S	S4S j5       r\S	\4S j5       r\S	\4S j5       rS	\4S jrS	\4S  jrS!\S	S4S" jrSS#S	\4S$ jr S(S% jr!S&r"g))r      Nr9   filer$   r   c                    Uc  [         R                  " S5      U l        O7[        U[        5      (       a  [         R                  " U5      U l        OXl        [	        U R                  5      U l        X l        S U l        SU l        [        R                  S   " 5       U l        U(       a  [        R                  " U5      U l        g [        U l        g )NrR   Frb   )r   Sectionr9   
isinstancerH   _linero   template	may_mergeweakrefWeakSet	_childrenref_listrl   )r2   r9   ro   r$   s       r!   r3   Deb822SourceEntry.__init__   s     ?"??2.DL%%"??73DL"L&
	)- )DEG;B;;t;LDJ&DJr'   otherr   c                    U R                   UR                   :H  =(       a    U R                  UR                  :H  =(       a    U R                  =(       aw    U R                  R                  S5      UR                  R                  S5      :H  =(       a9    U R                  UR                  :H  =(       a    U R
                  UR
                  :H  $ z+equal operator for two sources.list entries/disabledrI   urir   distcompsr2   r|   s     r!   __eq__Deb822SourceEntry.__eq__   s     MMU^^+ *		UZZ'** $		(8(8(==* 		UZZ'	*
 

ekk)	
r'   ArchitectureszThe list of architecturesTypeszThe list of typesURIszURIs in the sourceSuiteszSuites in the source
ComponentszComponents in the sourcec                 .    U R                   R                  $ )1Legacy attribute describing the paragraph header.r9   headerr2   s    r!   commentDeb822SourceEntry.comment   s     ||"""r'   r   c                 $    XR                   l        g)r   Nr   )r2   r   s     r!   r   r      s     &r'   c                 j     [         R                  " U R                  S   5      $ ! [         a     gf = f)z%Return the value of the Trusted fieldTrustedN)apt_pkgstring_to_boolr9   KeyErrorr   s    r!   trustedDeb822SourceEntry.trusted   s3    	))$,,y*ABB 		s   "% 
22r>   c                 x    Uc   U R                   S	 g U(       a  SOSU R                   S'   g ! [         a     g f = f)Nr   yesnor9   r   r2   r>   s     r!   r   r      s@    =LL+ 05e$DLL#  s   , 
99c                 l    [         R                  " U R                  R                  SS5      5      (       + $ )zCheck if Enabled: no is set.Enabledr   )r   r   r9   r:   r   s    r!   r   Deb822SourceEntry.disabled   s)     ))$,,*:*:9e*LMMMr'   c                 n    U(       a  SU R                   S'   g  U R                   S	 g ! [         a     g f = f)Nr   r   r   r   s     r!   r   r      s6    &*DLL#LL+ s   ' 
44c                 $    U R                   (       + $ )z7A section is invalid if it doesn't have proper entries.)r9   r   s    r!   invalidDeb822SourceEntry.invalid   s     <<r'   c                     U R                   $ )z The entire (original) paragraph.)rs   r   s    r!   lineDeb822SourceEntry.line   s     zzr'   c                 >    U R                  5       R                  5       $ r.   rH   stripr   s    r!   __str__Deb822SourceEntry.__str__  s    xxz!!r'   c                 ,    [        U R                  5      $ )z(Section as a string, newline terminated.)rH   r9   r   s    r!   rH   Deb822SourceEntry.str  s    4<<  r'   enabledc                     U(       + U l         g)z.Deprecated (for deb822) accessor for .disabledNr   r2   r   s     r!   set_enabledDeb822SourceEntry.set_enabled      #r'   AnySourceEntryc           
         U R                   (       d/  U R                  c"  [        S U R                   5       5      (       d  gU R                  UR                  :w  a  g[        U[        5      (       d  gU R                  UR                  :w  a.  [        S U R                  UR                  4 5       5      (       d  g[        [        U R                  R                  5      [        UR                  R                  5      -   5       HX  nUR                  5       S;   a  M  U R                  R                  US5      nUR                  R                  US5      nX4:w  d  MX    g   [        [        U R                   5      [        UR                   5      :g  [        U R"                  5      [        UR"                  5      :g  [        U R$                  5      [        UR$                  5      :g  [        U R&                  5      [        UR&                  5      :g  [        U R(                  5      [        UR(                  5      :g  /5      S:  a  gUR                    H*  nXPR                   ;  d  M  U =R                   U/-  sl        M,     UR"                   H*  nX`R"                  ;  d  M  U =R"                  U/-  sl        M,     UR$                   H*  nXpR$                  ;  d  M  U =R$                  U/-  sl        M,     UR&                   H*  nXR&                  ;  d  M  U =R&                  U/-  sl        M,     UR(                   H*  n	XR(                  ;  d  M  U =R(                  U	/-  sl        M,     g)z-Merge the two entries if they are compatible.Nc              3   8   #    U  H  oR                   v   M     g 7fr.   )rt   ).0childs     r!   	<genexpr>*Deb822SourceEntry.merge.<locals>.<genexpr>  s     CN5Ns   Fc              3   ,   #    U  H
  nS U;   v   M     g7f)zAdded by software-propertiesNrK   )r   cs     r!   r   r     s      5
9VA*a/9Vs   )typesurissuites
componentsarchitecturesz	signed-byr   T)ru   rt   allrx   ro   rr   r   r   anyr%   r$   r9   tagslowerr:   sumr   r   r   r   r   )
r2   r|   tagin_selfin_othertypr   suite	componentarchs
             r!   mergeDeb822SourceEntry.merge  s    %CDNNCCC99

"%!233<<5==( 5
:>,,9V5
 2
 2
 tDLL--.emm6H6H1IIJCyy{   ll&&sD1G}}((d3H" K  

Os5;;'77		Nc%**o5$ELL(99

Os5;;'77**+s53F3F/GG 	 ;;C**$

se#
  ::C))#		cU"	  \\EKK'w& " I

*

yk)
 % ''D---""tf," ( r'   c                 L   U R                    H  nUR                   H  nUR                   Hn  nUR                   H[  nUR                  UR
                  UR                  4X4U4:X  d  M.  UR                  U :X  d   e[        R                  " U5      Ul
        M]     Mp     M     M     g)z_If we end up being split, check if any of our children need to be reparented to the new parent.N)rx   r   r   r   _type_uri_suiter]   rv   ry   _parent)r2   tor   r   r   r   s         r!   _reparent_children$Deb822SourceEntry._reparent_childrenP  s|    ^^Exx77C!#!KKU\\BsQVFWW#(<<4#77#7,3KKOEM "+ #   $r'   )rx   rs   rz   r   ro   ru   r9   rt   r.   )r   r   r   N)#rD   rE   rF   rG   r   rq   rH   r   r3   r   r   rM   r   r   rj   r)   rI   r   r   r   r   r   propertyr   setterboolr   r   r   r   r   r   r   r   rJ   rK   r'   r!   r   r      s   
 )-	'3&-' ' }%	'0

C 

C 

 '8STMw(;<E1';NOPDf&:;D
09MN
OC*@AF1(<RSTD|-GHE# # # ^^&s &t & &    ^^?TD[ ?T ? ? N$ N N __d t         c  " "!S !$4 $D $B+ B BH<r'   r   c                      \ rS rSrSr/ SQrS\S\S\S\4S jr\	S	\4S
 j5       r
\	S	\4S j5       r\R                  S\S	S4S j5       r\	S	\\   4S j5       r\	S	\\   4S j5       r\	S	\\   4S j5       r\	S	\4S j5       r\R                  S\S	S4S j5       r\	S	\4S j5       r\R                  S\S	S4S j5       rSS jrSS jrS	\4S jr\" \R.                  5      r\" \R0                  5      r\" \R2                  5      r\\   " \R6                  5      r\" \R8                  5      r\" \R:                  5      rS\S	S4S jr\	S	\4S j5       rSr g)rb   i[  zXThis represents a bit of a deb822 paragraph corresponding to a legacy sources.list entry)r   r   r   r   rt   __weakref__r]   r   r   r   c                     [         R                  " U5      U l        X l        X0l        X@l        UR                  U l        UR                  R                  U 5        g r.   )	rv   ry   r   r   r   r   rt   rx   add)r2   r]   r   r   r   s        r!   r3   "ExplodedDeb822SourceEntry.__init__a  s@    {{6*
	T"r'   r   c                 \    U R                   b  U R                  5       =nb  U$ [        S5      e)Nz#The parent entry is no longer valid)r   
ValueErrorr`   s     r!   r]    ExplodedDeb822SourceEntry.parenti  s.    <<#,,.(5>??r'   c                 :    U R                  5         U R                  $ r.   )'_ExplodedDeb822SourceEntry__check_validr   r   s    r!   r   ExplodedDeb822SourceEntry.urip  s    yyr'   Nc                     U R                  5         U R                  R                   Vs/ s H  o"U R                  :w  a  UOUPM     snU R                  l        Xl        g s  snf r.   )rf   r]   r   r   )r2   r   us      r!   r   r   u  sK    BF++BRBRSBRQdiiAS8BRS	 Ts   Ac                     U R                   /$ r.   rI   r   s    r!   r   ExplodedDeb822SourceEntry.types{      		{r'   c                     U R                   /$ r.   r   r   s    r!   r    ExplodedDeb822SourceEntry.suites  r   r'   c                     U R                   /$ r.   r   r   s    r!   r   ExplodedDeb822SourceEntry.uris  s    zr'   c                 :    U R                  5         U R                  $ r.   )r   r   r   s    r!   rI   ExplodedDeb822SourceEntry.type  s    zzr'   c                     U R                  5         U/U R                  l        Xl        U R	                  5         U R                  U:X  d   eU R                  R                  U R                  /:X  d   eg r.   )rf   r]   r   r   r   )r2   r   s     r!   rI   r     s[     E
zzS   {{  TZZL000r'   c                 :    U R                  5         U R                  $ r.   )r   r   r   s    r!   r   ExplodedDeb822SourceEntry.dist  s    {{r'   c                     U R                  5         U/U R                  l        Xl        U R	                  5         U R                  U:X  d   eU R                  R                  U R                  /:X  d   eg r.   )rf   r]   r   r   r   )r2   r   s     r!   r   r     s[    #W{{e###{{!!dkk]222r'   c                 r   U R                   R                  5       c  [        S5      eU R                   R                   Hj  nU R                   R                   HM  nU R                   R
                   H0  nXU4U R                  U R                  U R                  4:X  d  M.        g    MO     Ml     [        SU  35      e)NThe parent entry is deadCould not find parent of )	r]   rz   r   r   r   r   r   r   r   )r2   rI   r   r   s       r!   __check_valid'ExplodedDeb822SourceEntry.__check_valid  s    ;;&788KK%%D{{''![[//E5)djj$))T[[-QQ 0 ( &
 4TF;<<r'   c           	         U R                   nUR                  UR                  UR                  4U R                  /U R
                  /U R                  /4:X  a  g UR                  5       nUc  [        S5      e UR                  R                  U5      nUR                  U5        Sn[        UR                  5       GH  n[        UR                  5       H  n[        UR                  5       H  n[        [        R                  " UR                   5      UR"                  US9n	U/U	l        U/U	l        U/U	l        SU	l        UR'                  U	5        UR                  R)                  X95        XgU4U R                  U R
                  U R                  4:X  d  M  [*        R,                  " U	5      U l        SnM     M     GM     U(       d  [        SU  35      eg ! [         a  n[        SU  S35      UeS nAff = f)Nr   z Parent entry for partial deb822 z no longer validF)r9   ro   r$   Tr   )r]   r   r   r   r   r   r   rz   r   r$   r   removereversedr   r   rq   r9   ro   ru   r   insertrv   ry   r   )
r2   r]   sources_listr   e
reparentedrI   r   r   news
             r!   rf   #ExplodedDeb822SourceEntry.split_out  s   LL&++v}}5ZZLYYK[[M:
 

 ||~788	 %%++F3E 	F#
V\\*D,%fmm4E+ ' ?#[[)C
 "&CI #uCH"'CJ$(CM--c2 %%,,U85)djj$))T[[-QQ'.{{3'7%)
 5 - +$ 8?@@ 5  	24&8HI	s   8G 
G7"G22G7c                 n    SU R                    SU R                   SU R                   SU R                   3$ )Nz<child rW   z of )r   r   r   r   r   s    r!   __repr__"ExplodedDeb822SourceEntry.__repr__  s1    Adii[$++d4<<.QQr'   r   c                     U(       + U l         g)zSet the source to enabled.Nr   r   s     r!   r   %ExplodedDeb822SourceEntry.set_enabled  r   r'   c                 .    U R                   R                  $ )zReturn the file.)r]   ro   r   s    r!   ro   ExplodedDeb822SourceEntry.file  s     {{r'   )r   r   r   r   r   rt   r   N)!rD   rE   rF   rG   r0   	__slots__r   rH   r3   r   r]   r   r   r$   r   r   r   rI   r   r   rf   r  r[   r   r   r   r   r   r   r   r   ro   rJ   rK   r'   r!   rb   rb   [  s#   b RI#0 #s # #S # @) @ @ S   	ZZs t  
 tCy   S	   d3i   c   
[[1 1 1 1 c   
[[3# 3$ 3 3=)AVR# R **;*I*IJM!"3"9"9:E#$5$=$=>G$T*+<+E+EFH#$5$=$=>G#$5$=$=>G$4 $D $  c    r'   rb   c                   >   \ rS rSrSrSS\S\S-  4S jjrS\S\4S	 jr\	S\S\
\   4S
 j5       rS\SS4S jrS\SS4S jrS\4S jrS\4S jr\S\
\R
                     4S j5       r\S\
\R
                     4S j5       r\S\
\R
                     4S j5       rSrg)r   i  zsingle sources.list entryNr   ro   c                 ^   SU l         SU l        SU l        / U l        S U l        SU l        SU l        / U l        SU l        Xl	        Uc  [        R                  R                  S5      nUR                  S5      (       a  [        S5      eX l        U R!                  U5        S U l        / U l        g )NFrR   Dir::Etc::sourcelist.sourcesz6Classic SourceEntry cannot be written to .sources file)r   r   rI   r   r   r   r   r   r   r   r   config	find_fileendswithr   ro   parsert   children)r2   r   ro   s      r!   r3   SourceEntry.__init__  s    	(*$(	 "
	<>>++,BCD==$$UVV	

4)-+-r'   r|   r   c                 p   U R                   UR                   :H  =(       a    U R                  UR                  :H  =(       aw    U R                  R                  S5      UR                  R                  S5      :H  =(       a9    U R                  UR                  :H  =(       a    U R
                  UR
                  :H  $ r~   r   r   s     r!   r   SourceEntry.__eq__  s     MMU^^+ *		UZZ'*$		(8(8(==* 		UZZ'* 

ekk)	
r'   c                    U R                  5       n / nSnSnSn[        [        U 5      5       H  nX   S:X  a-  U(       a  SnSnUR                  U5        X   nM-  SnX U   -  nM8  X   S:X  a  SnX U   -  nMK  U(       a0  X   R	                  5       (       d  SnUR                  U5        X   nM  X   R	                  5       (       a  U(       d  SnM  X U   -  nM     [        U5      S:  a  UR                  U5        U$ )zta split() implementation that understands the sources.list
format better and takes [] into account (for e.g. cdroms)rR   F[T]r   )r   rangelenappendisspace)r   piecestmpp_foundspace_foundis         r!   rS   SourceEntry.mysplit  s     zz|s4y!Aw#~"'K"GMM#&'C"G7NCCAwTW__%6%6#c"g""7"Aw- "0 s8a<MM#r'   c                 T   Xl         UR                  5       nUS:X  d  US:X  a  SU l        gUS   S:X  a>  SU l        USS R                  5       R	                  5       nUS   S;  a  SU l        gUSS nUR                  S5      nUS:  a  XS-   S U l        USU nU R                  U5      n[        U5      S:  a  SU l        gUS   R                  5       U l	        U R                  S	;  a  SU l        gUS   R                  5       S   S
:X  a  UR                  S5      R                  S5      R	                  5       nU H`  n UR	                  SS5      u  pgUS:X  a  UR	                  S5      U l        M6  US:X  a  [        R                  " U5      U l        MY  SU l        Mb     US   R                  5       U l        [        U R                   5      S:  a  SU l        US   R                  5       U l        [        U5      S:  a  USS U l        g/ U l        g! [         a    SU l         M  f = f)zPparse a given sources.list (textual) line and break it up
into the field we haverR   #TNr   r   )rpmrpm-srcdebdeb-src   )r1  r2  r/  r0  r!  z[]=r   ,r      )r   r   r   r   r   findr   rS   r$  rI   popr   r   r   r   	Exceptionr   r   r   )r2   r   r'  r+  optionsoptionr+   r>   s           r!   r  SourceEntry.parse3  s    	zz|2:DL7c> DM!"X^^%++-F!9 DD#ABxIIcNq5A=DL8Dd#v;?DL1IOO%	99@@DL!9??Q3&jjm))$/557G!
,!'c1!5JC f}-2[[-=*	)'.'='=e'D'+ " !9??$txx=1DL 1IOO%	v;?DJDJ+ ! (#'DL(s    HH'&H'	new_valuec                     U(       + U l         U(       a/  U R                  R                  5       R                  S5      U l        gU R                  R                  5       S   S:w  a  SU R                  -   U l        gg)z!set a line to enabled or disabledr.  r   N)r   r   lstripr   )r2   r=  s     r!   r   SourceEntry.set_enableds  s[    %		((*11#6DI yy #s*$))O	 +r'   c                 >    U R                  5       R                  5       $ )zdebug helperr   r   s    r!   r   SourceEntry.__str__~  s    xxz!!r'   c                    U R                   (       a  U R                  $ SnU R                  (       a  SnXR                  -  nU R                  (       aO  U R
                  bB  USR                  SR                  U R                  5      U R
                  (       a  SOS5      -  nO[U R
                  b  USU R
                  (       a  SOS-  -  nO2U R                  (       a!  USSR                  U R                  5      -  -  nUS	U R                   S	U R                   3-  n[        U R                  5      S
:  a!  US	S	R                  U R                  5      -   -  nU R                  S:w  a  USU R                  -   -  nUS-  nU$ )z!return the current line as stringrR   z# z [arch={} trusted={}]r5  r   r   z [trusted=%s]z
 [arch=%s]rW   r   z #
)r   r   r   rI   r   r   formatrX   r   r   r$  r   r   )r2   r   s     r!   rH   SourceEntry.str  s9   <<99==D		$,,":+22++,4 D \\%Ou$GGDL388D,>,>#???D!DHH:Qtyyk**tzz?QC#((4::...D<<2D4<<''Dr'   c                     U R                   /$ )z'deb822 compatible accessor for the typer   r   s    r!   r   SourceEntry.types       		{r'   c                     U R                   /$ )z&deb822 compatible accessor for the urir   r   s    r!   r   SourceEntry.uris  s     zr'   c                     U R                   /$ )z(deb822 compatible accessor for the suiter   r   s    r!   r   SourceEntry.suites  rI  r'   )r   r  r   r   r   r   ro   r   r   rt   r   rI   r   r.   )rD   rE   rF   rG   r0   rH   r3   r   r   staticmethodr$   rS   r  r   r   r   r   builtinsr   r   r   rJ   rK   r'   r!   r   r     s   #.S .d
 .(
C 
C 
 #c #d3i # #J># >$ >@	,T 	,d 	," "S 6 tHLL)   d8<<(   X\\*  r'   r   c                   *    \ rS rSrSrS\S\4S jrSrg)r   i  za Matcher that does nothingr"   r   c                     g)NTrK   )r2   r"   s     r!   matchNullMatcher.match  s    r'   rK   N)	rD   rE   rF   rG   r0   AnyExplodedSourceEntryr   rR  rJ   rK   r'   r!   r   r     s    %- $ r'   r   c                      \ rS rSrSr  S*SS.S\S\S\4S jjjrS+S jrS	\	\
   4S jrS\\/\4   S\S	\	\   4S jrSSS
/ S
4S\S\S\S\\   S\S\S\S
-  S\\   S\S
-  S	\4S jjrS\S	S
4S jrS\S	S
4S jrS,S\S
-  S	\4S  jjrS\S	S
4S! jrS"\S	\4S# jrS+S$ jrS+S% jrS&\\
   S	\\\
   \\\\
   4   4   4S' jrS	\\   4S( jrS)r g
)-r   i  z6represents the full sources.list + sources.list.d fileF)deb822withMatchermatcherPathrV  c                    / U l         U   U(       a  [        U5      U l        O[        5       U l        X0l        U R                  5         g r.   )r$   r   matcherr   rV  refresh)r2   rW  rX  rV  s       r!   r3   SourcesList.__init__  s4     +-	-k:DL&=DLr'   r   Nc                     / U l         [        R                  R                  S5      nUS:w  a5  [        R
                  R                  U5      (       a  U R                  U5        [        R                  R                  S5      nUS:w  a  [        R
                  R                  U5      (       a  [        [        R                  " U5      5       Hp  nU R                  (       a  UR                  S5      (       d  UR                  S5      (       d  MB  U R                  [        R
                  R                  X!5      5        Mr     U R                    H1  nUR                  (       a  M  U R                  R!                  U5        M3     g)z update the list of known entriesr  z	/dev/nullDir::Etc::sourcepartsr  z.listN)r$   r   r  r  ospathexistsloadfind_dirsortedlistdirrV  r  rX   r   rZ  rR  )r2   ro   partsdirsources       r!   r[  SourcesList.refresh  s    	~~''(>?;277>>$#7#7IIdO>>**+BC{"rww~~h'?'?rzz(34KKDMM*$=$=$--C C IIbggll8:;	 5 iiF>>>""6*  r'   c              #   8   #    U R                    Sh  vN   g N7f)z?simple iterator to go over self.list, returns SourceEntry
typesNr$   r   s    r!   __iter__SourcesList.__iter__  s      99s   
predicatesattrsc              /   l  ^^#    TR                  SS 5      nU R                  5        H  mU(       aA  TR                  (       a0  UR                  S5      TR                  R                  S5      :w  a  MK  [	        UU4S jT 5       5      (       d  Mh  [	        U4S jU 5       5      (       d  M  Tv   M     g 7f)Nr   r   c              3   H   >#    U  H  n[        TU5      TU   :H  v   M     g 7fr.   )getattr)r   r+   rn  rg  s     r!   r   %SourcesList.__find.<locals>.<genexpr>  s!     G#763'5:5s   "c              3   2   >#    U  H  o" T5      v   M     g 7fr.   rK   )r   	predicaterg  s     r!   r   rr    s      P3=i	&!!:s   )r8  exploded_listr   r   r   )r2   rm  rn  r   rg  s     ` @r!   __findSourcesList.__find  s      iit$((*Fvzzcjjo9J9J39O&OGGGGC P3=P M M  +s   BB4B4+	B4rR   rI   r   r   
orig_compsr   posro   r   r]   c
           	      z  ^ UR                  5       nUR                  S5      n
U
(       a  USS R                  5       n[        T5      mUSS nU R	                  U4S jU
SUUUS9nU HC  nU H:  nXR
                  ;   d  M  XR                  U5      	 [        U5      S:X  d  M6  Us  s  $    ME     U R	                  U4S jSUUUS	9nU H  nUR                  U
:X  aC  [        UR
                  5      [        U5      :w  a  [        UR
                  U-   5      Ul        Us  $ UR                  (       d  Mi  U
(       a  Mr  [        UR
                  5      [        U5      :X  d  M  SUl        Us  $    Uc  [        R                  R                  S
5      nUR                  S5      (       a  [        SXpS9nU	(       a]  [        U	SU	5      n	[!        U	[        5      (       d   eU	R"                  R$                   H  nU	R"                  U   UR"                  U'   M!     U/Ul        U/Ul        U/Ul        Xl        T(       a  [-        T5      Ul        X_R"                  l        Xl        OU
(       a  SOSUT(       a  SSR3                  T5      -  OSUU/nUR5                  U5        U(       a  UR7                  SU-   5        SR3                  S U 5       5      S-   n[9        U5      nUb  Xl        U R<                  R?                  U5        US:  a  U R,                  R7                  U5        U$ U R,                  RA                  Xo5        U$ )z
Add a new source to the sources.list.
The method will search for existing matching repos and will try to
reuse them as far as possible
r.  r   Nc                 4   > [        U R                  5      T:H  $ r.   r%   r   r"   r   s    r!   <lambda>!SourcesList.add.<locals>.<lambda>      c!//*m;r'   F)r   r   rI   r   r   r   c                 4   > [        U R                  5      T:H  $ r.   r}  r~  s    r!   r  r    r  r'   )r   rI   r   r   r  r  )ro   r$   r]   rR   z	[arch=%s]r5  rW   c              3   6   #    U  H  o(       d  M  Uv   M     g 7fr.   rK   )r   parts     r!   r   "SourcesList.add.<locals>.<genexpr>P  s     ;UTdDDUs   
	rD  )!r   
startswithr?  r%   _SourcesList__findr   r   r$  r   r&   r   r  r  r  r   rq  rr   r9   r   r   r   r   r$   r   r   rX   extendr%  r   ro   rZ  rR  r  )r2   rI   r   r   ry  r   rz  ro   r   r]   r   r   sourcesrg  new_comp	new_entrykpartsr   s           `          r!   r   SourcesList.add  s   $ zz|??3'8??$DM* 1++;  
 F!||+ kk(345zQ% "  ++;  
 F(* v||$E
2#'u(<#=FLv||$E
2&+FO!M  <>>++,BCD==$$)$TEI 6:!&*;<<<<,,A+1>>!+<I%%a( -#fIO!UIN $vI#O*.}*=	''.$!)  R;Hsxx66bE LLS7]+88;U;;dBD#D)I!%9%7IIY'  IIS,r'   source_entryc                     [        U[        5      (       a  UR                  5         UR                  nU R                  R                  U5        g)z0remove the specified entry from the sources.listN)rr   rb   rf   r]   r$   r  )r2   r  s     r!   r  SourcesList.remove]  s9    l$=>>""$'..L		&r'   
backup_extc                    [         R                  R                  S5      n[        R                  R                  X!-   5      (       a=  [        R                  R                  U5      (       a  [        R                  " X!-   U5        [         R                  R                  S5      n[        R                  " SU-  5       HD  n[        R                  R                  X!-   5      (       d  M+  [        R                  " X!-   U5        MF     g)z8restore sources.list files based on the backup extensionr  r^  z%s/*N)
r   r  r  r_  r`  ra  shutilcopyrc  glob)r2   r  ro   rf  s       r!   restore_backupSourcesList.restore_backupd  s    ~~''(>?77>>$+,,1E1EKK)40>>**+BCIIfx/0Dww~~d/00D-t4 1r'   c                 T   [        5       nUc  [        R                  " S5      nU R                   Ht  nUR                  U;  d  M  [
        R                  R                  UR                  5      (       d  ME  [        R                  " UR                  UR                   U 35        Mv     U$ )zxmake a backup of the current source files, if no backup extension
is given, the current date/time is used (and returned)z%y%m%d.%H%M)
r%   timestrftimer$   ro   r_  r`  ra  r  r  )r2   r  already_backupedrg  s       r!   backupSourcesList.backupo  sx     +.%}5JiiF{{"22rww~~fkk7R7RFKKFKK=)EF   r'   c           
          [        U5       nUR                  S5      (       aA  [        R                  " U5       H&  nU R                  R                  [        X1U S95        M(     O/U H)  n[        XA5      nU R                  R                  U5        M+     SSS5        g! , (       d  f       g= f! [         a'  n[        R                  " SU SU S35         SnAgSnAff = f)z(re)load the current sourcesr  rj  Nzcould not open file 'z': rD  )openr  r   Filer$   r%  r   r   r9  loggingwarning)r2   ro   fr9   r   rg  excs          r!   rb  SourcesList.loadz  s    
	Fdq==,,#*<<?		(():7t)TU $3 !"!,T!8		((0 !"   	FOO3D6SEDEE	Fs5   B. BBB. 
B+'B. +B. .
C8CCentryc                     [        U[        5      (       a%  U R                  R                  UR                  5      $ U R                  R                  U5      $ r.   )rr   rb   r$   r   r]   )r2   r  s     r!   r   SourcesList.index  s:    e67799??5<<00yyu%%r'   c                    SnU(       a  SnSnUS-   [        U R                  5      :  a  U R                  U   n[        U[        5      (       aq  US-   nU[        U R                  5      :  aS  UR	                  U R                  U   5      (       a  U R                  U	 SnOUS-  nU[        U R                  5      :  a  MS  US-  nUS-   [        U R                  5      :  a  M  U(       a  M  gg)z=Merge consecutive entries that have been split back together.Tr   Fr   N)r$  r$   rr   r   r   )r2   mergedr+  r  js        r!   r   SourcesList.merge  s    AFa%#dii.(		!e%677AAc$))n, ;;tyy|44 $		!%)FFA c$))n, Q a%#dii.( fr'   c                    0 n[        U R                  5      S:X  aH  [        R                  R	                  S5      nSn[        US5       nUR                  U5        SSS5        gU R                  5          U R                   H  nUR                  U;  a#  [        UR                  S5      XR                  '   O2[        U[        5      (       a  XR                     R                  S5        XR                     R                  UR                  5       5        M     UR                  5        H  nUR                  5         M     g! , (       d  f       g= f! UR                  5        H  nUR                  5         M     f = f)zsave the current sourcesr   r  z## See sources.list(5) for more information, especialy
# Remember that you can only use http, ftp or file URIs
# CDROMs are managed through the apt-cdrom tool.
wNrD  )r$  r$   r   r  r  r  writer   ro   rr   r   rH   rU   close)r2   filesr`  r   r  rg  s         r!   saveSourcesList.save  s   -/tyy>Q>>++,BCDE  dCA !

		));;e+)-fkk3)?E++&(9::++&,,T2kk"((6 $ \\^	 $ ! \\^	 $s   	E 5B#E  
E)E:r  c                 :   / n0 nU H  nUR                   c  M  UR                   R                  (       a,  UR                   nXS;  a  / X5'   X5   nUR                  U5        MY  [        UR                   R                  5      S:  d  M~  UR                  U5        M     X#4$ )z5get all parent and child channels in the sources listr   )rt   r   r%  r$  r  )r2   r  parentsused_child_templatesrg  r+   temps          r!   check_for_relationsSourcesList.check_for_relations  s     EG"F& $$oo202(-+0F# v//014NN6* #$ ..r'   c                     / nU R                    H  n[        U[        5      (       a  UR                  U5        M+  [	        UR
                  5      S:X  aE  [	        UR                  5      S:X  a,  [	        UR                  5      S:X  a  UR                  U5        M  UR
                   Hb  nUR                   HO  nUR                   H<  nUR                  [        X#XE5      5        U R                  R                  US   5        M>     MQ     Md     M     U$ )a&  Present an exploded view of the list where each entry corresponds exactly to a Release file.

A release file is uniquely identified by the triplet (type, uri, suite). Old style entries
always referred to a single release file, but deb822 entries allow multiple values for each
of those fields.
r   rx  )r$   rr   r   r%  r$  r   r   r   rb   rZ  rR  )r2   resr  r   r   suis         r!   ru  SourcesList.exploded_list  s     -/YYE%--

5!EKK A%

Oq(%*

5! ;;C$zz#(<<CJJ'@S'VW LL..s2w7 $0  * '   
r'   )rV  r$   rZ  )Tz /usr/share/python-apt/templates/r  r.   )!rD   rE   rF   rG   r0   r   rH   r3   r[  r   r   rk  r   rT  r   r  r$   intr   r   r  r  r  rb  r   r   r  tupledictr   r  ru  rJ   rK   r'   r!   r   r     s   @ !=
  
  +((>2 

#%;$<d$BC
NQ
	(	)
$ ')04ii i 	i
 Ii i i Dji  }i '-i 
 iV'#9 'd '	5 	5 	5	t 	s 	F F F&1 &c &
$8/$^4/	tN#T(D4H*H%II	J/4t$:; r'   r   c                   8    \ rS rSrSrS\4S jrS\S\4S jr	Sr
g	)
r   i  zlmatcher class to make a source entry look nice
lots of predefined matchers to make it i18n/gettext friendly
rX  c                 L   / U l         [        R                  " SU-  5      nU H~  n[        R                  R	                  U5      nUR                  S5      nUSU n[        X1S9nUR                    H-  nUR                  c  M  U R                   R                  U5        M/     M     g )Nz	%s/*.infoz.infor   )base_dir)		templatesr  r_  r`  basenamer7  r   	match_urir%  )r2   rX  
spec_filesr  r+  r   rt   s          r!   r3   SourceEntryMatcher.__init__  s    )+YY{[89
A  #AwA!AAA4D NN%%1NN))(3 +  	r'   rg  r   c                    SnU R                    GHg  nUR                  b  UR                  c  M   UR                  b  UR                  b  UR                  b  UR                  b  [
        R                  " UR                  UR                  5      (       ae  [
        R                  " UR                  UR                  5      (       a5  UR                  UR                  :X  d  UR                  S:X  a  SnX1l	          U$ UR                  UR                  5      (       d  GM  UR                  c  GM  UR                  c  GM,  [
        R                  " UR                  UR                  5      (       d  GM_  SnX1l	          U$    U$ )z%Add a matching template to the sourceFr1  T)r  r   r   r  
match_nameresearchrR  rI   rt   r   )r2   rg  foundrt   s       r!   rR  SourceEntryMatcher.match  s   Hzz!V[[%8"".''3JJ*KK+IIh00&**==HHX00&++>> -%1G"*  ""6::..''3KK+HHX00&++>>"*7 '6 r'   )r  N)rD   rE   rF   rG   r0   rH   r3   rT  r   rR  rJ   rK   r'   r!   r   r     s'    C 2 t r'   r   __main__zentry %sz!http://archive.ubuntu.com/ubuntu/z$http://de.archive.ubuntu.com/ubuntu/zis_mirror(): %sz http://archive.ubuntu.com/ubuntuz#http://de.archive.ubuntu.com/ubuntur  )5rO  r  ior  os.pathr_  r  r  r  rv   collections.abcr   r   r   typingr   r   r   r	   r
   r   rR   r   distinfor   r   r   __all__rH   r   r   r$   r&   r   r)   rM   r[   rj   rl   r   rb   r   r   rT  r   r   r   rD   init_configr  r  infomirrorrK   r'   r!   <module>r     s  4   	   	    8 8 9 9   ( CL# C D :HQK DG *( *&1 1 /Hgaj / Q 1 
z< z<zN  N b~ ~B {$556"$== 
 s sl	1 1j zmGZ%))+-.  +-SF LL"V+,LL.0V	

 LL/1V	
% r'   