HEX
Server: Apache/2.4.65 (Debian)
System: Linux kubikelcreative 5.10.0-35-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64
User: www-data (33)
PHP: 8.4.13
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/apt/__pycache__/package.cpython-39.pyc
a

?��`
��@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
ddlmZddlmZmZmZmZmZmZmZmZmZmZmZddlZddlZddlm Z m!Z!dd	lm"Z#d
Z$dd�Z%Gd
d�de&�Z'Gdd�de'�Z(Gdd�de)�Z*Gdd�dee*�Z+Gdd�de)�Z,Gdd�deeef�Z-Gdd�de)�Z.Gdd�dee.�Z/Gdd�de)�Z0edd ��Z1e2d!k�r�e1�dS)"z"Functionality related to packages.�)�print_functionN)�
BadStatusLine)�	HTTPError)�urlopen)�Any�Iterable�Iterator�List�Optional�Set�Tuple�Union�
no_type_check�Mapping�Sequence)�AcquireProgress�InstallProgress)�gettext)�BaseDependency�
Dependency�Origin�Package�Record�Version�VersionListcCsXtj�|�rTtj�|�|krTt|�� }t�|�j|kWd�S1sJ0YdS)z(Return ``True`` if the file is the same.NF)�os�path�exists�getsize�open�apt_pkgZHashes�hashes)r�sizer!Zfobj�r#�-/usr/lib/python3/dist-packages/apt/package.py�
_file_is_same6s
.r%c@seZdZdZdS)�
FetchErrorz(Raised when a file could not be fetched.N��__name__�
__module__�__qualname__�__doc__r#r#r#r$r&?sr&c@seZdZdZdS)�UntrustedErrorz/Raised when a file did not have a trusted hash.Nr'r#r#r#r$r,Csr,c@s�eZdZdZGdd�de�Zdd�Zdd�Zdd	�Ze	d
d��Z
e	dd
��Ze	dd��Ze	dd��Z
e	dd��Ze	dd��Ze	dd��Ze	dd��Ze	dd��ZdS)rzA single dependency.c@s eZdZdZdd�Zdd�ZdS)zBaseDependency.__dstraQCompare helper for compatibility with old third-party code.

        Old third-party code might still compare the relation with the
        previously used relations (<<,<=,==,!=,>=,>>,) instead of the curently
        used ones (<,<=,=,!=,>=,>,). This compare helper lets < match to <<,
        > match to >> and = match to ==.
        cCs`t�||�rdSt�|d�r(t�d|�St�|d�r@t�d|�St�|d�rXt�d|�SdSdS)	NT�<z<<�>z>>�=z==F)�str�__eq__��self�otherr#r#r$r1SszBaseDependency.__dstr.__eq__cCs|�|�S�N)r1r2r#r#r$�__ne__`szBaseDependency.__dstr.__ne__N)r(r)r*r+r1r6r#r#r#r$�__dstrJs
r7cCs||_||_dSr5)�_version�_dep)r3�version�depr#r#r$�__init__dszBaseDependency.__init__cCsd|j|jfS�Nz%s: %s��rawtype�rawstr�r3r#r#r$�__str__iszBaseDependency.__str__cCsd|j|j|j|jfS)Nz;<BaseDependency: name:%r relation:%r version:%r rawtype:%r>)�name�relationr:r?rAr#r#r$�__repr__ms�zBaseDependency.__repr__cCs
|jjjS)zThe name of the target package.)r9Z
target_pkgrCrAr#r#r$rCrszBaseDependency.namecCs|�|jj�S)z�The relation (<, <=, =, !=, >=, >, '') in mathematical notation.

        The empty string will be returned in case of an unversioned dependency.
        )�_BaseDependency__dstrr9Z	comp_typerAr#r#r$rDxszBaseDependency.relationcCs|jjS)avThe relation (<<, <=, =, !=, >=, >>, '') in Debian notation.

        The empty string will be returned in case of an unversioned dependency.
        For more details see the Debian Policy Manual on the syntax of
        relationship fields:
        https://www.debian.org/doc/debian-policy/ch-relationships.html#s-depsyntax  # noqa

        .. versionadded:: 1.0.0
        )r9Z
comp_type_debrAr#r#r$�relation_deb�szBaseDependency.relation_debcCs|jjS)z�The target version or an empty string.

        Note that the version is only an empty string in case of an unversioned
        dependency. In this case the relation is also an empty string.
        )r9Z
target_verrAr#r#r$r:�szBaseDependency.versioncCsJg}|j��}|D]2}|j}|jjj}|�|�}t||�}|�|�q|S)zfA list of all Version objects which satisfy this dependency.

        .. versionadded:: 1.0.0
        )	r9Zall_targetsZ
parent_pkgr8�package�_pcacheZ_rawpkg_to_pkgr�append)r3�tversZ_tversZ_tver�_pkg�cache�pkg�tverr#r#r$�target_versions�s



zBaseDependency.target_versionscCsdd�|jD�S)�iA list of all installed Version objects which satisfy this dep.

        .. versionadded:: 1.0.0
        cSsg|]}|jr|�qSr#��is_installed��.0rOr#r#r$�
