
    )uyc=%                        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
 n# e$ r Y nw xY w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dS )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dS )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dS )WatchFileFormatErrorz(Raised when the input is not valid.
    Nr   r   r   r   r   r   A   s           r   r   c                     t          t                                                    }||d<   |                                D ]\  }}|                     ||          } | 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   s^     -%%''((F "F; " "1||Aq!!Kr   c                 \    |rt          |           t                              |            d S N)r   loggerwarning)msgstricts     r   	_complainr(   W   s0     ("3'''
NN3r   c                   D    e Zd ZdZddefdZd Zd Zedd            Z	dS )		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 }|| _        d S r#   )versionentriesoptions)selfr-   r.   r,   s       r   __init__zWatchFile.__init__g   s1    
 ?G?Gr   c                 *    t          | j                  S r#   )iterr-   r/   s    r   __iter__zWatchFile.__iter__t   s    DL!!!r   c                 R   d }| j         |                    d| j         z             | j        r&|                     || j                  dz              | j        D ]}|j        r&|                     ||j                  dz              |                    |j                   |j        r|                    d|j        z              |j         r|                    d|j         z              |j        r|                    d|j        z              |                    d           dS )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                 V    d                     |           }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   s;    Aaxx4199!|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22< 	<GG%%dl33d:;;;\ 
	 
	E} @))%-883>???GGEI% 6e44555} -em+,,,| ,el*+++GGDMMMM
	 
	r   Fc                 .   g }g }|D ]}|                     d          r|                                s-|                    d                              d          r)|                    |                    d                     ~|                    |           |                    |           g }|r%t          d|           |                    |           |sdS d                    |                    d                    }	 |                    d	d
          \  }}n# t          $ r t                      w xY w|                                dk    rt                      t          |                                          }	g }
g }|D ]}|	dk    rd |D             }d                    |                                          }|s?|                     d          r|d         dk    rF|                    dd          }|dk    rt          d|z            |d|         }||d
z   d         }n?	 |dd                             dd
          \  }}n# t          $ r |dd         }d}Y nw xY w|                    d          }ng }|r	 |                    dd
          \  }}n# t          $ r |}d}Y nw xY wt          j        d|          }|r\t          |d                   ft!          |                    dd
                    z   }|dt#          |d                    d
z
           }n#t!          |                    dd                    }|                    t%          |g|R d|i           |
                    |             | ||
|	          S )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,      c                 6    g | ]}|                                 S r   )lstrip).0chunks     r   
<listcomp>z(WatchFile.from_lines.<locals>.<listcomp>   s     ???e5<<>>???r   r;      r:      zNot matching " in %rr7   z/([^/]*\([^/]*\)[^/]*)$   r=   )r-   r.   r,   )
startswithstriprstripendswithappendr(   r<   popsplit
ValueErrorr   intindexrefindallstrtuplelenWatchextend)clslinesr'   joined_lines	continuedline	firstlinekeyvaluer,   persistent_optionsr-   chunkedoptendopts_strr=   rB   mpartss                      r   
from_lineszWatchFile.from_lines   s    	 
	 
	Ds## ::<< {{4  ))$//   V!4!45555  &&&##I...		 	+CVLLL	*** 	4GGL,,Q//00		#"a00JC 	# 	# 	# """	#99;;)## """ekkmm$$# &	0 &	0G{{ @?w???777##))++D w'' 7c>>!ZZQ//F||()?$)FGGG#AfH~Hq		?DD"+/8>>$+B+B(44% " " "#'8!"  ~~c** 0 $

4 3 3IC!   CDDD J93?? 7 1YYME$**T12E2E,F,FFEmAaD		z!|m,CC!$**T1"5"566EuS<5<<<t<<===="))$////s%7J J J 	Js0   D   D90!II+*I+	J##J43J4)F)
r   r   r   r   DEFAULT_VERSIONr0   r4   rG   classmethodrw   r   r   r   r*   r*   ^   s          (   " " "  @ NJ NJ NJ [NJ NJ NJr   r*   c                   .    e Zd ZdZ	 	 	 	 ddZd Zd ZdS )rg   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                 T    || _         || _        || _        || _        |g }|| _        d S r#   )rB   rC   r,   rD   r.   )r/   rB   rC   r,   rD   r=   s         r   r0   zWatch.__init__   s6      0<Dr   c                 p    | 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__  sH     '''43H3H3Hdkkk4<<<9	:r   c                     t          |t                    sdS |j        | j        k    o?|j        | j        k    o/|j        | j        k    o|j        | j        k    o|j        | j        k    S )NF)
isinstancerg   rB   rC   r,   rD   r.   )r/   others     r   __eq__zWatch.__eq__  st    %'' 	5	TX% .&$*??.-. +. -		/r   )NNNN)r   r   r   r   r0   r   r   r   r   r   rg   rg      s^        	 	 #'   : : :/ / / / /r   rg   )r   loggingrb   typingr   r   r   r   r   r   r	   ImportErrorrx   r   	getLoggerr$   	Exceptionr   r_   r   r!   r(   objectr*   rg   r   r   r   <module>r      s  $ . -  					
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  	 	 	D	
 
 5 K	& :   
	>	*	*( ( ( ( (Y ( ( (    :   
  "  IJ IJ IJ IJ IJ IJ IJ IJX*/ */ */ */ */F */ */ */ */ */s    ''