
$Nc           @   sj  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d e f d     YZ d e f d     YZ	 d e f d     YZ
 d	 e j f d
     YZ d e f d     YZ e j d i d d 6e j  Z e j d  Z e j d  Z e j d  Z e j d  Z e j d e j  Z e j d e j  Z e j d e j  Z e j d e j  Z e j d e j  Z e j d  Z e j d  Z e j d  Z e j d  Z e j d  Z e j d e j  Z e j d e j  Z  e j d  e j  Z! e j d! e j  Z" e j d" e j  Z# e j d#  Z$ d$ e f d%     YZ% d&   Z& d S('   sA   This module implements facilities to deal with Debian changelogs.iNt   ChangelogParseErrorc           B   s&   e  Z d  Z e Z d   Z d   Z RS(   s0   Indicates that the changelog could not be parsedc         C   s   | |  _  d  S(   N(   t   _line(   t   selft   line(    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   __init__&   s    c         C   s   d |  j  S(   Ns   Could not parse changelog: (   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   __str__)   s    (   t   __name__t
   __module__t   __doc__t   Truet   is_user_errorR   R   (    (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR    "   s   	t   ChangelogCreateErrorc           B   s   e  Z d  Z RS(   s`   Indicates that changelog could not be created, as all the information
    required was not given(   R   R   R   (    (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR   ,   s   t   VersionErrorc           B   s&   e  Z d  Z e Z d   Z d   Z RS(   sB   Indicates that the version does not conform to the required formatc         C   s   | |  _  d  S(   N(   t   _version(   R   t   version(    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR   5   s    c         C   s   d |  j  S(   Ns   Could not parse version: (   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR   8   s    (   R   R   R   R	   R
   R   R   (    (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR   0   s   	t   Versionc           B   s   e  Z d  Z RS(   s)   Represents a version of a Debian package.(   R   R   R   (    (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR   =   s   t   ChangeBlockc           B   s   e  Z d  Z d d d d d d d d d d d 
 Z d   Z d   Z e e e  Z d   Z	 d   Z
 d   Z d   Z d	   Z d
   Z RS(   s=   Holds all the information about one block from the changelog.s   utf-8c         C   s   d  |  _ |  j |  | |  _ | |  _ | p1 d |  _ | p@ d |  _ | |  _ | |  _ | |  _	 g  |  _
 |	 ps i  |  _ |
 |  _ t |  _ d |  _ d  S(   Nt   unknownt    s     (   t   Nonet   _raw_versiont   _set_versiont   packaget   distributionst   urgencyt   urgency_commentt   _changest   authort   datet	   _trailingt   other_pairst	   _encodingt   Falset   _no_trailert   _trailer_separator(   R   R   R   R   R   R   t   changesR   R   R   t   encoding(    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR   D   s    									c         C   s"   | d  k	 r t |  |  _ n  d  S(   N(   R   t   strR   (   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR   V   s    c         C   s   t  |  j  S(   N(   R   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   _get_versionZ   s    c         C   sw   i  } xj t  j   D]\ \ } } | d j   | d j   } t j |  } | d  k re d | } n  | | | <q W| S(   Ni    i   s   XS-%s(   R   t   itemst   uppert   lowert   xbcs_ret   matchR   (   R   t	   norm_dictt   keyt   valuet   m(    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   other_keys_normalised_   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR#   i   s    c         C   s   |  j  j |  d  S(   N(   R   t   append(   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   add_trailing_linel   s    c         C   s   |  j  d  k r | g |  _  n |  j  } | j   t } xS t t |   D]? } t j | |  } | d  k rJ | j | |  t	 } PqJ qJ W| j   | s | j
 |  n  | |  _  d  S(   N(   R   R   t   reverseR    t   ranget   lent	   blanklineR+   t   insertR	   R1   (   R   t   changeR#   t   addedt   iR/   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt
   add_changeo   s    	

c         C   s  d } |  j  d  k r$ t d   n  | |  j  d 7} |  j d  k rS t d   n  | d |  j d 7} |  j d  k r t d   n  | |  j d 7} |  j d  k r t d	   n  | d
 |  j |  j 7} x1 |  j j   D]  \ } } | d | | f 7} q W| d 7} |  j	   d  k r,t d   n  x" |  j	   D] } | | d 7} q9W|  j
 s|  j d  k rxt d   n  |  j d  k rt d   n  | d |  j |  j |  j d 7} n  x |  j D] } | | d 7} qW| S(   NR   s   Package not specifiedt    s   Version not specifiedt   (s   ) s   Distribution not specifieds   ; s   Urgency not specifieds   urgency=s   , %s=%ss   
s   Changes not specifieds   Author not specifieds   Date not specifieds    -- (   R   R   R   R   R   R   R   R   R'   R#   R!   R   R   R"   R   (   R   t   blockR-   R.   R8   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   __unicode__   s<    
	#c         C   s   t  |   j |  j  S(   N(   t   unicodet   encodeR   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR      s    N(   R   R   R   R   R   R   R&   t   propertyR   R0   R#   R2   R;   R?   R   (    (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR   A   s   					
				!s?   ^(\w%(name_chars)s*) \(([^\(\) \t]+)\)((\s+%(name_chars)s+)+)\;s   [-+0-9a-z.]t
   name_charss   ^\s*$s	   ^\s\s+.*$sm   ^ -- (.*) <(.*)>(  ?)((\w+\,\s*)?\d{1,2}\s+\w+\s+\d{4}\s+\d{1,2}:\d\d:\d\d\s+[-+]\d{4}(\s+\([^\\(\)]\))?\s*)$sr   ^ --(?: (.*) <(.*)>(  ?)((\w+\,\s*)?\d{1,2}\s+\w+\s+\d{4}\s+\d{1,2}:\d\d:\d\d\s+[-+]\d{4}(\s+\([^\\(\)]\))?))?\s*$s   ^([-0-9a-z]+)=\s*(.*\S)$s   ^([-0-9a-z]+)((\s+.*)?)$s	   ^X[BCS]+-s   ^(;;\s*)?Local variables:s   ^vim:s   ^\$\w+:.*\$s   ^\# s	   ^/\*.*\*/sW   ^(\w+\s+\w+\s+\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}\s+[\w\s]*\d{4})\s+(.*)\s+(<|\()(.*)(\)|>)s:   ^(\w+\s+\w+\s+\d{1,2},?\s*\d{4})\s+(.*)\s+(<|\()(.*)(\)|>)s%   ^(\w[-+0-9a-z.]*) \(([^\(\) 	]+)\)\;?s"   ^([\w.+-]+)(-| )(\S+) Debian (\S+)s#   ^Changes from version (.*) to (.*):s$   ^Changes for [\w.+-]+-[\w.+-]+:?\s*$s   ^Old Changelog:\s*$s   ^(?:\d+:)?\w[\w.+~-]*:?\s*$t	   Changelogc           B   s  e  Z d  Z d# d# e e d d  Z d   Z d# e e d# d  Z d   Z	 d   Z
 e e	 e
 d d Z e d	    Z e d
    Z e d    Z e d    Z e d    Z d   Z d   Z e e e d d Z d   Z e e d d Z d   Z d   Z d   Z d   Z d   Z d   Z e d   e  Z d   Z e d   e  Z d   Z  d   Z! e d   e!  Z" d   Z# e d    e#  Z$ d!   Z% d"   Z& RS($   s#   Represents a debian/changelog file.s   utf-8c         C   se   | |  _  g  |  _ g  |  _ | d k	 ra y# |  j | d | d | d | Wqa t k
 r] qa Xn  d S(   s  Initializer.

        Args:
          file: The contents of the changelog, either as a str, unicode object,
              or an iterator of lines (each of which is either a str or unicode)
          max_blocks: The maximum number of blocks to parse from the input.
              (Default: no limit)
          allow_empty_author: Whether to allow an empty author in the trailer
              line of a change block.  (Default: False)
          strict: Whether to raise an exception if there are errors.  (Default:
              use a warning)
          encoding: If the input is a str or iterator of str, the encoding to
              use when interpreting the input.
        t
   max_blockst   allow_empty_authort   strictN(   R   t   _blockst   initial_blank_linesR   t   parse_changelogR    (   R   t   fileRE   RF   RG   R$   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR      s    			c         C   s&   | r t  |   n t j |  d  S(   N(   R    t   warningst   warn(   R   t   messageRG   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   _parse_error   s    c   #      C   s|  d } d } d } d }	 d }
 | p* |  j  } | d  k rM |  j d |  d  Sg  |  _ g  |  _ t d |  } g  } | } d  } t | t  r t | j	    d k r |  j d |  d  S| j
   } n  xB| D]:} t | t  s | j |  } n  | j d	  } | | k s| | k r~t j |  } t j |  } | d  k	 r | d  k	 rnt |  j  | k rnd  S| j d
  | _ | j d  | _ | j d  j   | _ | j d d
  d
 } i  } i  } x?| j d  D].} | j	   } t j |  } | d  k r#|  j d | |  qn  | j d
  } | j d  } | j   | k rp|  j d | j   |  n  | | | j   <| j   d k r t j |  } | d  k r|  j d | |  q
