
$Nc           @   sC  d  Z  d d l Z d d l Z d d l Z d d l Z d d l m Z y  d d l Z e j   e	 Z
 Wn e k
 r e Z
 n Xd e f d     YZ d e f d     YZ d e f d	     YZ d
 e f d     YZ e
 r d e f d     YZ n d e f d     YZ d   Z d d! d     YZ d d" d     YZ d e f d     YZ d   Z e e  Z e   d  Z e e  Z [ [ d   Z e e  Z e j d  d  Z e e  Z  d   Z! e e!  Z" d   Z# e e#  Z$ d   Z% e e%  Z& d   Z' e e'  Z( d d  Z* e e*  Z+ d    Z, e e,  Z- d S(#   sH   This module implements facilities to deal with Debian-specific metadata.iN(   t   function_deprecated_byt
   ParseErrorc           B   s>   e  Z d  Z d   Z d   Z d   Z d   Z e e  Z RS(   s   An exception which is used to signal a parse failure.

    Attributes:

    filename - name of the file
    lineno - line number in the file
    msg - error message

    c         C   s:   t  |  t j k s t  | |  _ | |  _ | |  _ d  S(   N(   t   typet   typest   IntTypet   AssertionErrort   filenamet   linenot   msg(   t   selfR   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   __init__.   s    		c         C   s   |  j  S(   N(   R   (   R	   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   __str__4   s    c         C   s   d |  j  |  j |  j f S(   Ns   ParseError(%s, %d, %s)(   R   R   R   (   R	   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   __repr__7   s    
c         C   s1   | j  d |  j |  j |  j f  | j   d S(   s0   Writes a machine-parsable error message to file.s
   %s:%d: %s
N(   t   writeR   R   R   t   flush(   R	   t   file(    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt	   print_out<   s    #(	   t   __name__t
   __module__t   __doc__R
   R   R   R   R    t   printOut(    (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR   #   s   					t   BaseVersionc           B   st   e  Z d  Z e j d  Z d Z d   Z d   Z d	   Z	 d
   Z
 d   Z d   Z d   Z d   Z d   Z RS(   s  Base class for classes representing Debian versions

    It doesn't implement any comparison, but it does check for valid versions
    according to Section 5.6.12 in the Debian Policy Manual.  Since splitting
    the version into epoch, upstream_version, and debian_revision components is
    pretty much free with the validation, it sets those fields as properties of
    the object, and sets the raw version to the full_version property.  A
    missing epoch or debian_revision results in the respective property set to
    None.  Setting any of the properties results in the full_version being
    recomputed and the rest of the properties set from that.

    It also implements __str__, just returning the raw version given to the
    initializer.
    sd   ^((?P<epoch>\d+):)?(?P<upstream_version>[A-Za-z0-9.+:~-]+?)(-(?P<debian_revision>[A-Za-z0-9+.~]+))?$t   full_versiont   epocht   upstream_versiont   debian_revisiont   debian_versionc         C   s   | |  _  d  S(   N(   R   (   R	   t   version(    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR
   Z   s    c         C   s   |  j  j |  } | s+ t d |   n  | j d  d  k rh d | j d  k rh t d |   n  | |  _ | j d  |  _ | j d  |  _ | j d  |  _ d  S(   Ns   Invalid version string %rR   t   :R   R   (	   t   re_valid_versiont   matcht
   ValueErrort   groupt   Nonet   _BaseVersion__full_versiont   _BaseVersion__epocht   _BaseVersion__upstream_versiont   _BaseVersion__debian_revision(   R	   R   t   m(    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   _set_full_version]   s    *	c         C   s   | |  j  k r, t t |   j | |  d  S| d k rA d } n  | d k rc |  j t |   n | d  k	 r~ t |  } n  d | } t |  |  } t |  | |  y |  j	   WnA t
 k
 r t |  | |  |  j	   t
 d | | f   n Xd  S(   NR   R   R   s   _BaseVersion__%ss+   Setting %s to %r results in invalid version(   t   magic_attrst   superR   t   __setattr__R'   t   strR!   t   getattrt   setattrt   _update_full_versionR   (   R	   t   attrt   valuet   privatet	   old_value(    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR*   k   s&    	

c         C   sQ   | |  j  k r% t t |   j |  S| d k r: d } n  d | } t |  |  S(   NR   R   s   _BaseVersion__%s(   R(   R)   R   t   __getattribute__R,   (   R	   R/   R1   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   __getattr__   s    	
c         C   s`   d } |  j  d  k	 r) | |  j  d 7} n  | |  j 7} |  j rS | d |  j 7} n  | |  _ d  S(   Nt    R   t   -(   R#   R!   R$   R%   R   (   R	   R   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR.      s    	c         C   s   |  j  S(   N(   R   (   R	   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR      s    c         C   s   d |  j  j |  f S(   Ns   %s('%s')(   t	   __class__R   (   R	   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR      s    c         C   s
   t   d  S(   N(   t   NotImplementedError(   R	   t   other(    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   __cmp__   s    c         C   s   t  t |    S(   N(   t   hashR+   (   R	   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   __hash__   s    (   s   full_versions   epochs   upstream_versions   debian_revisions   debian_version(   R   R   R   t   ret   compileR   R(   R
   R'   R*   R4   R.   R   R   R:   R<   (    (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR   C   s   	 									t   AptPkgVersionc           B   s    e  Z d  Z d   Z d   Z RS(   sA   Represents a Debian package version, using apt_pkg.VersionComparec         C   s/   t  s t d   n  t t |   j |  d  S(   Ns5   apt_pkg not available; install the python-apt package(   t   _have_apt_pkgR8   R)   R?   R
   (   R	   R   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR
      s    c         C   s   t  j t |   t |   S(   N(   t   apt_pkgt   version_compareR+   (   R	   R9   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR:      s    (   R   R   R   R
   R:   (    (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR?      s   	t   NativeVersionc           B   s   e  Z d  Z e j d  Z e j d  Z e j d  Z e j d  Z d   Z	 e
 d    Z e
 d    Z e
 d    Z RS(	   sB   Represents a Debian package version, with native Python comparisons   \d+|\D+s   \d+s   \ds   [A-Za-z]c         C   s   t  | t  sT y t t |   } WqT t k
 rP } t d | | f   qT Xn  t t |  j pf d  t | j px d   } | d k r | S|  j |  j | j  } | d k r | S|  j |  j	 p d | j	 p d  S(   Ns&   Couldn't convert %r to BaseVersion: %st   0i    (
   t
   isinstanceR   R+   R   t   cmpt   intR   t   _version_cmp_partR   R   (   R	   R9   t   et   res(    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR:      s    -c         C   s^   | d k r d S|  j  j |  r0 t |  d S|  j j |  rL t |  St |  d Sd S(   s'   Return an integer value for character xt   ~ii   i   N(   t   re_digitR   RG   t   re_alphat   ord(   t   clst   x(    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   _order   s    
c   	      C   s   g  | D] } |  j  |  ^ q } g  | D] } |  j  |  ^ q) } xk | sS | r d } d } | rw | j d  } n  | r | j d  } n  t | |  } | d k rG | SqG Wd S(   Ni    (   RQ   t   popRF   (	   RO   t   vat   vbRP   t   lat   lbt   at   bRJ   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   _version_cmp_string   s    ""c         C   s   |  j  j |  } |  j  j |  } x | s3 | r d } d } | rW | j d  } n  | ro | j d  } n  |  j j |  r |  j j |  r t |  } t |  } t | |  } | d k r | Sq' |  j | |  } | d k r' | Sq' Wd S(   NRD   i    (   t   re_all_digits_or_nott   findallRR   t	   re_digitsR   RG   RF   RY   (   RO   RS   RT   RU   RV   RW   RX   RJ   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyRH      s&    $(   R   R   R   R=   R>   RZ   R\   RL   RM   R:   t   classmethodRQ   RY   RH   (    (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyRC      s   	t   Versionc           B   s   e  Z RS(    (   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR^     s   c           B   s   e  Z RS(    (   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR^     s   c         C   s   t  t |   t |   S(   N(   RF   R^   (   RW   RX   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyRB     s    t   PackageFilec           B   sY   e  Z d  Z e j d  Z e j d  Z d d  Z d   Z	 d d  Z
 e e
  Z RS(   sm   A Debian package file.

    Objects of this class can be used to read Debian's Source and
    Packages files.s*   ^([A-Za-z][A-Za-z0-9-]+):(?:\s*(.*?))?\s*$s   ^\s+(?:\.|(\S.*?)\s*)$c         C   s:   | d k r t |  } n  | |  _ | |  _ d |  _ d S(   s   Creates a new package file object.

        name - the name of the file the data comes from
        file_obj - an alternate data source; the default is to open the
                  file with the indicated name.
        i    N(   R!   R   t   nameR   (   R	   R`   t   file_obj(    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR
     s
    		c         c   s}  |  j  j   } |  j d 7_ g  } xD| rj| j d  d k r t |  d k rd |  j d  n  | Vg  } |  j  j   } |  j d 7_ q' n  |  j j |  } | s |  j d  n  | j   \ } } | p d } xx t	 rS|  j  j   } |  j d 7_ |  j
 j |  } | rO| j   \ } | d  k r<d } n  d | | f } q Pq W| j | | f  q' W| ry| Vn  d  S(	   Ni   s    	s   
i    s   expected package records   expected package fieldR5   s   %s
%s(   R   t   readlineR   t   stript   lent   raise_syntax_errort   re_fieldR   t   groupst   Truet   re_continuationR!   t   append(   R	   t   linet   pkgR   R`   t   contentst	   ncontents(    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   __iter__$  s<    			c         C   s1   | d  k r |  j } n  t |  j | |   d  S(   N(   R!   R   R   R`   (   R	   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyRe   G  s    N(   R   R   R   R=   R>   Rf   Ri   R!   R
   Ro   Re   R    t   raiseSyntaxError(    (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR_     s   	#t
   PseudoEnumc           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s8   A base class for types which resemble enumeration types.c         C   s   | |  _  | |  _ d  S(   N(   t   _nameRQ   (   R	   R`   t   order(    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR
   P  s    	c         C   s   d |  j  j t f S(   Ns   %s(%s)(   R7   t   _name__R`   (   R	   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR   S  s    c         C   s   |  j  S(   N(   Rr   (   R	   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR   U  s    c         C   s   t  |  j | j  S(   N(   RF   RQ   (   R	   R9   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR:   W  s    c         C   s   t  |  j  S(   N(   R;   RQ   (   R	   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyR<   Y  s    (   R   R   R   R
   R   R   R:   R<   (    (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyRq   N  s   				t   Releasec           B   s   e  Z RS(    (   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyRu   \  s    c          C   sQ   i  }  d } x5 t  t |   D]! } t | | |  |  | | <q W|  t _ |  S(   Nt   potatot   woodyt   sarget   etcht   lennyt   sid(   Rv   Rw   Rx   Ry   Rz   R{   (   t   rangeRd   Ru   t   releases(   R}   t   relst   r(    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   list_releases^  s    	c         C   s   | j  |   r | |  Sd  Sd  S(   N(   t   has_keyR!   (   R`   R}   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   intern_releaseh  s    c         C   s4   t  j   } x |  D] } | j |  q W| j   S(   N(   t   hashlibt   sha1t   updatet	   hexdigest(   t   linesR&   t   l(    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   read_lines_sha1s  s    s   ^(\d+)(?:,(\d+))?([acd])$c   
      c   s  t  |   } xy| D]q} | j |  } | d
 k rE t d |  n  | j   \ } } } t |  } | d
 k	 r t |  } n  | d k r | d } | d
 k r | d } n  | | g  f Vq n  | d k r | d
 k	 r t d |  n  | } n# | d } | d
 k r| d } n  g  } xT | D]L }	 |	 d k rIt d |  n  |	 d k sa|	 d	 k rePn  | j |	  q&W| | | f Vq Wd
 S(   s1  Converts source to a stream of patches.

    Patches are triples of line indexes:

    - number of the first line to be replaced
    - one plus the number of the last line to be replaced
    - list of line replacements

    This is enough to model arbitrary additions, deletions and
    replacements.
    s   invalid patch command: t   di   RW   s   invalid patch argument: R5   s   end of stream in command: s   .
t   .N(   t   iterR   R!   R   Rg   RG   Rj   (
   t   sourcet   re_cmdt   iRk   R   t   firstt   lastt   cmdR   R   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   patches_from_ed_script{  s<    
	
c         C   s+   x$ | D] \ } } } | |  | | +q Wd S(   s2   Applies patches to lines.  Updates lines in place.N(    (   R   t   patchesR   R   t   args(    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   patch_lines  s    c         C   s   d d  l  } | d } t | d  } z< x |  D] } | j |  q/ W| j   | j | |  Wd  | j j |  r | j |  n  Xd  S(   Nis   .news   w+(   t   os.pathR   R   t   closet   renamet   patht   existst   unlink(   R   t   localt   ost	   local_newt   new_fileR   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   replace_file  s    

c   
      C   s   d d l  } d d l } d d l } | j   \ } } zN t j |  | j |  |  \ } } | j |  } | j   }	 | j   Wd t j	 |  X|	 S(   s[   Downloads a file from a remote location and gunzips it.

    Returns the lines in the file.iN(
   t   gzipt   tempfilet   urllibt   mkstempR   R   t   urlretrievet   GzipFilet	   readlinesR   (
   t   remoteR   R   R   t   handlet   fnameR   t   headerst   gfileR   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   download_gunzip_lines  s    c         C   s!   t  |  d  } t | |  | S(   s   Copies a gzipped remote file to the local system.

    remote - URL, without the .gz suffix
    local - name of the local file
    s   .gz(   R   R   (   R   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   download_file  s    c         C   s.  y t  |  } Wn) t k
 r; | r. d GHn  t |  |  SX| j   } | j   t |  } g  } i  } d d l } |  d }	 t j d  }
 y( | j	 |	  } t
 t |	 |   } WnQ t k
 r | r d GHn  t |  |  St k
 r
| r d GHn  t |  |  SXxO| D]G} x>| D]6\ } } | d k rp|
 j |  \ } } | | k r| rfd	 GHn  | Sqn  | d
 k rx` | j   D]R } | d k rqn  |
 j |  \ } } } | s| | k r| j |  qqWqn  | d k rBxH | j   D]: } | d k rqn  |
 j |  \ } } } | | | <qWqn  | rd | GHqqWqW| s| rud G| GHn  t |  |  Sxj | D]b } d | GHt |  d | d  } t |  | | k rt d |  n  t | t |   qWt |  } | | k rt d | | f  n  t | |  | S(   sj   Updates the local file by downloading a remote patch.

    Returns a list of lines in the local file.
    s1   update_file: no local copy, downloading full fileiNs   .diff/Indexs   \s+s1   update_file: could not interpret patch index files0   update_file: could not download patch index files   SHA1-Currents%   update_file: local file is up-to-dates   SHA1-HistoryR5   s   SHA1-Patchess   update_file: field %s ignoreds*   update_file: could not find historic entrys   update_file: downloading patch s   .diff/s   .gzs   patch %s was garbleds"   patch failed, got %s instead of %s(   R   t   IOErrorR   R   R   R   R   R=   R>   t   urlopent   listR_   R   t   splitt
   splitlinesRj   R   R   R   R   R   (   R   R   t   verboset
   local_fileR   t
   local_hasht   patches_to_applyt   patch_hashesR   t
   index_namet   re_whitespacet	   index_urlt   index_fieldst   fieldst   fieldR0   t   remote_hasht   remote_sizet   entryt	   hist_hasht	   hist_sizet
   patch_namet
   patch_hasht
   patch_sizet   patch_contentst   new_hash(    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   update_file  s    


c          G   sL   i  } x) |  D]! } x | D] } t  | | <q Wq W| j   } | j   | S(   sd   Create an order set (represented as a list) of the objects in
    the sequences passed as arguments.(   Rh   t   keyst   sort(   R   t   sRP   t   yR   (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   merge_as_setsP  s    
(    (    (.   R   R   R=   R   R   t   deprecationR    RA   t   initRh   R@   t   ImportErrort   Falset	   ExceptionR   t   objectR   R?   RC   R^   RB   R_   Rq   Ru   R   t   listReleasesR   t   internReleaseR   t   readLinesSHA1R>   R   t   patchesFromEdScriptR   t
   patchLinesR   t   replaceFileR   t   downloadGunzipLinesR   t   downloadFileR!   R   t
   updateFileR   t   mergeAsSets(    (    (    s9   /usr/lib/python2.7/dist-packages/debian/debian_support.pyt   <module>   sX   


 bQ	@		2				_	