
Uc           @  s  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z y4 d d l m	 Z	 d d l
 m Z d d l m Z Wn7 e k
 r d d l m	 Z	 d d l m Z m Z n Xd d l m Z m Z d d l Z d d l Z d d	 l m Z d
 d d d d d d f Z e j j d k r4e Z n  d   Z d e f d     YZ  d
 e! f d     YZ" d e# f d     YZ$ d e! f d     YZ% d e f d     YZ& d e! f d     YZ' d e f d     YZ( d e! f d     YZ) d   Z* e+ d k re*   n  d S(   s"   Functionality related to packages.i(   t   print_functionN(   t   BadStatusLine(   t	   HTTPError(   t   urlopen(   R   R   (   t   Mappingt   Sequence(   t   gettextt   BaseDependencyt
   Dependencyt   Origint   Packaget   Recordt   Versiont   VersionListi   c         C  sY   t  j j |   rU t  j j |   | k rU t |    } t j |  | k SWd QXn  d S(   s(   Return ``True`` if the file is the same.N(   t   ost   patht   existst   getsizet   opent   apt_pkgt   md5sum(   R   t   sizet   md5t   fobj(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   _file_is_same4   s    *t
   FetchErrorc           B  s   e  Z d  Z RS(   s(   Raised when a file could not be fetched.(   t   __name__t
   __module__t   __doc__(    (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR   ;   s   c           B  s   e  Z d  Z d e f d     YZ d   Z e d    Z e d    Z e d    Z	 e d    Z
 e d    Z d	   Z RS(
   s   A single dependency.t   __dstrc           B  s    e  Z d  Z d   Z d   Z RS(   sQ  Compare 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 ==.
        c         C  s   t  j |  |  r t St  j |  d  r8 t  j d |  St  j |  d  rZ t  j d |  St  j |  d  r| t  j d |  St Sd  S(   Nt   <s   <<t   >s   >>t   =s   ==(   t   strt   __eq__t   Truet   False(   t   selft   other(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR"   K   s    c         C  s   |  j  |  S(   N(   R"   (   R%   R&   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   __ne__W   s    (   R   R   R   R"   R'   (    (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR   B   s   	c         C  s   | |  _  d  S(   N(   t   _dep(   R%   t   dep(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   __init__Z   s    c         C  s   |  j  j j S(   s   The name of the target package.(   R(   t
   target_pkgt   name(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR,   ]   s    c         C  s   |  j  |  j j  S(   s   The relation (<, <=, !=, =, >=, >, ).

        Note that the empty string is a valid string as well, if no version
        is specified.
        (   t   _BaseDependency__dstrR(   t	   comp_type(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   relationb   s    c         C  s
   |  j  j S(   s\   The target version or None.

        It is None if and only if relation is the empty string.(   R(   t
   target_ver(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   versionk   s    c         C  s
   |  j  j S(   s   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.
        (   R(   t   dep_type_untranslated(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   rawtyper   s    	c         C  s   |  j  j d k S(   s   Whether this is a PreDepends.t
   PreDepends(   R(   R2   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt
   pre_depend}   s    c         C  s    d |  j  |  j |  j |  j f S(   Ns=   <BaseDependency: name:%r relation:%r version:%r preDepend:%r>(   R,   R/   R1   R5   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   __repr__   s    (   R   R   R   R!   R-   R*   t   propertyR,   R/   R1   R3   R5   R6   (    (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR   ?   s   		c           B  s&   e  Z d  Z d   Z e d    Z RS(   sx   Represent an Or-group of dependencies.

    Attributes defined here:
        or_dependencies - The possible choices
    c         C  s$   t  t |   j   |  j |  d  S(   N(   t   superR   R*   t   extend(   R%   t   alternatives(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR*      s    c         C  s   |  S(   N(    (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   or_dependencies   s    (   R   R   R   R*   R7   R;   (    (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR      s   	c           B  s    e  Z d  Z d   Z d   Z RS(   s  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.
    c         C  s   | j  |  _  | j |  _ | j |  _ | j |  _ | j |  _ | j |  _ | j |  _ | j j j	 |  } | r | j
 r t |  _ n	 t |  _ d  S(   N(   t   archivet	   componentt   labelt   origint   codenamet   sitet   not_automatict   _pcachet   _listt
   find_indext
   is_trustedR#   t   trustedR$   (   R%   t   pkgt   packagefilet	   indexfile(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR*      s    c         C  s,   d |  j  |  j |  j |  j |  j |  j f S(   NsH   <Origin component:%r archive:%r origin:%r label:%r site:%r isTrusted:%r>(   R=   R<   R?   R>   RA   RG   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR6      s    (   R   R   R   R*   R6   (    (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR	      s   	c           B  sk   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d d  Z d	   Z d
   Z RS(   s"  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.

    c         C  s   t  j |  |  _ d  S(   N(   R   t
   TagSectiont   _rec(   R%   t
   record_str(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR*      s    c         C  s   t  |  j  S(   N(   t   hashRL   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   __hash__   s    c         C  s   t  |  j  S(   N(   R!   RL   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   __str__   s    c         C  s   |  j  | S(   N(   RL   (   R%   t   key(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   __getitem__   s    c         C  s   | |  j  k S(   N(   RL   (   R%   RQ   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   __contains__   s    c         C  s   t  |  j j    S(   N(   t   iterRL   t   keys(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   __iter__   s    c         c  s0   x) |  j  j   D] } | |  j  | f Vq Wd S(   s6   An iterator over the (key, value) items of the record.N(   RL   RU   (   R%   RQ   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt	   iteritems   s    c         C  s   |  j  j | |  S(   s   Return record[key] if key in record, else *default*.

        The parameter *default* must be either a string or None.
        (   RL   t   get(   R%   RQ   t   default(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyRX      s    c         C  s   | |  j  k S(   s    deprecated form of ``key in x``.(   RL   (   R%   RQ   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   has_key   s    c         C  s   t  |  j  S(   N(   t   lenRL   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   __len__   s    N(   R   R   R   R*   RO   RP   RR   RS   RV   RW   t   NoneRX   RZ   R\   (    (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR      s   								c           B  s]  e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z d   Z e d    Z  e d    Z! e d    Z" e d     Z# e d!    Z$ e d"    Z% e d#    Z& e d$    Z' e d%    Z( e d&    Z) e d'    Z* d(   Z+ e d)    Z, e d*    Z- d+ d. d,  Z/ d+ d. e0 d-  Z1 RS(/   s   Representation of a package version.

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

    .. versionadded:: 0.7.9
    c         C  s   | |  _  | |  _ d  S(   N(   t   packaget   _cand(   R%   R^   t   cand(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR*      s    	c         C  sH   y t  j |  j j | j  SWn$ t k
 rC t  j |  j j |  SXd  S(   N(   R   t   version_compareR_   t   ver_strR1   t   AttributeError(   R%   R&   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   _cmp  s    c         C  s0   y |  j  |  d k SWn t k
 r+ t SXd  S(   Ni    (   Rd   t	   TypeErrort   NotImplemented(   R%   R&   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR"     s    c         C  s0   y |  j  |  d k SWn t k
 r+ t SXd  S(   Ni    (   Rd   Re   Rf   (   R%   R&   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   __ge__  s    c         C  s0   y |  j  |  d k SWn t k
 r+ t SXd  S(   Ni    (   Rd   Re   Rf   (   R%   R&   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   __gt__  s    c         C  s0   y |  j  |  d k SWn t k
 r+ t SXd  S(   Ni    (   Rd   Re   Rf   (   R%   R&   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   __le__  s    c         C  s0   y |  j  |  d k  SWn t k
 r+ t SXd  S(   Ni    (   Rd   Re   Rf   (   R%   R&   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   __lt__  s    c         C  s0   y |  j  |  d k SWn t k
 r+ t SXd  S(   Ni    (   Rd   Re   Rf   (   R%   R&   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR'   %  s    c         C  s
   |  j  j S(   N(   R_   RN   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyRO   +  s    c         C  s   d |  j  j |  j f S(   Ns    <Version: package:%r version:%r>(   R^   R,   R1   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR6   .  s    c         C  s3   |  j  j j j |  j j d  r/ |  j  j j Sd S(   s=   Internal helper that moves the Records to the right position.i    N(   R^   RC   t   _recordst   lookupR_   t	   file_list(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyRk   2  s    "c         C  s;   |  j  j } |  j j j j | j j d   |  j j j S(   s2   Internal helper to get the translated description.i    (   R_   t   translated_descriptionR^   RC   Rk   Rl   Rm   t   pop(   R%   t	   desc_iter(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   _translated_records8  s    "c         C  s
   |  j  j S(   s.   Return the size of the package when installed.(   R_   t   installed_size(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyRr   ?  s    c         C  s
   |  j  j S(   s$   Return the homepage for the package.(   Rk   t   homepage(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyRs   D  s    c         C  s
   |  j  j S(   s   Return the size of the package.(   R_   R   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR   I  s    c         C  s
   |  j  j S(   s/   Return the architecture of the package version.(   R_   t   arch(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   architectureN  s    c         C  s   t  |  j j  S(   s:   Return whether the version of the package is downloadable.(   t   boolR_   t   downloadable(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyRw   S  s    c         C  s
   |  j  j S(   s   Return the version as a string.(   R_   Rb   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR1   X  s    c         C  s
   |  j  j S(   s0   Return the short description (one line summary).(   Rq   t
   short_desc(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   summary]  s    c         C  s
   |  j  j S(   s"   return the long description (raw).(   Rk   t	   long_desc(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   raw_descriptionb  s    c         C  s
   |  j  j S(   s"   Return the section of the package.(   R_   t   section(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR|   g  s    c         C  s\  d } |  j  j } y% t | t  s6 | j d  } n  Wn* t k
 rc } t d  |  j j | f SXt	 | j
 d   } t |  x | D] } | j   d k r | j d  s | d 7} q q n  | j d  r| j d  s d | d	 } qJd
 | d	 } nF | j d  rD| j d  s.| d k r;| d } qJ| } n | } | | 7} q W| S(   s   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.
        t    s   utf-8s<   Invalid unicode in description for '%s' (%s). Please report.s   
t   .s   

s     s   
%s
i   s   %s
t    i   (   Rq   Rz   t
   isinstancet   unicodet   decodet   UnicodeDecodeErrort   _R^   R,   RT   t   splitt   nextt   stript   endswitht
   startswith(   R%   t   desct   dsct   errt   linest   raw_linet   line(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   descriptionl  s4    		
	c         C  s9   y |  j  j p |  j j SWn t k
 r4 |  j j SXd S(   s&   Return the name of the source package.N(   Rk   t
   source_pkgR^   t	   shortnamet
   IndexError(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   source_name  s    c         C  s9   y |  j  j p |  j j SWn t k
 r4 |  j j SXd S(   s)   Return the version of the source package.N(   Rk   t
   source_verR_   Rb   R   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   source_version  s    c         C  s
   |  j  j S(   s.   Return the priority of the package, as string.(   R_   t   priority_str(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   priority  s    c         C  sQ   d } |  j  j j j } x2 |  j j D]$ \ } } t | | j |   } q% W| S(   s   Return the internal policy priority as a number.
           See apt_preferences(5) for more information about what it means.
        i    (   R^   RC   t	   _depcachet   policyR_   Rm   t   maxt   get_priority(   R%   R   R   RI   t   _unused(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   policy_priority  s
    c         C  s   t  |  j j  S(   s   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
        (   R   Rk   t   record(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR     s    c         G  s   g  } |  j  j } xx | D]p } yV xO | | D]C } g  } x! | D] } | j t |   q@ W| j t |   q- WWq t k
 r q Xq W| S(   s8   Return a list of Dependency objects for the given types.(   R_   t   depends_listt   appendR   R   t   KeyError(   R%   t   typesR   t   dependst   type_t   dep_ver_listt	   base_depst   dep_or(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   get_dependencies  s    c         C  s!   g  |  j  j D] } | d ^ q S(   s3    Return a list of names that this version provides.i    (   R_   t   provides_list(   R%   t   p(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   provides  s    c         C  s   |  j  d  S(   s4   Return the list of enhances for the package version.t   Enhances(   R   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   enhances  s    c         C  s   |  j  d d  S(   s/   Return the dependencies of the package version.R4   t   Depends(   R   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   dependencies  s    c         C  s   |  j  d  S(   s-   Return the recommends of the package version.t
   Recommends(   R   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt
   recommends  s    c         C  s   |  j  d  S(   s+   Return the suggests of the package version.t   Suggests(   R   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   suggests  s    c         C  s@   g  } x3 |  j  j D]% \ } } | j t |  j |   q W| S(   s1   Return a list of origins for the package version.(   R_   Rm   R   R	   R^   (   R%   t   originsRI   R   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR     s    c         C  s
   |  j  j S(   sZ   Return the path to the file inside the archive.

        .. versionadded:: 0.7.10
        (   Rk   t   filename(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR     s    c         C  s
   |  j  j S(   sK   Return the md5sum of the binary.

        .. versionadded:: 0.7.10
        (   Rk   t   md5_hash(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR     s    c         C  s
   |  j  j S(   sL   Return the sha1sum of the binary.

        .. versionadded:: 0.7.10
        (   Rk   t	   sha1_hash(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   sha1  s    c         C  s
   |  j  j S(   sN   Return the sha256sum of the binary.

        .. versionadded:: 0.7.10
        (   Rk   t   sha256_hash(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   sha256  s    c         C  s   t  |  j d j    S(   s   Get the tasks of the package.

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

        .. versionadded:: 0.8.0
        t   Task(   t   setR   R   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   tasks  s    c         c  sV   xO |  j  j D]A \ } } |  j j j j |  } | r | j |  j j  Vq q Wd S(   sV   Return an iterator over all available urls.

        .. versionadded:: 0.7.10
        N(	   R_   Rm   R^   RC   RD   RE   t   archive_uriRk   R   (   R%   RI   R   RJ   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   _uris  s    c         C  s   t  |  j    S(   s^   Return a list of all available uris for the binary.

        .. versionadded:: 0.7.10
        (   t   listR   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   uris(  s    c         C  s3   y t  t |  j     SWn t k
 r. d SXd S(   sN   Return a single URI for the binary.

        .. versionadded:: 0.7.10
        N(   R   RT   R   t   StopIterationR]   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   uri0  s    R}   c         C  s   t  j j |  j j  } t  j j | |  } t | |  j |  j j  rf t	 d |  t  j j
 |  St j | p t j j j    } t j | |  j |  j j |  j | d | } | j   | j | j k r t d | j | j f   n  t  j j
 |  S(   se  Fetch 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.

        .. versionadded:: 0.7.10
        s"   Ignoring already existing file: %st   destfiles$   The item %r could not be fetched: %s(   R   R   t   basenameRk   R   t   joinR   R   R   t   printt   abspathR   t   Acquiret   aptt   progresst   textt   AcquireProgresst   AcquireFileR   t   runt   statust	   STAT_DONER   R   t
   error_text(   R%   t   destdirR   t   baseR   t   acqt   acqfile(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   fetch_binary;  s    !
c      
   C  s<  t  j   } t  j | p' t j j j    } d	 } |  j } | j	 pN |  j
 j } | j pc |  j j }	 | j |  }
 x( |
 r |	 | j k r | j |  }
 qx W|
 s t d |    n  t   } x | j D] \ } } } } t j j |  } t j j | |  } | d k r| } n  t | | |  r@t d |  q n  | j t  j | | j j |  | | | d |  q W| j   xB | j D]7 } | j  | j! k rt" d | j# | j$ f   qqW| r(| j
 d t  j% | j  } t j j | |  } t& j' d d | | g  t j j( |  St j j( |  Sd	 S(
   s[  Get 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.
        s   No source for %rR   s"   Ignoring already existing file: %sR   s$   The item %r could not be fetched: %st   -s   dpkg-sources   -xN()   R   t   SourceRecordsR   R   R   R   R   R]   Rk   R   R^   R   R   R_   Rb   Rl   R1   t
   ValueErrorR   t   filesR   R   R   R   R   R   R   R   t   indexR   R   t   itemsR   R   R   R   R   t   upstream_versiont
   subprocesst
   check_callR   (   R%   R   R   t   unpackt   srcR   R   R   R   R   t   source_lookupR   R   R   R   R   R   R   t   itemt   outdir(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   fetch_sourceW  sB    !			
N(2   R   R   R   R*   Rd   R"   Rg   Rh   Ri   Rj   R'   RO   R6   R7   Rk   Rq   Rr   Rs   R   Ru   Rw   R1   Ry   R{   R|   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R]   R   R#   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR      sZ   										/		
	
c           B  se   e  Z d  Z d
 d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d
 d	  Z RS(   s  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)
    c         C  s5   | |  _  | j j |  _ | r1 |  j | |  _ n  d  S(   N(   t   _packaget   _pkgt   version_listt	   _versions(   R%   R^   t   slice_(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR*     s    	c         C  s   t  | t  r" |  j |  j |  Sy t |  j |  j |  SWnD t k
 r x4 |  j D]% } | j | k rW t |  j |  SqW Wn Xt d |   d  S(   Ns   Version: %r not found.(	   R   t   slicet	   __class__R   R   R   Re   Rb   R   (   R%   R   t   ver(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyRR     s    c         C  s   d |  j    S(   Ns   <VersionList: %r>(   RU   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR6     s    c           s     f d     j  D S(   s*   Return an iterator over all value objects.c         3  s!   |  ] } t    j |  Vq d  S(   N(   R   R   (   t   .0R   (   R%   (    s/   /usr/lib/python2.7/dist-packages/apt/package.pys	   <genexpr>  s    (   R   (   R%   (    (   R%   s/   /usr/lib/python2.7/dist-packages/apt/package.pyRV     s    c         C  sF   t  | t  r | j } n  x$ |  j D] } | j | k r% t Sq% Wt S(   N(   R   R   R1   R   Rb   R#   R$   (   R%   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyRS     s    c         C  s   t  |   t  |  k S(   N(   R   (   R%   R&   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR"     s    c         C  s   t  |  j  S(   N(   R[   R   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR\     s    c         C  s   g  |  j  D] } | j ^ q
 S(   s*   Return a list of all versions, as strings.(   R   Rb   (   R%   R   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyRU     s    c         C  s%   y |  | SWn t  k
 r  | SXd S(   s   Return the key or the default.N(   t   LookupError(   R%   RQ   RY   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyRX     s    N(   R   R   R   R]   R*   RR   R6   RV   RS   R"   R\   RU   RX   (    (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR     s   								c           B  s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z e e e  Z e d    Z	 e d    Z
 e d    Z e d	    Z e d
    Z d   Z e d    Z d   Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z d% d% d  Z e d    Z e d    Z  e d    Z! e d    Z" d   Z# e$ e% d   Z& e$ e$ e$ d!  Z' e$ d"  Z( e$ d#  Z) d$   Z* RS(&   s   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.
    c         C  s   | |  _  | |  _ d |  _ d S(   s    Init the Package object R}   N(   R   RC   t
   _changelog(   R%   t   pcachet   pkgiter(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR*     s    		c         C  s#   d |  j  j |  j  j |  j  j f S(   Ns(   <Package: name:%r architecture=%r id:%r>(   R   R,   Ru   t   id(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR6     s    c         C  s   |  j  | j  k  S(   N(   R,   (   R%   R&   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyRj     s    c         C  s5   |  j  j j |  j  } | d k	 r1 t |  |  Sd S(   s   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(   RC   R   t   get_candidate_verR   R]   R   (   R%   R`   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt	   candidate  s    c         C  s:   |  j  j   |  j  j j |  j | j  |  j  j   d S(   s)   Set the candidate version of the package.N(   RC   t   cache_pre_changeR   t   set_candidate_verR   R_   t   cache_post_change(   R%   R1   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   __set_candidate  s    c         C  s)   |  j  j d k	 r% t |  |  j  j  Sd S(   s`   Return the currently installed version of the package.

        .. versionadded:: 0.7.9
        N(   R   t   current_verR]   R   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt	   installed  s    c         C  s   |  j  j t  S(   s|  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.
        (   R   t   get_fullnameR#   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR,     s    c         C  s   |  j  j t  S(   s\   Return the name of the package, including architecture.

        .. versionadded:: 0.7.100.3(   R   R   R$   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   fullname  s    c         C  s
   |  j  j S(   sZ   Return the name of the package, without architecture.

        .. versionadded:: 0.7.100.3(   R   R,   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR      s    c         C  s
   |  j  j S(   sn   Return a uniq ID for the package.

        This can be used eg. to store additional information about the pkg.(   R   R   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR   '  s    c         C  s
   |  j  j S(   s[   Return the hash of the object.

        This returns the same value as ID, which is unique.(   R   R   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyRO   .  s    c         C  s
   |  j  j S(   s>   Return True if the package is an essential part of the system.(   R   t	   essential(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR   4  s    c         C  s
   |  j  j S(   s  Return the Architecture of the package.

        .. 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.
        (   R   Ru   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyRu   9  s    c         C  s
   |  j  j S(   s"   Return the section of the package.(   R   R|   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR|   C  s    c         C  s   |  j  j j |  j  S(   s5   Return ``True`` if the package is marked for install.(   RC   R   t   marked_installR   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR  J  s    c         C  s   |  j  j j |  j  S(   s5   Return ``True`` if the package is marked for upgrade.(   RC   R   t   marked_upgradeR   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR  O  s    c         C  s   |  j  j j |  j  S(   s4   Return ``True`` if the package is marked for delete.(   RC   R   t   marked_deleteR   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR  T  s    c         C  s   |  j  j j |  j  S(   s2   Return ``True`` if the package is marked for keep.(   RC   R   t   marked_keepR   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR  Y  s    c         C  s   |  j  j j |  j  S(   s!    Package is marked for downgrade (   RC   R   t   marked_downgradeR   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR  ^  s    c         C  s   |  j  j j |  j  S(   s7   Return ``True`` if the package is marked for reinstall.(   RC   R   t   marked_reinstallR   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR  c  s    c         C  s   |  j  j d k	 S(   s,   Return ``True`` if the package is installed.N(   R   R   R]   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   is_installedh  s    c         C  s   |  j  o |  j j j |  j  S(   s-   Return ``True`` if the package is upgradable.(   R  RC   R   t   is_upgradableR   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR  m  s    	c         C  s(   |  j  s |  j o' |  j j j |  j  S(   s   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.
        (   R  R  RC   R   t
   is_garbageR   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   is_auto_removables  s    c         C  s   |  j  j j |  j  S(   s@   Return whether the package is marked as automatically installed.(   RC   R   t   is_auto_installedR   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR  ~  s    c         C  sz   xs |  j  |  j f D]_ } d | } y8 t | d  # } | j   j d  j d  SWd QXWq t k
 rq q q Xq Wg  S(   s   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
        s   /var/lib/dpkg/info/%s.listt   rbs   utf-8u   
N(   R,   R   R   t   readR   R   t   EnvironmentError(   R%   R,   R   Rm   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   installed_files  s    
&c         C  s~  |  j  d k r |  j  S| d k r |  j s. n  |  j j d j d k rP d } q |  j j d j d k rr d } q t d  } t | t  r | S| j d  Sn  |  j j	 } d	 } |  j j
 } |  j j } y t j   } Wn t k
 r n Xx} | j |  rn| j sq n  |  j j | j k r;| j } | j
 } Pn  t j | j |  d k r | j } | j
 } q q W| j d
 d  }	 t |	  d k r|	 d } n  ~	 | d }
 | j d  rd | d }
 n  | j d d  } t |  d k rd j | d  } n  ~ | i | d 6|
 d 6| d 6| d 6} t j   } z*yt j d  | re| j   red St |  } d } d t j |  } xt r| r| j   rd S| j   } | sPn  | j d  } t j | |  } | rt  |  j! d d  } | r&d | k r&| j d d  d } n  | j" d  } | r`d | k r`| j d d  d } n  | rt j | |  d k rPqn  | | 7} qWt |  d k rt d  } t | t  s| j d  } qn  | |  _  Wn t# k
 r%t d  | | f } t | t  r| S| j d  St$ t% f k
 rdt d  } t | t  rW| S| j d  SXWd t j |  X|  j  S(   s  
        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.Lock,
        which if set, prevents the download.
        u    i    t   Debianss   http://packages.debian.org/changelogs/pool/%(src_section)s/%(prefix)s/%(src_pkg)s/%(src_pkg)s_%(src_ver)s/changelogt   Ubuntusu   http://changelogs.ubuntu.com/changelogs/pool/%(src_section)s/%(prefix)s/%(src_pkg)s/%(src_pkg)s_%(src_ver)s/changelogs$   The list of changes is not availables   utf-8t   maint   /i   t   libi   t   :R}   t   src_sectiont   prefixt   src_pkgt   src_veri   s   ^%s \((.*)\)(.*)$R1   s   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.sO   Failed to download the list of changes. 
Please check your Internet connection.N(&   R   R]   R   R   R?   R   R   R   R   R   R|   R   R   R   t   SystemErrorRl   R1   Ra   R   R[   R   R   t   sockett   getdefaulttimeoutt   setdefaulttimeoutt   isSetR   t   ret   escapeR#   t   readlinet   matcht   getattrR   t   groupR   t   IOErrorR   (   R%   R   t   cancel_lockt   resR  R  R|   R  t   src_recordst   section_splitR  t   src_ver_splitt   timeoutt   changelog_filet	   changelogt   regexpt   line_rawR   R"  R   t   changelog_ver(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   get_changelog  s    			#				
		 %c         C  s
   t  |   S(   sc   Return a VersionList() object for all available versions.

        .. versionadded:: 0.7.9
        (   R   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   versions4  s    c         C  s   |  j  j j |  j  S(   s5   Return True if the to-be-installed package is broken.(   RC   R   t   is_inst_brokenR   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR3  <  s    c         C  s   |  j  j j |  j  S(   s/   Return True if the installed package is broken.(   RC   R   t   is_now_brokenR   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR4  A  s    c         C  s   |  j  j t j k S(   s8   Checks whether the package is is the config-files state.(   R   t   current_stateR   t   CURSTATE_CONFIG_FILES(   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   has_config_filesF  s    c         C  s4   |  j  j   |  j  j j |  j  |  j  j   d S(   s   Mark a package for keep.N(   RC   R   R   t	   mark_keepR   R   (   R%   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR8  M  s    c         C  s   |  j  j   |  j  j j |  j |  | r |  j  j j d k r t j |  j  j  } | j |  j  | j	 |  j  | j
 |  j  | j   | j   n  |  j  j   d S(   s+  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.
        i    N(   RC   R   R   t   mark_deleteR   t   broken_countR   t   ProblemResolvert   cleart   protectt   removet   install_protectt   resolveR   (   R%   t   auto_fixt   purget   fix(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR9  S  s    	
c         C  s   |  j  j   |  j  j j |  j | |  | r |  j  j j d k r t j |  j  j  } | j |  j  | j	 |  j  | j
 t  n  |  j  j   d S(   s0  Mark 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.
        i    N(   RC   R   R   t   mark_installR   R:  R   R;  R<  R=  R@  R#   R   (   R%   RA  t	   auto_instt	   from_usert   fixer(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyRD  h  s    c         C  sP   |  j  r2 |  j } |  j d |  |  j |  n t j j d |  j j  d S(   s   Mark a package for upgrade.RF  s1   MarkUpgrade() called on a non-upgrable pkg: '%s'
N(	   R  R  RD  t	   mark_autot   syst   stderrt   writeR   R,   (   R%   RF  t   auto(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   mark_upgrade  s    		c         C  s   |  j  j j |  j |  d S(   s  Mark 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(   RC   R   RH  R   (   R%   RL  (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyRH    s    c         C  s   |  j  j j | |  d S(   s  Commit 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(   RC   R   t   commit(   R%   t	   fprogresst	   iprogress(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyRN    s    	N(+   R   R   R   R*   R6   Rj   R   t   _Package__set_candidateR7   R   R,   R   R   R   RO   R   Ru   R|   R  R  R  R  R  R  R  R  R
  R  R  R]   R1  R2  R3  R4  R7  R8  R#   R$   R9  RD  RM  RH  RN  (    (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyR
     sL   								
		c          C  s}  t  d  d d l }  t j   t j j j   } t j |  } | d } t  d | j	  t  d | j
  t  d | j j  t  d | j j  t  d	 | j j  t  d
 | j j  t  d | j j  t  d | j j  t  d | j j  t  d | j  t  d | j j  t  d | j j  t  d | j j  t  d | j j  t  d | j j  t  d | j j  t  d | j j  x4 | j j D]& } t  d j d   | j D   qWt  d | j j  t  d | j j  t  d | j j  t  | d j    x t  t! f D] } t  d |  xB | D]: } | j" rC|  j# d d  d k r}| j$ |  q}qCqCWt  d | j% j&  t  d  | j% j'  q)Wt    x t  t! f D] } t  d! |  t j |  } xf | j(   D]X } |  j# d d  d k ry | | j) |  WqIt* k
 rEt  d" |  qIXqqWt  d | j% j&  t  d# | j% j+  qWd S($   s
   Self-test.s   Self-test for the Package moduliNs	   apt-utilss	   Name: %s s   ID: %s s   Priority (Candidate): %s s   Priority (Installed): %s s   Installed: %s s   Candidate: %s s   CandidateDownloadable: %ss   CandidateOrigins: %ss   SourcePkg: %s s   Section: %s s   Summary: %ss   Description (formatted) :
%ss   Description (unformatted):
%ss   InstalledSize: %s s   PackageSize: %s s   Dependencies: %ss   Recommends: %st   ,c         s  s1   |  ]' } d  | j  | j | j | j f Vq d S(   s   %s (%s) (%s) (%s)N(   R,   R1   R/   R5   (   R   t   o(    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pys	   <genexpr>  s   s   arch: %ss   homepage: %ss   rec: t   2vcards8   Running install on random upgradable pkgs with AutoFix: i    i   s   Broken: %s s   InstCount: %s s.   Randomly remove some packages with AutoFix: %ss   Error trying to remove: %s s   DelCount: %s (,   R   t   randomR   t   initR   R   R   t
   OpProgresst   CacheR,   R   R   R   R   R1   Rw   R   R   R|   Ry   R   R{   Rr   R   R   R   R   R;   Ru   Rs   R   R1  R#   R$   R  t   randintRD  R   R:  t
   inst_countRU   R9  R  t	   del_count(   RU  R   t   cacheRH   R)   t   iR,   (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   _test  sd    


	t   __main__(,   R   t
   __future__R    R   RI  R  R  R   t   http.clientR   t   urllib.errorR   t   urllib.requestR   t   ImportErrort   httplibt   urllib2t   collectionsR   R   R   t   apt.progress.textR   R   R   t   __all__t   version_infot   majorR!   R   R   t	   ExceptionR   t   objectR   R   R   R	   R   R   R   R
   R^  R   (    (    (    s/   /usr/lib/python2.7/dist-packages/apt/package.pyt   <module>   sF   		H#: K 	9