
    )gV$                         S r SSKrSSKrSSKJrJrJrJrJrJ	r	  Sr
SSSSS	.r\R                  " S
5      r " S S\5      r " S S\5      rS\S\S\4S jrS\S\SS4S jr " S S5      r " S S5      rg)z'Functions for working with watch files.    N)IterableIteratorListOptionalSequenceTextIO   z[-_]?(\d[\-+\.:\~\da-zA-Z]*)z2(?i)\.(?:tar\.xz|tar\.bz2|tar\.gz|zip|tgz|tbz|txz)zL(?i)\.(?:tar\.xz|tar\.bz2|tar\.gz|zip|tgz|tbz|txz)\.(?:asc|pgp|gpg|sig|sign)z%[\+~](debian|dfsg|ds|deb)(\.)?(\d+)?$)z@ANY_VERSION@z@ARCHIVE_EXT@z@SIGNATURE_EXT@z	@DEB_EXT@zdebian.watchc                       \ rS rSrSrSrg)MissingVersion7   zThe version= line is missing. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       ./usr/lib/python3/dist-packages/debian/watch.pyr   r   7   s    'r   r   c                       \ rS rSrSrSrg)WatchFileFormatError;   z(Raised when the input is not valid.
    r   Nr   r   r   r   r   r   ;   s    r   r   textpackagereturnc                     [        [        R                  5       5      nXS'   UR                  5        H  u  p4U R                  X45      n M     U $ )zApply substitutions to a string.

:param text: text to apply substitutions to
:param package: package name, as a string
:return: text with subsitutions applied
z	@PACKAGE@)dictSUBSTITUTIONSitemsreplace)r   r   substskvs        r   expandr%   @   sF     -%%'(F ";||A! Kr   msgstrictc                 R    U(       a  [        U 5      e[        R                  U 5        g N)r   loggerwarning)r&   r'   s     r   	_complainr,   P   s    "3''
NN3r   c                   H    \ rS rSrSrSS\4S jrS rS r\	S	S j5       r
Srg)
	WatchFileV   zA Debian watch file.

:ivar entries: list of Watch entries
:ivar options: optional list of global options, applied to all Watch
    entries
:ivar version: watch file version
Nc                 <    X0l         Uc  / nXl        Uc  / nX l        g r)   )versionentriesoptions)selfr2   r3   r1   s       r   __init__WatchFile.__init___   s'    
 ?G?Gr   c                 ,    [        U R                  5      $ r)   )iterr2   r4   s    r   __iter__WatchFile.__iter__l   s    DLL!!r   c                    S nU R                   b  UR                  SU R                   -  5        U R                  (       a$  UR                  U" U R                  5      S-   5        U R                   H  nUR                  (       a$  UR                  U" UR                  5      S-   5        UR                  UR                  5        UR
                  (       a  UR                  SUR
                  -   5        UR                   (       a  UR                  SUR                   -   5        UR                  (       a  UR                  SUR                  -   5        UR                  S5        M     g)a'  Write the contents of a watch file to a file-like object.

Note that this will not preserve the formatting of the original file,
and thus it is currently not possible to use this function to
parse and reserialize a file and end up with the same contents.

:param f: File-like object to write to
c                 V    SR                  U 5      nSU;   d  SU;   a  SU-   S-   $ SU-   $ )N, 	zopts=""opts=)join)optsss     r   serialize_options)WatchFile.dump.<locals>.serialize_optionsz   s5    Aax419!|c))Q;r   Nzversion=%d

