ó
AqzRc           @   s[   d  Z  d e f d     YZ d e f d     YZ e d k rW d d l Z e j   n  d S(   s   Parse debian/source/formatt   DebianSourceFormatErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s2   /usr/lib/python2.7/dist-packages/gbp/deb/format.pyR       s   t   DebianSourceFormatc           B   sn   e  Z d  Z d Z d   Z d   Z e d    Z e d    Z d   Z	 e
 d    Z e
 d	 d   Z RS(
   sĐ  
    Contents of debian/source/format

    >>> d = DebianSourceFormat("3.0 (quilt)")
    >>> d.type
    'quilt'
    >>> d.version
    '3.0'
    >>> d = DebianSourceFormat("3.0 (native)")
    >>> d.type
    'native'
    >>> d = DebianSourceFormat("1.0")
    >>> d.type
    >>> d.version
    '1.0'
    >>> d = DebianSourceFormat("1.0 broken")
    Traceback (most recent call last):
    ...
    DebianSourceFormatError: Cannot get source format from '1.0 broken'
    s   debian/source/formatc         C   s   | j    } | d |  _ t |  d k r} | d d d k rj | d d d k rj | d d d !|  _ q} t d |   n  d  S(   Ni    i   i   t   (i˙˙˙˙t   )s"   Cannot get source format from '%s'(   t   splitt   _versiont   lent   _typeR    (   t   selft   contentt   parts(    (    s2   /usr/lib/python2.7/dist-packages/gbp/deb/format.pyt   _parse-   s    c         C   s#   d  |  _ d  |  _ |  j |  d  S(   N(   t   NoneR   R	   R   (   R
   R   (    (    s2   /usr/lib/python2.7/dist-packages/gbp/deb/format.pyt   __init__9   s    		c         C   s   |  j  S(   s    The source format version number(   R   (   R
   (    (    s2   /usr/lib/python2.7/dist-packages/gbp/deb/format.pyt   version>   s    c         C   s   |  j  S(   s   The 'type' (e.g. git, native)(   R	   (   R
   (    (    s2   /usr/lib/python2.7/dist-packages/gbp/deb/format.pyt   typeC   s    c         C   s   d |  j  |  j f S(   Ns   %s (%s)(   R   R	   (   R
   (    (    s2   /usr/lib/python2.7/dist-packages/gbp/deb/format.pyt   __str__H   s    c         C   s)   t  |   } |  | j    SWd QXd S(   ső  
        Parse debian/source/format file

        @param filename: the file to parse
        @type filename: C{str}
        @returns: a debisn/source/format object
        @rtype: L{DebianSourceFormat}

        >>> import tempfile, os
        >>> with tempfile.NamedTemporaryFile(delete=False) as t:
        ...    t.write("3.0 (quilt)")
        >>> d = DebianSourceFormat.parse_file(t.name)
        >>> d.version
        '3.0'
        >>> d.type
        'quilt'
        >>> os.unlink(t.name)
        N(   t   opent   read(   t   klasst   filenamet   f(    (    s2   /usr/lib/python2.7/dist-packages/gbp/deb/format.pyt
   parse_fileK   s    c      	   C   sQ   | p |  j  } t |  j  d   } | j d | | f  Wd QX|  j |  j   S(   s  
        Write a format file from I{type} and I{format} at
        I{format_file}

        @param version: the source package format version
        @param type: the format type
        @param format_file: the format file to create with
            the above parameters
        t   ws   %s (%s)N(   t   format_fileR   t   writeR   (   R   R   R   R   R   (    (    s2   /usr/lib/python2.7/dist-packages/gbp/deb/format.pyt   from_contentb   s    N(   R   R   t   __doc__R   R   R   t   propertyR   R   R   t   classmethodR   R   R   (    (    (    s2   /usr/lib/python2.7/dist-packages/gbp/deb/format.pyR      s   			t   __main__i˙˙˙˙N(   R   t	   ExceptionR    t   objectR   R   t   doctestt   testmod(    (    (    s2   /usr/lib/python2.7/dist-packages/gbp/deb/format.pyt   <module>   s
   \