
    &=d!                         d dl Z d dlZddlmZ ddlmZ d dlmZ d dl	m
Z
 d dlmZ dZd	Zd
 Zd ZddZddZ	 	 	 ddZdS )    N   )utils)open_url)	NoNetwork)Deb822)debian_supportz4https://qa.debian.org/madison.php?package=%s&text=onz$http://ftp-master.debian.org/new.822c                 8    | r|sdS t          j        ||           S )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+    (  ( q)(G<<<    c                 2    t          | |          dk    r|S | S )ad  
    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#    & 1!!Hr   i386c                    t          j                    }t          | z  }|r|dd                    |          z   z  }|d|z   z  }	 t	          |||          }nL# t
          $ r i cY S t          j        j        $ r(}t          d|t          j                   i cY d}~S d}~ww xY w|si S |                    dd                                          }i }	|                    d	          D ]Z}
	 |
                    d
          \  }}}}n# t          $ r Y *w xY w|dk    r5t           j                            ||          }||	|<   [|	S )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Z11   			<!   j!#*----						  	 ll3##))++GHd##  	CJAq!QQ 	 	 	H	 == #''1--Os6   A B$B7BBB(D
DDc                    |d}	 t          t          ||          }nL# t          $ r i cY S t          j        j        $ r(}t          d|t          j                   i cY d}~S d}~ww xY w|si S i }t          j
        |          D ]O}|d         | k    rA|d         dz   |d         z   d	z   }	t          |d
                                                   ||	<   P|S )aj  
    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/   r0   r1   r2   r4   r5   r7   paraks
             r   get_newqueue_availablerI      s   4 })j'::   			<!   j!#*----						  	H &t,, 7 7>W$$^$t+d7m;cAAd9o335566HQKOs    A&A&A!A&!A&Tc                    i }t          | ||||          }	|                    |	           |r@t          j        |           }
|
| }
t	          |
||||          }	|                    |	           i }d}|D ]5}t          |||                   }|dk    r||         ||<   *|dk     r|dz  }6|o|t          |          k    }||fS )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.
    Nr   r   )r=   updater   get_source_namerI   r   len)r.   versionr/   r0   check_incomingcheck_newqueuer1   r2   availstuff
srcpackagenewnewerr<   
comparisontoo_news                   r   check_availablerX      s    P E"7GUJMME	LL *733
 J&z7E:tTTU C E  %guT{;;
>>dCII!^^QJE,#e**,G<r   )NNr   )NTTNr   )r&   urllib.errorr"   r   r   urlutilsr   reportbug.exceptionsr   debian.deb822r   debianr   r    rD   r   r   r=   rI   rX    r   r   <module>r_      s	  0 


                     
 !           ! ! ! ! ! !E5= = =2  0P P P Pf/ / / /d 6:8<*0C C C C C Cr   