<listcomp>��z<BaseDependency.installed_target_versions.<locals>.<listcomp>�rPrAr#r#r$�installed_target_versions�sz(BaseDependency.installed_target_versionscCs$|jrd|j|j|jfS|jSdS)a�String represenation of the dependency.

        Returns the string representation of the dependency as it would be
        written in the debian/control file.  The string representation does not
        include the type of the dependency.

        Example for an unversioned dependency:
          python3

        Example for a versioned dependency:
          python3 >= 3.2

        .. versionadded:: 1.0.0
        z%s %s %sN)r:rCrGrAr#r#r$r@�szBaseDependency.rawstrcCs|jjS)z�Type of the dependency.

        This should be one of 'Breaks', 'Conflicts', 'Depends', 'Enhances',
        'PreDepends', 'Recommends', 'Replaces', 'Suggests'.

        Additional types might be added in the future.
        �r9Zdep_type_untranslatedrAr#r#r$r?�s
zBaseDependency.rawtypecCs|jjdkS)zWhether this is a PreDepends.�
PreDependsrZrAr#r#r$�
pre_depend�szBaseDependency.pre_dependN)r(r)r*r+r0rFr<rBrE�propertyrCrDrGr:rPrYr@r?r\r#r#r#r$rGs.




	



rcsleZdZdZ�fdd�Zdd�Zdd�Zedd	��Zed
d��Z	edd
��Z
edd��Zedd��Z�Z
S)raMRepresent an Or-group of dependencies.

    Attributes defined here:
        or_dependencies - The possible choices
        rawstr - String represenation of the Or-group of dependencies
        rawtype - The type of the dependencies in the Or-group
        target_version - A list of Versions which satisfy this Or-group of deps
    cs tt|��|�||_||_dSr5)�superrr<r8�_rawtype)r3r:�	base_depsr?��	__class__r#r$r<�szDependency.__init__cCsd|j|jfSr=r>rAr#r#r$rB�szDependency.__str__cCsdd�dd�|D��S)Nz<Dependency: [%s]>�, css|]}t|�VqdSr5)�repr�rU�bdr#r#r$�	<genexpr>�rWz&Dependency.__repr__.<locals>.<genexpr>��joinrAr#r#r$rE�szDependency.__repr__cCs|Sr5r#rAr#r#r$�or_dependencies�szDependency.or_dependenciescCsd�dd�|D��S)axString represenation of the Or-group of dependencies.

        Returns the string representation of the Or-group of dependencies as it
        would be written in the debian/control file.  The string representation
        does not include the type of the Or-group of dependencies.

        Example:
          python2 >= 2.7 | python3

        .. versionadded:: 1.0.0
        z | css|]}|jVqdSr5)r@rer#r#r$rgrWz$Dependency.rawstr.<locals>.<genexpr>rhrAr#r#r$r@�szDependency.rawstrcCs|jS)aType of the Or-group of dependency.

        This should be one of 'Breaks', 'Conflicts', 'Depends', 'Enhances',
        'PreDepends', 'Recommends', 'Replaces', 'Suggests'.

        Additional types might be added in the future.

        .. versionadded:: 1.0.0
        )r_rAr#r#r$r?	szDependency.rawtypecCs0g}|D]"}|jD]}||vr|�|�qq|S)zlA list of all Version objects which satisfy this Or-group of deps.

        .. versionadded:: 1.0.0
        )rPrJ)r3rKrfrOr#r#r$rPs
zDependency.target_versionscCsdd�|jD�S)rQcSsg|]}|jr|�qSr#rRrTr#r#r$rV,rWz8Dependency.installed_target_versions.<locals>.<listcomp>rXrAr#r#r$rY%sz$Dependency.installed_target_versions)r(r)r*r+r<rBrEr]rjr@r?rPrY�
__classcell__r#r#rar$r�s	





rc@s eZdZdZdd�Zdd�ZdS)ra�The origin of a version.

    Attributes defined here:
        archive   - The archive (eg. unstable)
        component - The component (eg. main)
        label     - The Label, as set in the Release file
        origin    - The Origin, as set in the Release file
        codename  - The Codename, as set in the Release file
        site      - The hostname of the site.
        trusted   - Boolean value whether this is trustworthy.
    cCsb|j|_|j|_|j|_|j|_|j|_|j|_|j|_|jj�	|�}|rX|j
rXd|_nd|_dS�NTF)�archive�	component�label�originZcodename�siteZ
not_automaticrI�_list�
find_index�
is_trusted�trusted)r3rN�packagefile�	indexfiler#r#r$r<<s
zOrigin.__init__cCs d|j|j|j|j|j|jfS)NzH<Origin component:%r archive:%r origin:%r label:%r site:%r isTrusted:%r>)rnrmrprorqrurAr#r#r$rELs��zOrigin.__repr__N)r(r)r*r+r<rEr#r#r#r$r/src@sbeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
ddd�Zdd�Zdd�Z
dS)ra"Record in a Packages file

    Represent a record as stored in a Packages file. You can use this like
    a dictionary mapping the field names of the record to their values::

        >>> record = Record("Package: python-apt\nVersion: 0.8.0\n\n")
        >>> record["Package"]
        'python-apt'
        >>> record["Version"]
        '0.8.0'

    For example, to get the tasks of a package from a cache, you could do::

        package.candidate.record["Tasks"].split()

    Of course, you can also use the :attr:`Version.tasks` property.

    cCst�|�|_dSr5)r Z