| j d
  | _ | j d  } | d  k	 r
| | _ q
q| | | <qW| | _ | } q| d  k	 rb| | k rK|  j j |  q{|  j d j |  qt j |  } t  j |  } t! j |  } t" j |  } t# j |  } | d  k	 s| d  k	 r| | k r|  j d j |  | } |
 } q n  | d  k	 s| d  k	 s| d  k	 rT| | k r:|  j j |  q |  j d j |  q n  t$ j |  d  k	 st% j |  d  k	 st& j |  d  k	 st' j |  d  k	 st( j |  d  k	 st) j |  d  k	 st* j |  d  k	 st+ j |  d  k	 r.| | k r.|  j d j |  | } |
 } q n  |  j d | | f |  | | k rg|  j j |  q|  j d j |  q | | k s| |	 k rt, j |  }  t- j |  }! t. j |  }" t j |  } |  d  k	 r| j |  |	 } q|! d  k	 r|! j d  d k r>|  j d | |  |! j d  | _/ n  d |! j d
  |! j d  f | _0 |! j d  | _1 | | _2 |  j j |  g  } t d |  } | } q|" d  k	 r| s|  j d | |  q n  | | _2 |  j j |  g  } t d |  } | } q| d  k	 r+| j |  qt! j |  } t" j |  } t# j |  } | d  k	 s|| d  k	 s|| d  k	 r| j |  q n  |  j d | | f |  | j |  q | |
 k r| | k r|  j d j |  q| j |  q t3 s t4 d |  q W| | k r'| |
 k s?| |
 k rx| | k rx|  j d | |  | | _2 t5 | _6 |  j j |  n  d  S(   Ns   first headings   next heading of EOFs   start of change datas   more change data or trailers   slurp to ends   Empty changelog file.R$   i    s   
i   i   i   t   ;t   ,s$   Invalid key-value pair after ';': %ss   Repeated key-value: %sR   s!   Badly formatted urgency value: %sis(   Unexpected line while looking for %s: %ss     s    Badly formatted trailer line: %ss   %s <%s>i   s   Unknown state: %ss   Found eof where expected %s(7   R   R   RO   RH   RI   R   t
   isinstancet
   basestringR5   t   stript
   splitlinesR@   t   decodet   rstript   toplineR+   R6   t   groupR   R   t   lstripR   t   splitt   keyvalueR)   t   value_reR   R   R   R1   R2   t   emacs_variablest   vim_variablest   cvs_keywordt   commentst   more_commentst   old_format_re1t   old_format_re2t   old_format_re3t   old_format_re4t   old_format_re5t   old_format_re6t   old_format_re7t   old_format_re8R8   t   endlinet   endline_nodetailsR"   R   R   R   R    t   AssertionErrorR	   R!   (#   R   RK   RE   RF   RG   R$   t   first_headingt   next_heading_or_eoft   start_of_change_datat   more_changes_or_trailert   slurp_to_endt   current_blockR#   t   statet	   old_stateR   t	   top_matcht   blank_matcht   pairst   all_keysR   t   pairt   kv_matchR-   R.   t	   val_matcht   commentt   emacs_matcht	   vim_matcht	   cvs_matcht   comments_matcht   more_comments_matcht   change_matcht	   end_matcht   end_no_details_match(    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyRJ      s:   										"								c         C   s   |  j  d j S(   s,   Return a Version object for the last versioni    (   RH   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   get_version  s    c         C   s   t  |  |  j d _ d S(   sw   Set the version of the last changelog block

        version can be a full version string, or a Version object
        i    N(   R   RH   R   (   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   set_version  s    t   docs'   Version object for last changelog blockc         C   s
   |  j  j S(   N(   R   t   full_version(   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   <lambda>  s    c         C   s
   |  j  j S(   N(   R   t   epoch(   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR     s    c         C   s
   |  j  j S(   N(   R   t   debian_revision(   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR     s    c         C   s
   |  j  j S(   N(   R   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR     s    c         C   s
   |  j  j S(   N(   R   t   upstream_version(   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR     s    c         C   s   |  j  d j S(   s4   Returns the name of the package in the last version.i    (   RH   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   get_package  s    c         C   s   | |  j  d _ d  S(   Ni    (   RH   R   (   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   set_package  s    s'   Name of the package in the last versionc         C   s   g  |  j  D] } | j ^ q
 S(   s@   Returns a list of version objects that the package went through.(   RH   R   (   R   R>   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   get_versions  s    s0   List of version objects the package went throughc         C   s   g  |  j  D] } | j ^ q
 S(   N(   RH   R   (   R   R>   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   _raw_versions  s    c         C   sS   g  } | j  d j |  j   x$ |  j D] } | j  t |   q) Wd j |  S(   Nu   
u    (   R1   t   joinRI   RH   R@   (   R   t   piecesR>   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR?     s
    c         C   s   t  |   j |  j  S(   N(   R@   RA   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR     s    c         C   s   t  |  j  S(   N(   t   iterRH   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   __iter__  s    c         C   s   t  |  j  S(   N(   R5   RH   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   __len__  s    c         C   s   | |  j  d _ d  S(   Ni    (   RH   R   (   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   set_distributions  s    c         C   s   |  j  d j S(   Ni    (   RH   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR     s    c         C   s   | |  j  d _ d  S(   Ni    (   RH   R   (   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   set_urgency  s    c         C   s   |  j  d j S(   Ni    (   RH   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR     s    c         C   s   |  j  d j |  d  S(   Ni    (   RH   R;   (   R   R8   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR;     s    c         C   s   | |  j  d _ d  S(   Ni    (   RH   R   (   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt
   set_author  s    c         C   s   |  j  d j S(   Ni    (   RH   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR     s    c         C   s   | |  j  d _ d  S(   Ni    (   RH   R   (   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   set_date  s    c         C   s   |  j  d j S(   Ni    (   RH   R   (   R   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyR     s    c         K   sC   | j  d |  j  t |   } | j d  |  j j d |  d  S(   NR$   R   i    (   t
   setdefaultR   R   R2   RH   R7   (   R   t   kwargsR>   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt	   new_block  s    c         C   s   | j  |  j    d  S(   N(   t   writeR   (   R   RK   (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   write_to_open_file  s    N('   R   R   R   R   R    R	   R   RO   RJ   R   R   RB   R   R   R   t   debian_versionR   R   R   R   R   R   t   versionsR   R?   R   R   R   R   R   R   R   R;   R   R   R   R   R   R   (    (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyRD      sN   																							c          C   sa  t  j }  t j d  } d |  k rx | j |  d  } | rx d |  k r_ | j d  |  d <n  | j d  |  d <qx n  d |  k s d |  k r d |  k r | j |  d  } | r d |  k r | j d  |  d <n  | j d  |  d <q q n  d |  k r|  d } nd d |  k r%|  d } nK y+ t j d d	 t j t  j	    j
  } Wn t t f k
 rod } n Xd |  k r|  d } n d |  k r|  d } n d } t  j j d
  rt d
  } z | j   j   } Wd | j   Xn  | st j   } n  | rBt j t  j	    j } | s/d } qBd | | f } n  | rQ| } n d } | | f S(   s  Get the maintainer information in the same manner as dch.

    This function gets the information about the current user for
    the maintainer field using environment variables of gecos
    informations as approriate.

    It uses the same methods as dch to get the information, namely
    DEBEMAIL, DEBFULLNAME, EMAIL, NAME, /etc/mailname and gecos.

    :returns: a tuple of the full name, email pair as strings.
        Either of the pair may be None if that value couldn't
        be determined.
    s   ^(.*)\s+<(.*)>$t   DEBEMAILt   DEBFULLNAMEi   i   t   EMAILt   NAMEs   ,.*R   s   /etc/mailnameNs   %s@%s(   t   ost   environt   ret   compileR+   RY   t   subt   pwdt   getpwuidt   getuidt   pw_gecost   KeyErrort   AttributeErrorR   t   patht   existst   opent   readlineRT   t   closet   sockett   getfqdnt   pw_name(   t   envt   regext	   match_objt
   maintainert   emailt   addrt   ft   user(    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   get_maintainer  sX    	+
		('   R   R   R   R   R   RL   t   debian_supportt   StandardErrorR    R   R   R   t   objectR   R   t
   IGNORECASERX   R6   R8   Rk   Rl   R\   R]   R*   R^   R_   R`   Ra   Rb   Rc   Rd   Re   Rf   Rg   Rh   Ri   Rj   RD   R   (    (    (    s4   /usr/lib/python2.7/dist-packages/debian/changelog.pyt   <module>   sR   
f					 2