
    z#g!                         S SK r S SKrSSKJr  SSKJr  S SKJr  S SK	J
r
  S SKJr  SrS	rS
 rS rSS jrSS jr   SS jrg)    N   )utils)open_url)	NoNetwork)Deb822)debian_supportz4https://qa.debian.org/madison.php?package=%s&text=onz%https://ftp-master.debian.org/new.822c                 L    U (       a  U(       d  g[         R                  " X5      $ )a  
Compare package version strings

This is a wrapper around `debian_support.version_compare()` that
returns 0 if one if the versions is empty.

Parameters
----------
current : str
    version assumed to be currently installed
upstream : str
    version assumed to be available upstream

Returns
-------
int
    1 if upstream is newer than current, -1 if current is
    newer than upstream, and 0 if the same.
r   )r   version_compare)currentupstreams     9/usr/lib/python3/dist-packages/reportbug/checkversions.pycompare_versionsr   )   s    ( ())(<<    c                 (    [        X5      S:  a  U$ U $ )a,  
Pick the later version of two version strings

This is a helper function originally used in
:func:`get_incoming_version()`, but currently not used.

Parameters
----------
a : str
    first package version
b : str
    second package version

Returns
-------
str
    the later (higher) version string
r   )r   )abs     r   later_versionr   B   s    & !Hr   c                 v   [         R                  " 5       n[        U -  nU(       a  USSR                  U5      -   -  nUSU-   -  n [	        XSU5      nU(       d  0 $ UR                  SS5      R                  5       n0 n	UR                  S	5       HC  n
 U
R                  S
5      u  ppUS:X  a  M   [         R                   R#                  X5      nXU'   ME     U	$ ! [
         a    0 s $ [        R                  R                   a%  n[        SU[        R                  S9  0 s SnA$ SnAff = f! [         a     M  f = f)a  
Get package versions available.

If `dists` is not given, get versions from all dists known to the
version lookup service at https://qa.debian.org/madison.php

Parameters
----------
package : str
    package name
timeout : int
    connection timeout in seconds
dists : (str, ...), optional
    tuple of dist names ('stable', 'testing' etc.) to check
http_proxy : str, optional
    http proxy url
arch : str, optional
    architecture name

Returns
-------
{str: str, ...}
    dictionary with found dists as keys and versions as values,
    e.g.,:

        {
            "oldstable": "46.1",
            "stable": "1:26.1+1-3.2+deb10u1",
            "testing": "1:26.1+1-4",
            "unstable": "1:26.3+1-1"
        }
z&s=,z&a=source,all,Warning:fileN  
|source)r   get_archRMADISON_URLjoinr   r   urlliberror	HTTPErrorprintsysstderrreplacestripsplit
ValueErrorCODENAME2SUITEget)packagetimeoutdists
http_proxyarchurlpagexcontentversionslinepvdr   dists                   r   get_versions_availabler<   Z   s/   B >>D

 Cusxx&& d""C1 	 ll3#))+GHd#	CJA!
 = ##''- $  OK  	<<!! j!#**-	.  		s6   C D*D'%D'D"D'"D'*
D87D8c                    Uc  Sn [        [        X15      nU(       d  0 $ 0 n[        R                  " U5       H=  nUS   U :X  d  M  US   S-   US   -   S	-   n	[        US
   R                  5       5      Xy'   M?     U$ ! [         a    0 s $ [        R                  R
                   a%  n[        SU[        R                  S9  0 s SnA$ SnAff = f)a  
Get package versions available in the NEW queue

If `dists` is not given, get versions from unstable (NEW queue).

This is a helper function for :func:`check_available()`.

Parameters
----------
package : str
    package name
timeout : int
    connection timeout in seconds
dists : (str, ...), optional
    tuple of dist names ('stable', 'testing' etc.) to check
http_proxy : str, optional
    http proxy url
arch : str, optional
    unused

Returns
-------
{str: str, ...}
    dictionary with found dists as keys and versions as values
N)zunstable (new queue)r   r   SourceDistributionz (Queue)Version)r   NEWQUEUE_URLr   r!   r"   r#   r$   r%   r&   r   iter_paragraphsmaxr)   )
r-   r.   r/   r0   r1   r3   r4   r6   paraks
             r   get_newqueue_availablerH      s    4 })j: 	H &&t,>W$^$t+d7m;cAAd9o3356HK	 - O#  	<<!! j!#**-	s#   A; ;C	C&C CCc                 b   0 n[        XX6U5      n	UR                  U	5        U(       a9  [        R                  " U 5      n
U
c  U n
[	        XX6U5      n	UR                  U	5        0 nSnU H,  n[        XU   5      nUS:  a  X   X'   M  US:  d  M'  US-  nM.     U=(       a    U[        U5      :H  nX4$ )a  
Check a package version against other available versions

The package archive contains many different versions of most
packages. This function determines whether a given package version
is newer than all versions available in the archive, and (if not)
which available versions are newer.

Parameters
----------
package : str
    package name
version : str
    package version
timeout : int
    connection timeout in seconds
dists : (str, ...), optional
    tuple of dist names ('stable', 'testing' etc.) to check
check_incoming : bool
    unused/ignored
check_newqueue : bool
    True if the NEW queue should be checked for new versions
http_proxy : str, optional
    http proxy url
arch : str, optional
    architecture name

Returns
-------
(dict, bool)
    Tuple with a dictionary and a bool. The dictionary contains the
    versions found to be newer than the given version. E.g.,
            {"unstable": "42.1", "testing": "42.0"}

    The bool indicates whether the checked (installed)
    version is strictly newer than all available versions.
r   r   )r<   updater   get_source_namerH   r   len)r-   versionr.   r/   check_incomingcheck_newqueuer0   r1   availstuff
srcpackagenewnewerr;   
comparisontoo_news                   r   check_availablerW      s    P E"7UME	LL**73
 J&zEtTU C E%gT{;
>CI!^QJE  ,#e*,G<r   )NNi386)NTTNrX   )r%   urllib.errorr!   r   r   urlutilsr   reportbug.exceptionsr   debian.deb822r   debianr   r   rC   r   r   r<   rH   rW    r   r   <module>r_      sR   0    
 ! !E6=20Pf/d 6:8<*0Cr   