TagSection�_rec)r3Z
record_strr#r#r$r<hszRecord.__init__cCs
t|j�Sr5)�hashrxrAr#r#r$�__hash__lszRecord.__hash__cCs
t|j�Sr5)r0rxrAr#r#r$rBpszRecord.__str__cCs
|j|Sr5�rx�r3�keyr#r#r$�__getitem__tszRecord.__getitem__cCs
||jvSr5r{r|r#r#r$�__contains__xszRecord.__contains__cCst|j���Sr5)�iterrx�keysrAr#r#r$�__iter__|szRecord.__iter__ccs$|j��D]}||j|fVq
dS)z6An iterator over the (key, value) items of the record.N)rxr�r|r#r#r$�	iteritems�szRecord.iteritemsNcCs|j�||�S)zReturn record[key] if key in record, else *default*.

        The parameter *default* must be either a string or None.
        )rx�get�r3r}�defaultr#r#r$r��sz
Record.getcCs
||jvS)z deprecated form of ``key in x``.r{r|r#r#r$�has_key�szRecord.has_keycCs
t|j�Sr5)�lenrxrAr#r#r$�__len__�szRecord.__len__)N)r(r)r*r+r<rzrBr~rr�r�r�r�r�r#r#r#r$rTs
rc@seZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zedd��Zedd��Zedd��Zedd��Zed d!��Zed"d#��Zed$d%��Zed&d'��Zed(d)��Zed*d+��Zed,d-��Zed.d/��Zed0d1��Zed2d3��Zed4d5��Zed6d7��Zed8d9��Z ed:d;��Z!d<d=�Z"ed>d?��Z#ed@dA��Z$edBdC��Z%edDdE��Z&edFdG��Z'edHdI��Z(edJdK��Z)edLdM��Z*edNdO��Z+edPdQ��Z,edRdS��Z-dTdU�Z.edVdW��Z/edXdY��Z0dad\d]�Z1dbd_d`�Z2d[S)crz�Representation of a package version.

    The Version class contains all information related to a
    specific package version.

    .. versionadded:: 0.7.9
    cCs ||_||_|jjj�|�dSr5)rH�_candrIZ
_weakversions�add)r3rH�candr#r#r$r<�szVersion.__init__cCs�z@|jj}|jj}||kr WdS||kr.WdSt�|jj|j�WSty�zt�|jj|�WYSty~t	YYS0Yn0dS)a:Compares against another apt.Version object or a version string.

        This method behaves like Python 2's cmp builtin and returns an integer
        according to the outcome.  The return value is negative in case of
        self < other, zero if self == other and positive if self > other.

        The comparison includes the package name and architecture if other is
        an apt.Version object.  If other isn't an apt.Version object it'll be
        assumed that other is a version string (without package name/arch).

        .. versionchanged:: 1.0.0
        ����N)
rH�fullnamer �version_comparer��ver_strr:�AttributeError�	TypeError�NotImplemented)r3r4Z	self_nameZ
other_namer#r#r$�_cmp�szVersion._cmpcCs|�|�dkS�Nr�r�r2r#r#r$r1�szVersion.__eq__cCs|�|�dkSr�r�r2r#r#r$�__ge__�szVersion.__ge__cCs|�|�dkSr�r�r2r#r#r$�__gt__�szVersion.__gt__cCs|�|�dkSr�r�r2r#r#r$�__le__�szVersion.__le__cCs|�|�dkSr�r�r2r#r#r$�__lt__�szVersion.__lt__cCs,z|�|�dkWSty&tYS0dSr�)r�r�r�r2r#r#r$r6�szVersion.__ne__cCs|jjSr5)r�ryrAr#r#r$rz�szVersion.__hash__cCsd|jj|jfS)Nz%s=%s�rHrCr:rAr#r#r$rB�szVersion.__str__cCsd|jj|jfS)Nz <Version: package:%r version:%r>r�rAr#r#r$rE�s�zVersion.__repr__cCs*|jjj�|jjd�s td��|jjjS)z=Internal helper that moves the Records to the right position.rzCould not lookup record)rHrI�_records�lookupr��	file_list�LookupErrorrAr#r#r$r��szVersion._recordscCs.|jj}|jjj�|j�d��r*|jjjSdS)z2Internal helper to get the translated description.rN)r�Ztranslated_descriptionrHrIr�r�r��pop)r3Z	desc_iterr#r#r$�_translated_records�s
zVersion._translated_recordscCs|jjS)z.Return the size of the package when installed.)r��installed_sizerAr#r#r$r�szVersion.installed_sizecCs|jjS)z$Return the homepage for the package.)r��homepagerAr#r#r$r�szVersion.homepagecCs|jjS)zReturn the size of the package.)r�r"rAr#r#r$r"szVersion.sizecCs|jjS)z/Return the architecture of the package version.)r�ZarchrAr#r#r$�architectureszVersion.architecturecCst|jj�S)z:Return whether the version of the package is downloadable.)�boolr��downloadablerAr#r#r$r�szVersion.downloadablecCs |jj}|duo|jj|jjkS)zkReturn wether this version of the package is currently installed.

        .. versionadded:: 1.0.0
        N)rH�	installedr��id)r3Zinst_verr#r#r$rSszVersion.is_installedcCs|jjS)zReturn the version as a string.)r�r�rAr#r#r$r:(szVersion.versioncCs|j}|dur|jSdS)z0Return the short description (one line summary).N)r�Z
