
    pg                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
mZmZmZ d dlmZmZmZmZmZ d dlZddlmZ ddlmZmZ  ed      Zg dZd	ed
edefdZdee   dee   fdZ  G d de!      Z" G d de!      Z# G d de!ee         Z$dedefdZ%d+dZ& G d d      Z' G d d      Z( G d d      Z)ee)e'f   Z*ee)e'e(f   Z+ G d d      Z, G d  d!      Z- G d" d#      Z.e/d$k(  r ej`                           e-       Z1e1D ]%  Z2 ejf                  d%e2j9                         z         '  ed&d'      Z4 ejf                  d(e4z          ejf                   ed)d'              ejf                   ed&d*             yy),    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                    |j                  d      }| j                  d      } || k(  ry	 |j                  d      d   }| j                  d      d   }d|v r||j                  d      dz   d |k(  ryy# t        $ r Y yw xY w)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j !''-a0%%d+A.
 kk+*;*;C*@1*D*FG:U  s   (A2 2	A>=A>sc                 *    t        t        |             S )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                   `    e Zd ZdedefdZ	 dded   dedz  dedz  fd	Zddd
edz  ddfdZy)SingleValuePropertykeydocc                      || _         || _        y Nr*   __doc__selfr*   r+   s      r!   __init__zSingleValueProperty.__init__c       r'   Nobjr   objtyper   c                 V    || S |j                   j                  | j                  d       S r-   )sectiongetr*   r1   r4   r5   s      r!   __get__zSingleValueProperty.__get__g   s'     ;K{{txx..r'   valuec                 j    ||j                   | j                  = y ||j                   | j                  <   y r-   )r7   r*   r1   r4   r;   s      r!   __set__zSingleValueProperty.__set__n   s)    =DHH%$)CKK!r'   r-   )	__name__
__module____qualname__strr2   r   typer:   r>    r'   r!   r)   r)   b   sf    C c 
 JN//0/;?$;/	t/*. *sTz *d *r'   r)   c                   `    e Zd ZdedefdZ	 dded   dedz  dee   fd	Zddd
ee   ddfdZ	y)MultiValuePropertyr*   r+   c                      || _         || _        y r-   r.   r0   s      r!   r2   zMultiValueProperty.__init__v   r3   r'   Nr4   r   r5   r   c                 |    || S t         j                  |j                  j                  | j                  d            S )N )r   mysplitr7   r8   r*   r9   s      r!   r:   zMultiValueProperty.__get__z   s2     ;K""3;;??488R#@AAr'   valuesc                 T    dj                  |      |j                  | j                  <   y )N )joinr7   r*   )r1   r4   rK   s      r!   r>   zMultiValueProperty.__set__   s     # 0DHHr'   r-   )
r?   r@   rA   rB   r2   r   rC   r$   r:   r>   rD   r'   r!   rF   rF   u   sj    C c 
 JNB/0B;?$;B	cB1. 1S	 1d 1r'   rF   c                   P    e Zd ZdefdZ	 dded   dedz  defdZddd	eddfd
