o a%@sdZddlZddlmZzddlmZmZmZmZm Z m Z m Z Wn e y)YnwdZ dddd d ZGd d d eZGd ddeZddZddZGdddeZGdddeZdS)z'Functions for working with watch files.N)warn)IterableIteratorListOptionalSequenceTextIOTuplez[-_]?(\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@c@eZdZdZdS)MissingVersionzThe version= line is missing.N__name__ __module__ __qualname____doc__rr./usr/lib/python3/dist-packages/debian/watch.pyr :r c@r )WatchFileFormatErrorz(Raised when the input is not valid. Nr rrrrr>rrcCs6tt}||d<|D] \}}|||}q|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 SUBSTITUTIONSitemsreplace)textpackagesubstskvrrrexpandCs rcCs|rt|t|dSN)rr)msgstrictrrr _complainTs r#c@s>eZdZdZddefddZddZddZed d d Z dS) 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 NcCs.||_|dur g}||_|durg}||_dSr )versionentriesoptions)selfr&r'r%rrr__init__ds zWatchFile.__init__cCs t|jSr )iterr&r(rrr__iter__qs zWatchFile.__iter__cCsdd}|jdur|d|j|jr|||jd|jD];}|jr0|||jd||j|jrA|d|j|jrL|d|j|jrW|d|j|dq!dS)aOWrite 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 cSs.d|}d|vs d|vrd|dSd|S)N,  zopts=""opts=)join)optssrrrserialize_optionss  z)WatchFile.dump..serialize_optionsNz version=%d  r.)r%writer'r&urlmatching_patternscript)r(fr5entryrrrdumpus"    zWatchFile.dumpFc Csg}g}|D]*}|drq|sq|ddr$||dq||||g}q|r=td||||sAdSd|d}z |d d \}}Wn t y]t w|d krgt t |} g} g} |D]} | d krd d| D} d| }|sqs|dr|ddkr| dd} | dkrt d||d| }|| d d}n z|dddd \}}Wnt y|dd}d}Ynw|d}ng}|r4z |dd \}}Wn t y|}d}Ynwt d|}|rt|dft|dd }|dt|d d }nt|dd}| t|g|Rd|iqs| |qs|| | | dS)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 #r6\z \z*watchfile ended with \; skipping last lineNr=r%cSsg|]}|qSr)lstrip).0chunkrrr sz(WatchFile.from_lines..r1r0zNot matching " in %rr-z/([^/]*\([^/]*\)[^/]*)$r3)r&r'r%) startswithstriprstripendswithappendr#r2popsplit ValueErrorr intindexrefindallstrtuplelenWatchextend)clslinesr" joined_lines continuedline firstlinekeyvaluer%persistent_optionsr&chunkedoptendopts_strr3r8mpartsrrr from_liness                    zWatchFile.from_lines)F) rrrrDEFAULT_VERSIONr)r,r= classmethodrkrrrrr$[s    r$c@s2eZdZdZ    d ddZddZddZdS) r[aOWatch 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 NcCs.||_||_||_||_|durg}||_dSr )r8r9r%r:r')r(r8r9r%r:r3rrrr)s zWatch.__init__cCs"d|jj|j|j|j|j|jfS)Nz;%s(%r, matching_pattern=%r, version=%r, script=%r, opts=%r)) __class__rr8r9r%r:r'r+rrr__repr__s  zWatch.__repr__cCsJt|tsdS|j|jko$|j|jko$|j|jko$|j|jko$|j|jkS)NF) isinstancer[r8r9r%r:r')r(otherrrr__eq__ s      z Watch.__eq__)NNNN)rrrrr)rorrrrrrr[s   r[)rrVwarningsrtypingrrrrrrr ImportErrorrlr Exceptionr rSrrr#objectr$r[rrrrs* (