short_desc)r3�recordsr#r#r$�summary.szVersion.summarycCs|jjS)z"return the long description (raw).)r��	long_descrAr#r#r$�raw_description5szVersion.raw_descriptioncCs|jjS)z"Return the section of the package.)r��sectionrAr#r#r$r�;szVersion.sectionc
CsBd}|j}|dur|jnd}|s0td�|jjSzt|t�sF|�d�}Wn8ty�}z td�|jj|fWYd}~Sd}~00t	|�
d��}t|�|D]�}|��dkr�|�
d�s�|d7}q�|�d	��r�|�
d�s�d
|dd�}nd|dd�}n:|�d
��r0|�
d��s|dk�r*|dd�}n|}n|}||7}q�|S)z�Return the formatted long description.

        Return the formatted long description according to the Debian policy
        (Chapter 5.6.13).
        See http://www.debian.org/doc/debian-policy/ch-controlfields.html
        for more information.
        �Nz+Missing description for '%s'.Please report.�utf-8z<Invalid unicode in description for '%s' (%s). Please report.�
�.z

z  z
%s
�z%s
� r�)r�r��_rHrC�
isinstancer0�decode�UnicodeDecodeErrorr��split�next�strip�endswith�
startswith)r3Zdescr��dsc�err�linesZraw_line�liner#r#r$�descriptionAs@
�

�


zVersion.descriptioncCs2z|jjp|jjWSty,|jjYS0dS)z&Return the name of the source package.N)r��
source_pkgrH�	shortname�
IndexErrorrAr#r#r$�source_namewszVersion.source_namecCs2z|jjp|jjWSty,|jjYS0dS)z)Return the version of the source package.N)r��
source_verr�r�r�rAr#r#r$�source_version�szVersion.source_versioncCs|jjS)z.Return the priority of the package, as string.)r�Zpriority_strrAr#r#r$�priority�szVersion.prioritycCs|jjjj�|j�S)z�Return the internal policy priority as a number.
           See apt_preferences(5) for more information about what it means.
        )rHrI�	_depcacheZpolicyZget_priorityr�rAr#r#r$�policy_priority�szVersion.policy_prioritycCst|jj�S)z�Return a Record() object for this version.

        Return a Record() object for this version which provides access
        to the raw attributes of the candidate version
        )rr��recordrAr#r#r$r��szVersion.recordc	Gspg}|jj}|D]Z}zB||D]4}g}|D]}|�t||��q*|�t|||��qWqtyhYq0q|S)a(Return a list of Dependency objects for the given types.

        Multiple types can be specified. Possible types are:
        'Breaks', 'Conflicts', 'Depends', 'Enhances', 'PreDepends',
        'Recommends', 'Replaces', 'Suggests'

        Additional types might be added in the future.
        )r��depends_listrJrr�KeyError)r3�typesr�Zdepends�type_Zdep_ver_listr`Zdep_orr#r#r$�get_dependencies�s
zVersion.get_dependenciescCsdd�|jjD�S)z3 Return a list of names that this version provides.cSsg|]}|d�qS)rr#)rU�pr#r#r$rV�rWz$Version.provides.<locals>.<listcomp>)r�Z
provides_listrAr#r#r$�provides�szVersion.providescCs
|�d�S)z4Return the list of enhances for the package version.ZEnhances�r�rAr#r#r$�enhances�szVersion.enhancescCs|�dd�S)z/Return the dependencies of the package version.r[ZDependsr�rAr#r#r$�dependencies�szVersion.dependenciescCs
|�d�S)z-Return the recommends of the package version.Z
Recommendsr�rAr#r#r$�
recommends�szVersion.recommendscCs
|�d�S)z+Return the suggests of the package version.ZSuggestsr�rAr#r#r$�suggests�szVersion.suggestscCs,g}|jjD]\}}|�t|j|��q|S)z1Return a list of origins for the package version.)r�r�rJrrH)r3�originsrv�_unusedr#r#r$r��szVersion.originscCs|jjS)zZReturn the path to the file inside the archive.

        .. versionadded:: 0.7.10
        )r��filenamerAr#r#r$r��szVersion.filenamecCs|jjS)zKReturn the md5sum of the binary.

        .. versionadded:: 0.7.10
        )r�Zmd5_hashrAr#r#r$�md5�szVersion.md5cCs|jjS)zLReturn the sha1sum of the binary.

        .. versionadded:: 0.7.10
        )r�Z	sha1_hashrAr#r#r$�sha1�szVersion.sha1cCs|jjS)zNReturn the sha256sum of the binary.

        .. versionadded:: 0.7.10
        )r�Zsha256_hashrAr#r#r$�sha256�szVersion.sha256cCst|jd���S)z�Get the tasks of the package.

        A set of the names of the tasks this package belongs to.

        .. versionadded:: 0.8.0
        ZTask)�setr�r�rAr#r#r$�taskss	z
Version.tasksccs:|jjD],\}}|jjj�|�}|r|�|jj�VqdS)zVReturn an iterator over all available urls.

        .. versionadded:: 0.7.10
        N)	r�r�rHrIrrrs�archive_urir�r�)r3rvr�rwr#r#r$�_urissz
Version._uriscCst|���S)z^Return a list of all available uris for the binary.

        .. versionadded:: 0.7.10
        )�listr�rAr#r#r$�urisszVersion.uriscCs,ztt|����WSty&YdS0dS)zNReturn a single URI for the binary.

        .. versionadded:: 0.7.10
        N)r�r�r��
StopIterationrAr#r#r$�uri"szVersion.urir�NcCs@|durtj�dd�}tj�|jj�}tj�||�}t	||j
|jj�r`t�
d|�tj�|�S|jjd\}}|jjj�|�}|s�|r�|js�td|jj|jt|dd�f��|js�td	��|jj}	|s�|	js�td
|��t�|p�tjj �!��}
tj"|
|j|	|j
||d�}|
�#�|j$|j%k�r4t&d|j'|j(f��tj�|�S)
aCFetch the binary version of the package.

        The parameter *destdir* specifies the directory where the package will
        be fetched to.

        The parameter *progress* may refer to an apt_pkg.AcquireProgress()
        object. If not specified or None, apt.progress.text.AcquireProgress()
        is used.

        The keyword-only parameter *allow_unauthenticated* specifies whether
        to allow unauthenticated downloads. If not specified, it defaults to
        the configuration option `APT::Get::AllowUnauthenticated`.

        .. versionadded:: 0.7.10
        N�APT::Get::AllowUnauthenticatedF�"Ignoring already existing file: %sr�>Could not fetch %s %s source package: Source %r is not trusted�describez<unkown>zNo URI for this binary.�8The item %r could not be fetched: No trusted hash found.��destfile�$The item %r could not be fetched: %s))r �config�find_brr�basenamer�r�rir%r"r!�logging�debug�abspathr�r�rHrIrrrsrtr,rCr:�getattrr��
