
    Cfc=%                         d Z ddlZddlZ	 ddlmZmZmZmZmZm	Z	m
Z
 dZddddd	Z ej                  d
      Z G d de      Z G d de      Zd Zd Z G d de      Z G d de      Zy# e$ r Y Uw xY w)z'Functions for working with watch files.    N)IterableIteratorListOptionalSequenceTextIOTuple   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                       e Zd ZdZy)MissingVersionzThe version= line is missing.N__name__
__module____qualname____doc__     ./usr/lib/python3/dist-packages/debian/watch.pyr   r   =   s    'r   r   c                       e Zd ZdZy)WatchFileFormatErrorz(Raised when the input is not valid.
    Nr   r   r   r   r   r   A   s    r   r   c                     t        t        j                               }||d<   |j                         D ]  \  }}| j                  ||      }  | S )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)textpackagesubstskvs        r   expandr!   F   sQ     -%%'(F "F; "1||Aq!"Kr   c                 H    |rt        |       t        j                  |        y N)r   loggerwarning)msgstricts     r   	_complainr(   W   s    "3''
NN3r   c                   <    e Zd ZdZddefdZd Zd Zedd       Z	y)	WatchFilezA 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                 >    || _         |g }|| _        |g }|| _        y r#   )versionentriesoptions)selfr-   r.   r,   s       r   __init__zWatchFile.__init__g   s-    
 ?G?Gr   c                 ,    t        | j                        S r#   )iterr-   r/   s    r   __iter__zWatchFile.__iter__t   s    DLL!!r   c                    d }| j                   |j                  d| j                   z         | j                  r$|j                   || j                        dz          | j                  D ]  }|j                  r$|j                   ||j                        dz          |j                  |j                         |j
                  r|j                  d|j
                  z          |j                   r|j                  d|j                   z          |j                  r|j                  d|j                  z          |j                  d        y)aO  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                 N    dj                  |       }d|v sd|v rd|z   dz   S d|z   S )N, 	zopts=""opts=)join)optsss     r   serialize_optionsz)WatchFile.dump.<locals>.serialize_options   s5    Aax419!|c))Q;r   Nzversion=%d

r8   )r,   writer.   r-   urlmatching_patternscript)r/   fr?   entrys       r   dumpzWatchFile.dumpx   s    	 <<#GGNT\\12<<GG%dll3d:;\\ 
	E}})%--83>?GGEII%%e4445}}emm+,||ell*+GGDM
	r   c                    g }g }|D ]  }|j                  d      r|j                         s&|j                  d      j                  d      r!|j	                  |j                  d             g|j	                  |       |j	                  |       g } |rt        d|       |j	                  |       |sydj                  |j                  d            }	 |j                  d	d
      \  }}|j                         dk7  r
t               t        |j                               }	g }
g }|D ]}  }|	dkD  r|D cg c]  }|j                          }}dj                  |      j                         }|sH|j                  d      rf|d   dk(  r3|j                  dd      }|dk(  rt        d|z        |d| }||d
z   d }n	 |dd j                  dd
      \  }}|j                  d      }ng }|r	 |j                  dd
      \  }}t        j                  d|      }|rAt!        |d         ft#        |j                  dd
            z   }|dt%        |d          d
z
   }nt#        |j                  dd            }|j	                  t'        |g|d|i       m|
j)                  |         | ||
|	      S # t        $ r t               w xY wc c}w # t        $ r |dd }d}Y w xY w# t        $ r |}d}Y w xY w)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
        #r@   \z
\z*watchfile ended with \; skipping last lineN r   =   r,      r;      r:      zNot matching " in %rr7   z/([^/]*\([^/]*\)[^/]*)$   r=   )r-   r.   r,   )
startswithstriprstripendswithappendr(   r<   popsplit
ValueErrorr   intlstripindexrefindallstrtuplelenWatchextend)clslinesr'   joined_lines	continuedline	firstlinekeyvaluer,   persistent_optionsr-   chunkedchunkoptendopts_strr=   rB   mpartss                       r   
from_lineszWatchFile.from_lines   s    	 
	Ds#::<{{4 ))$/  V!45  &##I.	
	 CVL	*GGL,,Q/0		#"a0JC 99;)# ""ekkm$# &	0G{ 8??e5<<>??777#))+Dw'7c>!ZZQ/F|()?$)FGG#Af~Hq	?D"+/8>>$+B(4  ~~c* $

4 3IC JJ93? 1YME$**T12E,FFEmAaD	z!|,C!$**T1"56EuS<5<t<="))$/M&	0N %7J 	J]  	# ""	# @ & "#'8!" " CDs6   J4 5K=K,K'4KK$#K$'K76K7)F)
r   r   r   r   DEFAULT_VERSIONr0   r4   rG   classmethodrt   r   r   r   r*   r*   ^   s:     ("@ NJ NJr   r*   c                   ,    e Zd ZdZ	 	 	 	 ddZd Zd Zy)rc   aO  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                 R    || _         || _        || _        || _        |g }|| _        y r#   )rB   rC   r,   rD   r.   )r/   rB   rC   r,   rD   r=   s         r   r0   zWatch.__init__   s2      0<Dr   c                     | j                   j                  d| j                  d| j                  d| j                  d| j
                  d| j                  dS )N(z, matching_pattern=z
, version=z	, script=z, opts=))	__class__r   rB   rC   r,   rD   r.   r3   s    r   __repr__zWatch.__repr__  s<     ''43H3Hdkk4<<9	:r   c                 .   t        |t              sy|j                  | j                  k(  xrj |j                  | j                  k(  xrO |j                  | j                  k(  xr4 |j
                  | j
                  k(  xr |j                  | j                  k(  S )NF)
isinstancerc   rB   rC   r,   rD   r.   )r/   others     r   __eq__zWatch.__eq__  s    %'		TXX% .&&$*?*??.-. +. -		/r   )NNNN)r   r   r   r   r0   r}   r   r   r   r   rc   rc      s$    	 #':/r   rc   )r   loggingr^   typingr   r   r   r   r   r   r	   ImportErrorru   r   	getLoggerr$   	Exceptionr   rZ   r   r!   r(   objectr*   rc   r   r   r   <module>r      s   $ .  		
 
 
 
 5 K	& :  
		>	*(Y (: 
"IJ IJX*/F */Q  		s   A, ,A43A4