Zy)ExplodedEntryPropertyparentc                     || _         y r-   )rQ   r1   rQ   s     r!   r2   zExplodedEntryProperty.__init__   s	    r'   Nr4   ExplodedDeb822SourceEntryr5   r   c                 T    || S | j                   j                  |j                         S r-   )rQ   r:   r9   s      r!   r:   zExplodedEntryProperty.__get__   s'     ;K{{""3::..r'   r;   c                 p    |j                          | j                  j                  |j                  |       y r-   )	split_outrQ   r>   r=   s      r!   r>   zExplodedEntryProperty.__set__   s#    CJJ.r'   r-   )	r?   r@   rA   r   r2   r   rC   r:   r>   rD   r'   r!   rP   rP      sW    q  RV/78/CG$;/	
//6 /q /T /r'   rP   propc                     | S r-   rD   )rX   s    r!   DeprecatedPropertyrZ      s    Kr'   c                       y)z3Behaves like an expired weakref.ref, returning NoneNrD   rD   r'   r!   _null_weakrefr\      s    r'   c                   R   e Zd Z	 d%dej                  ez  dz  deded   fdZdedefd	Z	 e
d
d      Z e
dd      Z e edd            Z e
dd      Z e edd            Z e
dd      Z e edd            Z e
dd      Zedefd       Zej.                  deddfd       Zededz  fd       Zej.                  dedz  ddfd       Zedefd       Zej.                  deddfd       Zedefd       Zedefd       ZdefdZdefdZd eddfd!Zdd"defd#Zd&d$Z y)'r   Nr7   filer$   r   c                    |t        j                  d      | _        n2t        |t              rt        j                  |      | _        n|| _        t	        | j                        | _        || _        d | _        d| _        t        j                  d          | _        |rt        j                  |      | _        y t        | _        y )NrI   FrT   )r   Sectionr7   
isinstancerB   _liner^   template	may_mergeweakrefWeakSet	_childrenref_listr\   )r1   r7   r^   r$   s       r!   r2   zDeb822SourceEntry.__init__   s     ?"??2.DL%"??73DL"DL&
	)- )DEG;B;;t;LDJ&DJr'   otherr   c                 d   | j                   |j                   k(  xr | j                  |j                  k(  xr{ | j                  xrm | j                  j                  d      |j                  j                  d      k(  xr4 | j                  |j                  k(  xr | j
                  |j
                  k(  S z+equal operator for two sources.list entries/disabledrC   urir   distcompsr1   rj   s     r!   __eq__z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                 .    | j                   j                  S )1Legacy attribute describing the paragraph header.r7   headerr1   s    r!   commentzDeb822SourceEntry.comment   s     ||"""r'   r   c                 &    || j                   _        y)r{   Nr|   )r1   r   s     r!   r   zDeb822SourceEntry.comment   s     &r'   c                 f    	 t        j                  | j                  d         S # t        $ r Y yw xY w)z%Return the value of the Trusted fieldTrustedN)apt_pkgstring_to_boolr7   KeyErrorr~   s    r!   trustedzDeb822SourceEntry.trusted   s3    	))$,,y*ABB 		s   !$ 	00r;   c                 j    |	 | j                   d= y |rdnd| j                   d<   y # t        $ r Y y w xY w)Nr   yesnor7   r   r1   r;   s     r!   r   zDeb822SourceEntry.trusted   s@    =LL+ 05e$DLL#  s   & 	22c                 b    t        j                  | j                  j                  dd             S )zCheck if Enabled: no is set.Enabledr   )r   r   r7   r8   r~   s    r!   ro   zDeb822SourceEntry.disabled   s)     ))$,,*:*:9e*LMMMr'   c                 b    |rd| j                   d<   y 	 | j                   d= y # t        $ r Y y w xY w)Nr   r   r   r   s     r!   ro   zDeb822SourceEntry.disabled   s6    &*DLL#LL+ s   " 	..c                     | j                    S )z7A section is invalid if it doesn't have proper entries.)r7   r~   s    r!   invalidzDeb822SourceEntry.invalid   s     <<r'   c                     | j                   S )z The entire (original) paragraph.)rb   r~   s    r!   linezDeb822SourceEntry.line   s     zzr'   c                 >    | j                         j                         S r-   rB   stripr~   s    r!   __str__zDeb822SourceEntry.__str__  s    xxz!!r'   c                 ,    t        | j                        S )z(Section as a string, newline terminated.)rB   r7   r~   s    r!   rB   zDeb822SourceEntry.str  s    4<<  r'   enabledc                     | | _         y)z.Deprecated (for deb822) accessor for .disabledNro   r1   r   s     r!   set_enabledzDeb822SourceEntry.set_enabled      #r'   AnySourceEntryc           
      d   | j                   s)| j                  t        d | j                  D              sy| j                  |j                  k7  ryt        |t              sy| j                  |j                  k7  r)t        d | j                  |j                  fD              syt        t        | j                  j                        t        |j                  j                        z         D ]T  }|j                         dv r| j                  j                  |d      }|j                  j                  |d      }||k7  sT y t        t        | j                         t        |j                         k7  t        | j"                        t        |j"                        k7  t        | j$                        t        |j$                        k7  t        | j&                        t        |j&                        k7  t        | j(                        t        |j(                        k7  g      dkD  ry|j                   D ]'  }|| j                   vs| xj                   |gz  c_        ) |j"                  D ]'  }|| j"                  vs| xj"                  |gz  c_        ) |j$                  D ]'  }|| j$                  vs| xj$                  |gz  c_        ) |j&                  D ]'  }|| j&                  vs| xj&                  |gz  c_        ) |j(                  D ]'  }	|	| j(                  vs| xj(                  |	gz  c_        ) y)z-Merge the two entries if they are compatible.Nc              3   4   K   | ]  }|j                     y wr-   )rc   ).0childs     r!   	<genexpr>z*Deb822SourceEntry.merge.<locals>.<genexpr>  s     C5Cs   Fc              3   $   K   | ]  }d |v  
 yw)zAdded by software-propertiesNrD   )r   cs     r!   r   z*Deb822SourceEntry.merge.<locals>.<genexpr>  s      5
45*a/5
s   )typesurissuites
componentsarchitecturesz	signed-byr   T)rd   rc   allrg   r^   ra   r   r   anyr%   r$   r7   tagslowerr8   sumr   r   r   rr   r   )
r1   rj   tagin_selfin_othertyprp   suite	componentarchs
             r!   mergezDeb822SourceEntry.merge  s    %CDNNCC99

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

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

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

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

*

yk)
	* '' 	-D4---""tf,"	- r'   c                 6   | j                   D ]  }|j                  D ]y  }|j                  D ]h  }|j                  D ]W  }|j                  |j
                  |j                  f|||fk(  s-|j                  | k(  sJ t        j                  |      |_
        Y j {  y)z_If we end up being split, check if any of our children need to be reparented to the new parent.N)rg   r   r   r   _type_uri_suiterQ   re   rh   _parent)r1   tor   r   rp   r   s         r!   _reparent_childrenz$Deb822SourceEntry._reparent_childrenP  s    ^^ 	<Exx <77 <C!# <!KKU\\BsCQVFWW#(<<4#77#7,3KKOEM<<<	<r'   r-   )r   r   r   N)!r?   r@   rA   r   r`   rB   r   r2   r   rt   rF   r   r   rZ   r)   rC   r   rp   r   rq   rr   propertyr   setterboolr   ro   r   r   r   r   r   r   rD   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                      e Zd ZdZg dZdedededefdZedefd	       Z	edefd
       Z
e
j                  deddfd       Z
edee   fd       Zedee   fd       Zedee   fd       Zedefd       Zej                  deddfd       Zedefd       Zej                  deddfd       ZddZddZdefdZ eej,                        Z eej.                        Z eej0                        Z ee   ej4                        Z eej6                        Z eej8                        ZdeddfdZedefd       Zy)rT   zXThis represents a bit of a deb822 paragraph corresponding to a legacy sources.list entry)r   r   r   r   rc   __weakref__rQ   r   rp   r   c                     t        j                  |      | _        || _        || _        || _        |j                  | _        |j                  j                  |        y r-   )	re   rh   r   r   r   r   rc   rg   add)r1   rQ   r   rp   r   s        r!   r2   z"ExplodedDeb822SourceEntry.__init__a  sF    {{6*
	T"r'   r   c                 X    | j                   | j                         x}|S t        d      )Nz#The parent entry is no longer valid)r   
ValueErrorrS   s     r!   rQ   z ExplodedDeb822SourceEntry.parenti  s.    <<#,,.(5>??r'   c                 :    | j                          | j                  S r-   )'_ExplodedDeb822SourceEntry__check_validr   r~   s    r!   rp   zExplodedDeb822SourceEntry.urip  s    yyr'   Nc                     | j                          | j                  j                  D cg c]  }|| j                  k7  r|n| c}| j                  _        || _        y c c}w r-   )rW   rQ   r   r   )r1   rp   us      r!   rp   zExplodedDeb822SourceEntry.uriu  sI    BF++BRBRSQdiiAS8S	 Ts   Ac                     | j                   gS r-   rC   r~   s    r!   r   zExplodedDeb822SourceEntry.types{      		{r'   c                     | j                   gS r-   rq   r~   s    r!   r   z ExplodedDeb822SourceEntry.suites  r   r'   c                     | j                   gS r-   rp   r~   s    r!   r   zExplodedDeb822SourceEntry.uris  s    zr'   c                 :    | j                          | j                  S r-   )r   r   r~   s    r!   rC   zExplodedDeb822SourceEntry.type  s    zzr'   c                     | j                          |g| j                  _        || _        | j	                          | j                  |k(  sJ | j                  j                  | j                  gk(  sJ y r-   )rW   rQ   r   r   r   )r1   r   s     r!   rC   zExplodedDeb822SourceEntry.type  s]     E
zzS   {{  TZZL000r'   c                 :    | j                          | j                  S r-   )r   r   r~   s    r!   rq   zExplodedDeb822SourceEntry.dist  s    {{r'   c                     | j                          |g| j                  _        || _        | j	                          | j                  |k(  sJ | j                  j                  | j                  gk(  sJ y r-   )rW   rQ   r   r   r   )r1   r   s     r!   rq   zExplodedDeb822SourceEntry.dist  s]    #W{{e###{{!!dkk]222r'   c                 d   | j                   j                         t        d      | j                   j                  D ]e  }| j                   j                  D ]J  }| j                   j
                  D ]/  }|||f| j                  | j                  | j                  fk(  s-   y  L g t        d|        )NThe parent entry is deadCould not find parent of )	rQ   ri   r   r   r   r   r   r   r   )r1   rC   rp   r   s       r!   __check_validz'ExplodedDeb822SourceEntry.__check_valid  s    ;;&788KK%% 	D{{'' ![[// Ec5)djj$))T[[-QQ	
 4TF;<<r'   c                    | j                   }|j                  |j                  |j                  f| j                  g| j
                  g| j                  gfk(  ry |j                         }|t        d      	 |j                  j                  |      }|j                  |       d}t        |j                        D ]  }t        |j                        D ]  }t        |j                        D ]  }t        t        j                  |j                         |j"                  |      }	|g|	_        |g|	_        |g|	_        d|	_        |j'                  |	       |j                  j)                  ||	       |||f| j                  | j
                  | j                  fk(  st+        j,                  |	      | _        d}   |st        d|        y # t        $ r}t        d|  d      |d }~ww xY w)Nr   z Parent entry for partial deb822 z no longer validF)r7   r^   r$   Tr   )rQ   r   r   r   r   r   r   ri   r   r$   r   removereversedr   r   r`   r7   r^   rd   r   insertre   rh   r   )
r1   rQ   sources_listr   e
reparentedrC   rp   r   news
             r!   rW   z#ExplodedDeb822SourceEntry.split_out  s   LL&++v}}5ZZLYYK[[M:
 

 ||~788	 %%++F3E 	F#
V\\* 	*D, *%fmm4 *E+ ' ?#[[)C
 "&CI #uCH"'CJ$(CM--c2 %%,,UC8c5)djj$))T[[-QQ'.{{3'7%)
**	*$ 8?@@ 5  	24&8HI	s   6G
 
	G(G##G(c                 n    d| j                    d| j                   d| j                   d| j                   S )Nz<child rM   z of )r   r   r   r   r~   s    r!   __repr__z"ExplodedDeb822SourceEntry.__repr__  s1    Adii[$++d4<<.QQr'   r   c                     | | _         y)zSet the source to enabled.Nr   r   s     r!   r   z%ExplodedDeb822SourceEntry.set_enabled  r   r'   c                 .    | j                   j                  S )zReturn the file.)rQ   r^   r~   s    r!   r^   zExplodedDeb822SourceEntry.file  s     {{r'   r   N)r?   r@   rA   r/   	__slots__r   rB   r2   r   rQ   rp   r   r$   r   r   r   rC   rq   r   rW   r   rP   r   rr   r   r   ro   r   r   r   r^   rD   r'   r!   rT   rT   [  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'   rT   c                       e Zd ZdZddededz  fdZdedefdZedede	e   fd	       Z
deddfd
ZdeddfdZdefdZdefdZede	ej                     fd       Zede	ej                     fd       Zede	ej                     fd       Zy)r   zsingle sources.list entryNr   r^   c                 V   d| _         d| _        d| _        g | _        d | _        d| _        d| _        g | _        d| _        || _	        |t        j                  j                  d      }|j                  d      rt        d      || _        | j!                  |       d | _        g | _        y )NFrI   Dir::Etc::sourcelist.sourcesz6Classic SourceEntry cannot be written to .sources file)r   ro   rC   r   r   rp   rq   rr   r   r   r   config	find_fileendswithr   r^   parserc   children)r1   r   r^   s      r!   r2   zSourceEntry.__init__  s    	(*$(	 "
	<>>++,BCD==$UVV	

4)-+-r'   rj   r   c                 H   | j                   |j                   k(  xr | j                  |j                  k(  xrm | j                  j                  d      |j                  j                  d      k(  xr4 | j                  |j                  k(  xr | j
                  |j
                  k(  S rl   rn   rs   s     r!   rt   zSourceEntry.__eq__  s     MMU^^+ *		UZZ'*$		(8(8(==* 		UZZ'* 

ekk)	
r'   c                    | j                         } g }d}d}d}t        t        |             D ]  }| |   dk(  r(|rd}d}|j                  |       | |   }(d}|| |   z  }3| |   dk(  rd}|| |   z  }F|r,| |   j	                         sd}|j                  |       | |   }t| |   j	                         r|sd}|| |   z  } t        |      dkD  r|j                  |       |S )z|a split() implementation that understands the sources.list
        format better and takes [] into account (for e.g. cdroms)rI   F[T]r   )r   rangelenappendisspace)r   piecestmpp_foundspace_foundis         r!   rJ   zSourceEntry.mysplit  s    zz|s4y! 	AAw#~"'K"GMM#&q'C"G47NCaCtAwT!W__%6#c"1ga"7"tAw-	0 s8a<MM#r'   c                 0   || _         |j                         }|dk(  s|dk(  rd| _        y|d   dk(  r<d| _        |dd j                         j	                         }|d   dvrd| _        y|dd }|j                  d      }|dkD  r||dz   d | _        |d| }| j                  |      }t        |      dk  rd| _        y|d   j                         | _	        | j                  d	vrd| _        y|d   j                         d   d
k(  r|j                  d      j                  d      j	                         }|D ][  }	 |j	                  dd      \  }}|dk(  r|j	                  d      | _        5|dk(  rt        j                  |      | _        Ud| _        ] |d   j                         | _        t        | j                         dk  rd| _        |d   j                         | _        t        |      dkD  r|dd | _        yg | _        y# t        $ r
 d| _        Y w xY w)zXparse a given sources.list (textual) line and break it up
        into the field we haverI   #TNr   r   )rpmrpm-srcdebdeb-src   )r  r  r  r  r   z[]=r   ,r      )r   r   r   ro   r   findr   rJ   r   rC   popr   r   r   r   	Exceptionrp   rq   rr   )r1   r   r   r   optionsoptionr*   r;   s           r!   r   z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   8HHH	new_valuec                     | | _         |r/| j                  j                         j                  d      | _        y| j                  j                         d   dk7  rd| j                  z   | _        yy)z!set a line to enabled or disabledr   r   N)ro   r   lstripr   )r1   r  s     r!   r   zSourceEntry.set_enableds  s[    %		((*11#6DI yy #s*$))O	 +r'   c                 >    | j                         j                         S )zdebug helperr   r~   s    r!   r   zSourceEntry.__str__~  s    xxz!!r'   c                    | j                   r| j                  S d}| j                  rd}|| j                  z  }| j                  rI| j
                  =|dj                  dj                  | j                        | j
                  rdnd      z  }nP| j
                  |d| j
                  rdndz  z  }n-| j                  r!|ddj                  | j                        z  z  }|d	| j                   d	| j                   z  }t        | j                        d
kD  r!|d	d	j                  | j                        z   z  }| j                  dk7  r|d| j                  z   z  }|dz  }|S )z!return the current line as stringrI   z# z [arch={} trusted={}]r  r   r   z [trusted=%s]z
 [arch=%s]rM   r   z #
)r   r   ro   rC   r   r   formatrN   rp   rq   r   rr   r   )r1   r   s     r!   rB   zSourceEntry.str  s;   <<99==D		$,,":+22++,4 D \\%Ou$GGDL388D,>,>#???D!DHH:Qtyyk**tzz?QC#((4::...D<<2D4<<''Dr'   c                     | j                   gS )z'deb822 compatible accessor for the typer   r~   s    r!   r   zSourceEntry.types       		{r'   c                     | j                   gS )z&deb822 compatible accessor for the urir   r~   s    r!   r   zSourceEntry.uris  s     zr'   c                     | j                   gS )z(deb822 compatible accessor for the suiter   r~   s    r!   r   zSourceEntry.suites  r  r'   r-   )r?   r@   rA   r/   rB   r2   r   rt   staticmethodr$   rJ   r   r   r   r   r   builtinsr   r   r   rD   r'   r!   r   r     s   #.S .d
 .(
C 
C 
 #c #d3i # #J># >$ >@	,T 	,d 	," "S 6 tHLL)   d8<<(   X\\*  r'   r   c                        e Zd ZdZdedefdZy)r   za Matcher that does nothingr"   r   c                      y)NTrD   )r1   r"   s     r!   matchzNullMatcher.match  s    r'   N)r?   r@   rA   r/   AnyExplodedSourceEntryr   r  rD   r'   r!   r   r     s    %- $ r'   r   c                   t   e Zd ZdZ	 	 d(dddededefdZd)d
Zdee	   fdZ
deegef   dedee   fdZddd	g d	fdedededee   dededed	z  dee   ded	z  defdZdedd	fdZdedd	fdZd*ded	z  defdZdedd	fd Zd!edefd"Zd)d#Zd)d$Zd%ee	   deee	   eeee	   f   f   fd&Zdee   fd'Zy	)+r   z6represents the full sources.list + sources.list.d fileF)deb822withMatchermatcherPathr   c                    g | _         |  |rt        |      | _        nt               | _        || _        | j                          y r-   )r$   r   matcherr   r   refresh)r1   r!  r"  r   s       r!   r2   zSourcesList.__init__  s6     +-	-k:DL&=DLr'   r   Nc                    g | _         t        j                  j                  d      }|dk7  r0t        j
                  j                  |      r| j                  |       t        j                  j                  d      }|dk7  rt        j
                  j                  |      rxt	        j                  |      D ]`  }| j                  r|j                  d      s|j                  d      s2| j                  t        j
                  j                  ||             b | j                   D ]*  }|j                  r| j                  j                  |       , y)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listdirr   r   rN   r   r$  r  )r1   r^   partsdirsources       r!   r%  zSourcesList.refresh  s    	~~''(>?;277>>$#7IIdO>>**+BC{"rww~~h'?

8, <KKDMM*$=$--C IIbggll8T:;	< ii 	+F>>""6*	+r'   c              #   8   K   | j                   E d{    y7 w)zGsimple iterator to go over self.list, returns SourceEntry
        typesNr$   r~   s    r!   __iter__zSourcesList.__iter__  s      99s   
predicatesattrsc              /   4  K   j                  dd       }| j                         D ]m  |r:j                  r.|j                  d      j                  j                  d      k7  r?t	        fdD              sUt	        fd|D              sj o y w)Nrp   rm   c              3   B   K   | ]  }t        |      |   k(    y wr-   )getattr)r   r*   r4  r/  s     r!   r   z%SourcesList.__find.<locals>.<genexpr>  s!     G#763'5:5Gs   c              3   .   K   | ]  } |        y wr-   rD   )r   	predicater/  s     r!   r   z%SourcesList.__find.<locals>.<genexpr>  s      P&/	&!Ps   )r
  exploded_listrp   r   r   )r1   r3  r4  rp   r/  s     ` @r!   __findzSourcesList.__find  s      iit$((* 	Fvzzcjjo9J9J39O&OGGGC P3=P M 	s   A7B<BBrI   rC   rp   rq   
orig_compsr   posr^   r   rQ   c
                    |j                         }|j                  d      }
|
r|dd j                         }t              |dd }| j	                  fd|
d|||      }|D ]>  }|D ]7  }||j
                  v s||j                  |      = t        |      dk(  s3|c c S  @ | j	                  fdd|||	      }|D ]  }|j                  |
k(  rBt        |j
                        t        |      k7  rt        |j
                  |z         |_        |c S |j                  sa|
rdt        |j
                        t        |      k(  sd|_        |c S  |t        j                  j                  d
      }|j                  d      rt        d||       }|	rVt        |	d|	      }	t!        |	t              sJ |	j"                  j$                  D ]  }|	j"                  |   |j"                  |<     |g|_        |g|_        |g|_        ||_        rt-              |_        ||j"                  _        |
|_        nw|
rdnd|rddj3                        z  nd||g}|j5                  |       |r|j7                  d|z          dj3                  d |D              dz   }t9        |      }|||_        | j<                  j?                  |       |dk  r| j,                  j7                  |       |S | j,                  jA                  ||       |S )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    t        | j                        k(  S r-   r%   r   r"   r   s    r!   <lambda>z!SourcesList.add.<locals>.<lambda>      c!//*m; r'   F)ro   r   rC   rp   rq   r   c                 4    t        | j                        k(  S r-   rA  rB  s    r!   rC  z!SourcesList.add.<locals>.<lambda>  rD  r'   )r   rC   rp   rq   r   r   )r^   r$   rQ   rI   z	[arch=%s]r  rM   c              3   &   K   | ]	  }|s|  y wr-   rD   )r   parts     r!   r   z"SourcesList.add.<locals>.<genexpr>P  s     ;TdD;s   r  )!r   
startswithr  r%   _SourcesList__findrr   r   r   ro   r&   r   r   r   r   r   r7  ra   r7   r   r   r   r   r$   r   r}   rN   extendr   r   r^   r$  r  r   )r1   rC   rp   rq   r=  r   r>  r^   r   rQ   ro   rr   sourcesr/  new_comp	new_entrykpartsr   s           `          r!   r   zSourcesList.add  s   $ zz|??3'8??$DM* 1++;  
  	&F! &v||+ ekk(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#IO*.}*=	''.I$!)I  R;Hsxx66bE LLS7]+88;U;;dBD#D)I!%	9%7IIY'  IIS),r'   source_entryc                     t        |t              r|j                          |j                  }| j                  j                  |       y)z0remove the specified entry from the sources.listN)ra   rT   rW   rQ   r$   r   )r1   rP  s     r!   r   zSourcesList.remove]  s6    l$=>""$'..L		&r'   
backup_extc                    t         j                  j                  d      }t        j                  j                  ||z         r8t        j                  j                  |      rt        j                  ||z   |       t         j                  j                  d      }t        j                  d|z        D ]>  }t        j                  j                  ||z         s&t        j                  ||z   |       @ y)z8restore sources.list files based on the backup extensionr   r'  z%s/*N)
r   r   r   r(  r)  r*  shutilcopyr,  glob)r1   rR  r^   r.  s       r!   restore_backupzSourcesList.restore_backupd  s    ~~''(>?77>>$+,1EKKz)40>>**+BCIIfx/0 	5Dww~~dZ/0D:-t4	5r'   c                 8   t               }|t        j                  d      }| j                  D ]i  }|j                  |vst
        j                  j                  |j                        s<t        j                  |j                  |j                   |        k |S )zmake 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$   r^   r(  r)  r*  rT  rU  )r1   rR  already_backupedr/  s       r!   backupzSourcesList.backupo  s|     +.%}5Jii 	GF{{"22rww~~fkk7RFKKFKK=)EF	G r'   c           	         	 t        |      5 }|j                  d      rBt        j                  |      D ])  }| j                  j                  t        |||              + n.|D ])  }t        ||      }| j                  j                  |       + ddd       y# 1 sw Y   yxY w# t        $ r&}t        j                  d| d| d       Y d}~yd}~ww xY w)z(re)load the current sourcesr   r1  Nzcould not open file 'z': r  )openr   r   Filer$   r   r   r   r  loggingwarning)r1   r^   fr7   r   r/  excs          r!   r+  zSourcesList.loadz  s    
	Fd 1q==,#*<<? V		(():7Dt)TUV !" 1!,T4!8		((011 1 1  	FOO3D6SEDEE	Fs5   B$ BBB$ B!B$ !B$ $	C-CCentryc                     t        |t              r%| j                  j                  |j                        S | j                  j                  |      S r-   )ra   rT   r$   r   rQ   )r1   rd  s     r!   r   zSourcesList.index  s7    e6799??5<<00yyu%%r'   c                    d}|rd}d}|dz   t        | j                        k  r| j                  |   }t        |t              ri|dz   }|t        | j                        k  rL|j	                  | j                  |         r| j                  |= d}n|dz  }|t        | j                        k  rL|dz  }|dz   t        | j                        k  r|ryy)z=Merge consecutive entries that have been split back together.Tr   Fr   N)r   r$   ra   r   r   )r1   mergedr   rd  js        r!   r   zSourcesList.merge  s    AFa%#dii.(		!e%67AAc$))n, ;;tyy|4 $		!%)FFA c$))n, Q a%#dii.( r'   c                    i }t        | j                        dk(  rHt        j                  j	                  d      }d}t        |d      5 }|j                  |       ddd       y| j                          	 | j                  D ]  }|j                  |vr$t        |j                  d      ||j                  <   n.t        |t              r||j                     j                  d       ||j                     j                  |j                                 	 |j                         D ]  }|j                           y# 1 sw Y   yxY w# |j                         D ]  }|j                           w xY w)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.
wNr  )r   r$   r   r   r   r^  writer   r^   ra   r   rB   rK   close)r1   filesr)  r}   rb  r/  s         r!   savezSourcesList.save  s+   -/tyy>Q>>++,BCDE  dC  A 

		)) 7;;e+)-fkk3)?E&++&(9:&++&,,T2fkk"((67 \\^ 	  \\^ 	s   D84BE 8E'E+r   c                 &   g }i }|D ]  }|j                   |j                   j                  r,|j                   }||vrg ||<   ||   }|j                  |       Rt        |j                   j                        dkD  su|j                  |        ||fS )z5get all parent and child channels in the sources listr   )rc   r   r   r   r   )r1   r   parentsused_child_templatesr/  r*   temps          r!   check_for_relationszSourcesList.check_for_relations  s     EG" 	+F& $$oo2202(-+C0F# v//014NN6*	+$ -..r'   c                     g }| j                   D ]  }t        |t              r|j                  |       %t	        |j
                        dk(  rBt	        |j                        dk(  r*t	        |j                        dk(  r|j                  |       |j
                  D ]_  }|j                  D ]N  }|j                  D ]=  }|j                  t        ||||             | j                  j                  |d          ? P a  |S )aF  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   r<  )r$   ra   r   r   r   r   r   r   rT   r$  r  )r1   resrd  r   rp   suis         r!   r:  zSourcesList.exploded_list  s     -/YY 	8E%-

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

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

5! ;; 8C$zz 8#(<< 8CJJ'@SRU'VW LL..s2w7888	8  
r'   )Tz /usr/share/python-apt/templates/r   r-   )r?   r@   rA   r/   r   rB   r2   r%  r   r   r2  r   r  r   rI  r$   intr   r   r   rW  r\  r+  r   r   rn  tupledictr   rs  r:  rD   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                   ,    e Zd ZdZdefdZdedefdZy)r   ztmatcher class to make a source entry look nice
    lots of predefined matchers to make it i18n/gettext friendly
    r"  c                 F   g | _         t        j                  d|z        }|D ]}  }t        j                  j	                  |      }|j                  d      }|d| }t        ||      }|j                   D ]*  }|j                  | j                   j                  |       ,  y )Nz	%s/*.infoz.infor   )base_dir)		templatesrV  r(  r)  basenamer	  r   	match_urir   )r1   r"  
spec_filesrb  r   rq   rc   s          r!   r2   zSourceEntryMatcher.__init__  s    )+YY{[89
 	4A  #AwA!AAA4D NN 4%%1NN))(34	4 	r'   r/  r   c                    d}| j                   D ]A  }|j                  |j                  |j                  |j                  |j                  |j                  t        j                  |j                  |j                        r^t        j                  |j                  |j                        r4|j                  |j                  k(  s|j                  dk(  rd}||_	         |S |j                  |j                        s|j                  |j                  t        j                  |j                  |j                        s8d}||_	         |S  |S )z%Add a matching template to the sourceFr  T)r}  rp   rq   r  
match_nameresearchr  rC   rc   r   )r1   r/  foundrc   s       r!   r  z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'   N)	r?   r@   rA   r/   rB   r2   r  r   r  rD   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   )5r  rV  ior`  os.pathr(  r  rT  rY  re   collections.abcr   r   r   typingr   r   r   r	   r
   r   rI   r   distinfor   r   r   __all__rB   r   r   r$   r&   r   r)   rF   rP   rZ   r\   r   rT   r   r   r  r   r   r   r?   init_configrK  rd  infomirrorrD   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GmG /Z%))+-./ +-SF GLL"V+,GLL.0V	

 GLL/1V	
% r'   