ValueError�usable�Acquire�apt�progress�textr�AcquireFile�run�status�	STAT_DONEr&r��
error_text)r3�destdirr��allow_unauthenticated�baser�Zpfile�offset�indexr!�acqZacqfiler#r#r$�fetch_binary.sD�

��
��
�zVersion.fetch_binaryTcCs|durtj�dd�}t��}t�|p0tjj���}d}|j	}|j
pJ|jj}	|j
pX|jj}
|�|	�}|r~|
|jkr~|�|	�}qd|s�td|��t�}|s�|jjs�td|jj|j|jjf��|jD]�}
tj�|
j�}tj�||�}|
jdkr�|}t||
j |
j!��rt"�#d|�q�|�s.|
j!j$�s.td|��|�%tj&||j�'|
j�|
j!|
j ||d	��q�|�(�|du�rxtd|��|j)D](}|j*|j+k�r~t,d
|j-|j.f���q~|�r�|jdt�/|j�}tj�||�}t0�1dd
||g�tj�2|�Stj�2|�SdS)a9Get the source code of a package.

        The parameter *destdir* specifies the directory where the source will
        be fetched to.

        The parameter *progress* may refer to an apt_pkg.AcquireProgress()
        object. If not specified or None, apt.progress.text.AcquireProgress()
        is used.

        The parameter *unpack* describes whether the source should be unpacked
        (``True``) or not (``False``). By default, it is unpacked.

        If *unpack* is ``True``, the path to the extracted directory is
        returned. Otherwise, the path to the .dsc file is returned.

        The keyword-only parameter *allow_unauthenticated* specifies whether
        to allow unauthenticated downloads. If not specified, it defaults to
        the configuration option `APT::Get::AllowUnauthenticated`.
        Nr�FzNo source for %rr�r�r�r�r�r��-zdpkg-sourcez-x)3r r�r��
SourceRecordsr�r�r�r�rr�r�rHr�r�r�r�r�r:r�r�rrtr,rCr��filesrrr�ri�typer%r"r!r�r�r�rJr�r�r��itemsr�r�r&r�rZupstream_version�
subprocessZ
check_callr�)r3rr�Zunpackr�srcrr�r�r�r�Z
source_lookupr
Zfilrr��itemZoutdirr#r#r$�fetch_sourcedsh�

��

�
�



�
zVersion.fetch_source)r�NN)r�NTN)3r(r)r*r+r<r�r1r�r�r�r�r6rzrBrEr]r�r�r�r�r"r�r�rSr:r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr#r#r#r$r�s�
	






	




5




	













�
6�rc@sdeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zddd�Z
dS)ra�Provide a mapping & sequence interface to all versions of a package.

    This class can be used like a dictionary, where version strings are the
    keys. It can also be used as a sequence, where integers are the keys.

    You can also convert this to a dictionary or a list, using the usual way
    of dict(version_list) or list(version_list). This is useful if you need
    to access the version objects multiple times, because they do not have to
    be recreated this way.

    Examples ('package.versions' being a version list):
        '0.7.92' in package.versions # Check whether 0.7.92 is a valid version.
        package.versions[0] # Return first version or raise IndexError
        package.versions[0:2] # Return a new VersionList for objects 0-2
        package.versions['0.7.92'] # Return version 0.7.92 or raise KeyError
        package.versions.keys() # All keys, as strings.
        max(package.versions)
    NcCs$||_|jj|_|r |j||_dSr5)�_packagerLZversion_list�	_versions)r3rHZslice_r#r#r$r<�s
zVersionList.__init__cCszt|t�r|�|j|�Szt|j|j|�WStyh|jD]"}|j|kr@t|j|�YSq@Yn0td|��dS)NzVersion: %r not found.)	r��slicerbrrrr�r�r��r3r�verr#r#r$r~�s