r?   )r1   writer3   r2   urlmatching_patternscript)r4   frF   entrys       r   dumpWatchFile.dumpp   s    	 <<#GGNT\\12<<GG%dll3d:;\\E}})%--83>?GGEII%%e4445}}emm+,||ell*+GGDM "r   c                 f   / n/ nU H  nUR                  S5      (       a  M  UR                  5       (       d  M2  UR                  S5      R                  S5      (       a"  UR	                  UR                  S5      5        My  UR	                  U5        UR	                  U5        / nM     U(       a  [        SU5        UR	                  U5        U(       d  gSR                  UR                  S5      5      n UR                  S	S
5      u  pxUR                  5       S:w  a
  [        5       e[        UR                  5       5      n	/ n
/ nU GH  nU	S:  a  U Vs/ s H  oR                  5       PM     nnSR                  U5      R                  5       nU(       d  MQ  UR                  S5      (       af  US   S:X  a3  UR                  SS5      nUS:X  a  [        SU-  5      eUSU nX^S
-   S nO USS R                  SS
5      u  pUR                  S5      nO/ nU(       a   UR                  SS
5      u  nn[        R                  " SU5      nU(       aA  [!        US   5      4[#        UR                  SS
5      5      -   nUS[%        US   5      * S
-
   nO[#        UR                  SS5      5      nUR	                  ['        U/UQ7SU065        GM  U
R)                  U5        GM     U " XU	S9$ ! [         a    [        5       ef = fs  snf ! [         a    USS nSn GNf = f! [         a    UnSn Nf = f)a  Parse from the contents that make up a watch file.

:param lines: watch file lines to parse
:return: instance or None if there are no non-comment lines in the file
:raise MissingVersion: if there is no version number declared
:raise ValueError: when syntax errors are encountered
#rH   \z
\z*watchfile ended with \; skipping last lineN r   =   r1      rB      rA      zNot matching " in %rr>   z/([^/]*\([^/]*\)[^/]*)$   rD   r2   r3   r1   )
startswithstriprstripendswithappendr,   rC   popsplit
ValueErrorr   intlstripindexrefindallstrtuplelenWatchextend)clslinesr'   joined_lines	continuedline	firstlinekeyvaluer1   persistent_optionsr2   chunkedchunkoptendopts_strrD   rJ   mpartss                       r   
from_linesWatchFile.from_lines   s    	Ds##::<<{{4 ))$//  V!45  &##I.	  CVL	*GGL,,Q/0		#"a0JC 99;)# ""ekkm$#G{ 8??we<<>w?777#))+Dw''7c>!ZZQ/F|()?$)FGG#Af~Hq	?D"+/8>>$+B(  ~~c* $

4 3IC JJ93? 1YME$**T12E,FFEmAaD	z!|,C!$**T1"56EuS<5<t<="))$/M $N J 	J]  	# ""	# @ & "#'8!" " CDs6   5K* L*LL*K?LLL0/L0r\   )F)r   r   r   r   r   DEFAULT_VERSIONr5   r:   rO   classmethodr~   r   r   r   r   r.   r.   V   s:     ("@ NJ NJr   r.   c                   >    \ rS rSrSr    S	S jrS\4S jrS rSr	g)
rm      a3  Watch line entry.

This will contain the attributes documented in uscan(1):

:ivar url: The URL (possibly including the filename regex)
:ivar matching_pattern: a filename regex, optional
:ivar version: version policy, optional
:ivar script: script to run, optional
:ivar opts: a list of options, as strings
Nc                 J    Xl         X l        X0l        X@l        Uc  / nXPl        g r)   )rJ   rK   r1   rL   r3   )r4   rJ   rK   r1   rL   rD   s         r   r5   Watch.__init__   s(      0<Dr   r   c                     U R                   R                  < SU R                  < SU R                  < SU R                  < SU R
                  < SU R                  < S3$ )N(z, matching_pattern=z
, version=z	, script=z, opts=))	__class__r   rJ   rK   r1   rL   r3   r9   s    r   __repr__Watch.__repr__   s<     ''43H3Hdkk4<<9	:r   c                 `   [        U[        5      (       d  gUR                  U R                  :H  =(       ay    UR                  U R                  :H  =(       aY    UR                  U R                  :H  =(       a9    UR
                  U R
                  :H  =(       a    UR                  U R                  :H  $ )NF)
isinstancerm   rJ   rK   r1   rL   r3   )r4   others     r   __eq__Watch.__eq__  s    %''		TXX% .&&$*?*??.-. +. -		/r   )rK   r3   rL   rJ   r1   )NNNN)
r   r   r   r   r   r5   rj   r   r   r   r   r   r   rm   rm      s+    	 #':# :/r   rm   )r   loggingrh   typingr   r   r   r   r   r   r   r   	getLoggerr*   	Exceptionr   rd   r   rj   r%   boolr,   r.   rm   r   r   r   <module>r      s   $ .  	  
 5 K	& :  
		>	*(Y (: 
 s s  3   IJ IJX)/ )/r   