zVersionList.__getitem__cCsdd�dd�|D��S)Nz[%s]rccss|]}t|�VqdSr5)r0�rUrr#r#r$rg�rWz&VersionList.__str__.<locals>.<genexpr>rhrAr#r#r$rB�szVersionList.__str__cCsd|��S)Nz<VersionList: %r>)r�rAr#r#r$rE�szVersionList.__repr__cs�fdd��jD�S)z*Return an iterator over all value objects.c3s|]}t�j|�VqdSr5)rrrrAr#r$rg�rWz'VersionList.__iter__.<locals>.<genexpr>�rrAr#rAr$r��szVersionList.__iter__cCs0t|t�r|j}|jD]}|j|krdSqdSrl)r�rr:rr�rr#r#r$r�s


zVersionList.__contains__cCst|�t|�kSr5)r�r2r#r#r$r1�szVersionList.__eq__cCs
t|j�Sr5)r�rrAr#r#r$r��szVersionList.__len__cCsdd�|jD�S)z*Return a list of all versions, as strings.cSsg|]
}|j�qSr#)r�rr#r#r$rVrWz$VersionList.keys.<locals>.<listcomp>rrAr#r#r$r�szVersionList.keyscCs&z
||WSty |YS0dS)zReturn the key or the default.N)r�r�r#r#r$r�s
zVersionList.get)N)N)r(r)r*r+r<r~rBrEr�rr1r�r�r�r#r#r#r$r�s

rc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zed
d��Z	e	j
dd��Z	ed
d��Zedd��Zedd��Z
edd��Zedd��Zedd��Zdd�Zedd��Zedd��Zedd ��Zed!d"��Zed#d$��Zed%d&��Zed'd(��Zed)d*��Zed+d,��Zed-d.��Zed/d0��ZdJd2d3�Zed4d5��Zed6d7��Zed8d9��Z ed:d;��Z!d<d=�Z"dKd@dA�Z#dLdBdC�Z$dMdDdE�Z%dNdFdG�Z&dHdI�Z'd1S)Orz�Representation of a package in a cache.

    This class provides methods and properties for working with a package. It
    lets you mark the package for installation, check if it is installed, and
    much more.
    cCs||_||_d|_dS)z Init the Package object r�N)rLrI�
_changelog)r3ZpcacheZpkgiterr#r#r$r<szPackage.__init__cCs|jSr5�rCrAr#r#r$rBszPackage.__str__cCsd|jj|jj|jjfS)Nz(<Package: name:%r architecture=%r id:%r>)rLrCr�r�rAr#r#r$rE"s�zPackage.__repr__cCs|j|jkSr5rr2r#r#r$r�'szPackage.__lt__cCs&|jj�|j�}|dur"t||�SdS)z�Return the candidate version of the package.

        This property is writeable to allow you to set the candidate version
        of the package. Just assign a Version() object, and it will be set as
        the candidate version.
        N)rIr�Zget_candidate_verrLr)r3r�r#r#r$�	candidate+s	
zPackage.candidatecCs,|j��|jj�|j|j�|j��dS)z)Set the candidate version of the package.N)rI�cache_pre_changer�Zset_candidate_verrLr��cache_post_change)r3r:r#r#r$r9s
cCs|jjdurt||jj�SdS)z`Return the currently installed version of the package.

        .. versionadded:: 0.7.9
        N)rL�current_verrrAr#r#r$r�AszPackage.installedcCs|j�d�S)a}Return the name of the package, possibly including architecture.

        If the package is not part of the system's preferred architecture,
        return the same as :attr:`fullname`, otherwise return the same
        as :attr:`shortname`

        .. versionchanged:: 0.7.100.3

        As part of multi-arch, this field now may include architecture
        information.
        T�rLZget_fullnamerAr#r#r$rCLszPackage.namecCs|j�d�S)z�Return the name of the package, including architecture.

        Note that as for :meth:`architecture`, this returns the
        native architecture for Architecture: all packages.

        .. versionadded:: 0.7.100.3FrrAr#r#r$r�\s	zPackage.fullnamecCs|jjS)zZReturn the name of the package, without architecture.

        .. versionadded:: 0.7.100.3)rLrCrAr#r#r$r�gszPackage.shortnamecCs|jjS)znReturn a uniq ID for the package.

        This can be used eg. to store additional information about the pkg.)rLr�rAr#r#r$r�osz
Package.idcCs|jjS)z>Return True if the package is an essential part of the system.)rL�	essentialrAr#r#r$rwszPackage.essentialcCs|jjS)aReturn the Architecture of the package.

        Note that for Architecture: all packages, this returns the
        native architecture, as they are internally treated like native
        packages. To get the concrete architecture, look at the
        :attr:`Version.architecture` attribute.

        .. versionchanged:: 0.7.100.3
            This is now the package's architecture in the multi-arch sense,
            previously it was the architecture of the candidate version
            and deprecated.
        )rLr�rAr#r#r$r�}szPackage.architecturecCs|jj�|j�S)z5Return ``True`` if the package is marked for install.)rIr��marked_installrLrAr#r#r$r �szPackage.marked_installcCs|jj�|j�S)z5Return ``True`` if the package is marked for upgrade.)rIr��marked_upgraderLrAr#r#r$r!�szPackage.marked_upgradecCs|jj�|j�S)z4Return ``True`` if the package is marked for delete.)rIr��
marked_deleterLrAr#r#r$r"�szPackage.marked_deletecCs|jj�|j�S)z2Return ``True`` if the package is marked for keep.)rIr��marked_keeprLrAr#r#r$r#�szPackage.marked_keepcCs|jj�|j�S)z! Package is marked for downgrade )rIr��marked_downgraderLrAr#r#r$r$�szPackage.marked_downgradecCs|jj�|j�S)z7Return ``True`` if the package is marked for reinstall.)rIr��marked_reinstallrLrAr#r#r$r%�szPackage.marked_reinstallcCs|jjduS)z,Return ``True`` if the package is installed.N)rLrrAr#r#r$rS�szPackage.is_installedcCs|jo|jj�|j�S)z-Return ``True`` if the package is upgradable.)rSrIr��
is_upgradablerLrAr#r#r$r&�s�zPackage.is_upgradablecCs|js|jo|jj�|j�S)z�Return ``True`` if the package is no longer required.

        If the package has been installed automatically as a dependency of
        another package, and if no packages depend on it anymore, the package
        is no longer required.
        )rSr rIr�Z
is_garbagerLrAr#r#r$�is_auto_removable�s	�zPackage.is_auto_removablecCs|jj�|j�S)z@Return whether the package is marked as automatically installed.)rIr��is_auto_installedrLrAr#r#r$r(�szPackage.is_auto_installedc	Cs~|j|jfD]l}d|}zHt|d��*}|���d��d�Wd�WS1sT0YWqtyvYqYq0qgS)z�Return a list of files installed by the package.

        Return a list of unicode names of the files which have
        been installed by this package
        z/var/lib/dpkg/info/%s.list�rbr�r�N)rCr�r�readr�r��EnvironmentError)r3rCrr�r#r#r$�installed_files�s<zPackage.installed_filesNc	Cs�|jdkr|jS|jstd�S|durv|jjdjdkr>d}n8|jjdjdkrVd}n td�}t|t�rl|S|�d	�S|jj}d
}|jj	}|jj
}zt��}Wnt
y�YnT0|�|��r|js�q�|jj
|jkr�|j}|j	}�qt�|j|�dkr�|j}|j	}q�|�dd�}	t|	�dk�r&|	d}~	|d}
|�d
��rHd
|d}
|�dd�}t|�dk�rtd�|dd��}~|||
||d�}t��}�z2�zLt�d�|�r�|���r�WWt�|�dSt|�}
d}dt�|�}|�r|���rWWt�|�dS|
��}|�s�q�|�d	�}t�||�}|�r�t|jdd�}|�r\d|v�r\|�dd�d}|� d�}|�r�d|v�r�|�dd�d}|�r�t�||�dk�r��q�||7}�q�t|�dk�r�td�}t|t��s�|�d	�}||_Wn�t!�y^|jjdjdk�rtd�||f}ntd�}t|t��r@|YWt�|�S|�d	�YWt�|�SYnZt"t#f�y�td�}t|t��r�|YWt�|�S|�d	�YWt�|�SYn0Wt�|�nt�|�0|jS)a�
        Download the changelog of the package and return it as unicode
        string.

        The parameter *uri* refers to the uri of the changelog file. It may
        contain multiple named variables which will be substitued. These
        variables are (src_section, prefix, src_pkg, src_ver). An example is
        the Ubuntu changelog::

            "http://changelogs.ubuntu.com/changelogs/pool" \
                "/%(src_section)s/%(prefix)s/%(src_pkg)s" \
                "/%(src_pkg)s_%(src_ver)s/changelog"

        The parameter *cancel_lock* refers to an instance of threading.Event,
        which if set, prevents the download.
        r�z$The list of changes is not availableNrZDebianzshttp://packages.debian.org/changelogs/pool/%(src_section)s/%(prefix)s/%(src_pkg)s/%(src_pkg)s_%(src_ver)s/changelogZUbuntuzuhttp://changelogs.ubuntu.com/changelogs/pool/%(src_section)s/%(prefix)s/%(src_pkg)s/%(src_pkg)s_%(src_ver)s/changelogr��main�/r��lib��:)�src_section�prefix�src_pkg�src_verr�z^%s \((.*)\)(.*)$r:z�The list of changes is not available yet.

Please use http://launchpad.net/ubuntu/+source/%s/%s/+changelog
until the changes become available or try again later.zOFailed to download the list of changes. 
Please check your Internet connection.)$rrr�r�rpr�r0r�r�r�r�r r	�SystemErrorr�r:r�r�r�r�ri�socketZgetdefaulttimeoutZsetdefaulttimeoutZis_setr�re�escape�readline�matchr�r��groupr�IOErrorr)r3r�Zcancel_lock�resr4r2r�r5Zsrc_recordsZ
section_splitr3Z
src_ver_splitZtimeoutZchangelog_fileZ	changelogZregexpZline_rawr�r;r�Z
changelog_verr#r#r$�
get_changelog�s�


�
A
�8
�


��

�
�	
�
�
�
zPackage.get_changelogcCst|�S)zcReturn a VersionList() object for all available versions.

        .. versionadded:: 0.7.9
        )rrAr#r#r$�versions�szPackage.versionscCs|jj�|j�S)z5Return True if the to-be-installed package is broken.)rIr��is_inst_brokenrLrAr#r#r$rA�szPackage.is_inst_brokencCs|jj�|j�S)z/Return True if the installed package is broken.)rIr��
is_now_brokenrLrAr#r#r$rB�szPackage.is_now_brokencCs|jjtjkS)z8Checks whether the package is is the config-files state.)rLZ
current_stater ZCURSTATE_CONFIG_FILESrAr#r#r$�has_config_files�szPackage.has_config_filescCs(|j��|jj�|j�|j��dS)zMark a package for keep.N)rIrr��	mark_keeprLrrAr#r#r$rD�s
zPackage.mark_keepTFcCsv|j��|jj�|j|�|rh|jjjdkrht�|jj�}|�|j�|�	|j�|�
|j�|��|j��dS)a+Mark a package for deletion.

        If *auto_fix* is ``True``, the resolver will be run, trying to fix
        broken packages.  This is the default.

        If *purge* is ``True``, remove the configuration files of the package
        as well.  The default is to keep the configuration.
        rN)
rIrr��mark_deleterL�broken_countr �ProblemResolver�clear�protect�remove�resolver)r3�auto_fix�purgeZfixr#r#r$rE�s

zPackage.mark_deletecCsn|j��|jj�|j||�|r`|jjjdkr`t�|jj�}|�|j�|�	|j�|�
d�|j��dS)a0Mark a package for install.

        If *autoFix* is ``True``, the resolver will be run, trying to fix
        broken packages.  This is the default.

        If *autoInst* is ``True``, the dependencies of the packages will be
        installed automatically.  This is the default.

        If *fromUser* is ``True``, this package will not be marked as
        automatically installed. This is the default. Set it to False if you
        want to be able to automatically remove the package at a later stage
        when no other package depends on it.
        rTN)rIrr��mark_installrLrFr rGrHrIrKr)r3rLZ	auto_inst�	from_userZfixerr#r#r$rN�s

zPackage.mark_installcCs<|jr$|j}|j|d�|�|�ntj�d|jj�dS)zMark a package for upgrade.)rOz4MarkUpgrade() called on a non-upgradeable pkg: '%s'
N)	r&r(rN�	mark_auto�sys�stderr�writerLrC)r3rO�autor#r#r$�mark_upgrade�s�zPackage.mark_upgradecCs|jj�|j|�dS)aMark a package as automatically installed.

        Call this function to mark a package as automatically installed. If the
        optional parameter *auto* is set to ``False``, the package will not be
        marked as automatically installed anymore. The default is ``True``.
        N)rIr�rPrL)r3rTr#r#r$rP�szPackage.mark_autocCs|jj�||�dS)aCommit the changes.

        The parameter *fprogress* refers to a apt_pkg.AcquireProgress() object,
        like apt.progress.text.AcquireProgress().

        The parameter *iprogress* refers to an InstallProgress() object, as
        found in apt.progress.base.
        N)rIr��commit)r3Z	fprogressZ	iprogressr#r#r$rV�s
zPackage.commit)NN)TF)TTT)T)T)(r(r)r*r+r<rBrEr�r]r�setterr�rCr�r�r�rr�r r!r"r#r$r%rSr&r'r(r,r?r@rArBrCrDrErNrUrPrVr#r#r#r$rsx






















/








rc
Cs�td�ddl}t��tjj��}t�|�}|d}td|j	�td|j
�td|jj�td|j
j�td	|j
j�td
|jj�td|jj�td|jj�td
|jj�td|j�td|jj�td|jj�td|jj�td|jj�td|jj�td|j
j�td|j
j�|jjD] }td�dd�|jD����qHtd|jj�td|jj�td|jj�t|d���dD]`}td|�|D]*}|j �r�|�!dd�dk�r�|�"|��q�td |j#j$�td!|j#j%��q�t�dD]�}td"|�t�|�}|�&�D]L}|�!dd�dk�r:z||�'|�Wn t(�y�td#|�Yn0�q:td |j#j$�td$|j#j)��qdS)%z
Self-test.zSelf-test for the Package modulrNz	apt-utilsz	Name: %s zID: %s zPriority (Candidate): %s zPriority (Installed): %s zInstalled: %s zCandidate: %s zCandidateDownloadable: %szCandidateOrigins: %szSourcePkg: %s zSection: %s zSummary: %szDescription (formatted) :
%szDescription (unformatted):
%szInstalledSize: %s zPackageSize: %s zDependencies: %szRecommends: %s�,css&|]}d|j|j|j|jfVqdS)z%s (%s) (%s) (%s)N)rCr:rDr\)rU�or#r#r$rg#s��z_test.<locals>.<genexpr>zarch: %szhomepage: %szrec: Z2vcard)TFz8Running install on random upgradable pkgs with AutoFix: r�zBroken: %s zInstCount: %s z.Randomly remove some packages with AutoFix: %szError trying to remove: %s z
DelCount: %s )*�print�randomr Zinitr�r�r�Z
OpProgressZCacherCr�rr�r�r:r�r�r�r�r�r�r�r�r"r�r�rirjr�r�r�r?r&ZrandintrNr�rFZ
inst_countr�rEr6Z	del_count)r[r�rMrNr;�irCr#r#r$�_testsf
�

r]�__main__)3r+Z
__future__rr�rrQr8r7r
Z	threadingZhttp.clientrZurllib.errorrZurllib.requestr�typingrrrr	r
rrr
rrrr Zapt.progress.textr�Zapt.progress.baserrrr��__all__r%�	Exceptionr&r,�objectrrrrrrrr]r(r#r#r#r$�<module>sN4	S%D!Z|
: