ó
[³XMc           @   sv   d  Z  d d l Z d d l Z d e f d „  ƒ  YZ e ƒ  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 „  Z d S(
   s0   
Versions for Python packages.

See L{Version}.
iÿÿÿÿNt   _infc           B   s   e  Z d  Z d „  Z RS(   s:   
    An object that is bigger than all other objects.
    c         C   s   | t  k r d Sd S(   s‘   
        @param other: Another object.
        @type other: any

        @return: 0 if other is inf, 1 otherwise.
        @rtype: C{int}
        i    i   (   R    (   t   selft   other(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/versions.pyt   __cmp__   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/versions.pyR       s   t   IncomparableVersionsc           B   s   e  Z d  Z RS(   s-   
    Two versions could not be compared.
    (   R   R   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/versions.pyR   !   s   t   Versionc           B   sw   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z e Z e Z d	 „  Z d
 „  Z RS(   s   
    An object that represents a three-part version number.

    If running from an svn checkout, include the revision number in
    the version string.
    c         C   s1   | |  _  | |  _ | |  _ | |  _ | |  _ d S(   s¥  
        @param package: Name of the package that this is a version of.
        @type package: C{str}
        @param major: The major version number.
        @type major: C{int}
        @param minor: The minor version number.
        @type minor: C{int}
        @param micro: The micro version number.
        @type micro: C{int}
        @param prerelease: The prerelease number.
        @type prerelease: C{int}
        N(   t   packaget   majort   minort   microt
   prerelease(   R   R	   R
   R   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/versions.pyt   __init__-   s
    				c         C   s9   |  j  ƒ  } |  j ƒ  } | r5 | d t | ƒ 7} n  | S(   so   
        Return a string in canonical short version format,
        <major>.<minor>.<micro>[+rSVNVer].
        s   +r(   t   baset   _getSVNVersiont   str(   R   t   st   svnver(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/versions.pyt   shortA   s
    c         C   sE   |  j  d k r d } n d |  j  f } d |  j |  j |  j | f S(   s:   
        Like L{short}, but without the +rSVNVer.
        t    s   pre%ss
   %d.%d.%d%sN(   R   t   NoneR
   R   R   (   R   t   pre(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/versions.pyR   M   s    		c         C   sv   |  j  ƒ  } | r d | } n  |  j d  k r7 d } n d |  j f } d |  j j |  j |  j |  j |  j | | f S(   Ns     #R   s   , prerelease=%rs   %s(%r, %d, %d, %d%s)%s(	   t   _formatSVNVersionR   R   t	   __class__R   R	   R
   R   R   (   R   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/versions.pyt   __repr__[   s    		c         C   s   d |  j  |  j ƒ  f S(   Ns   [%s, version %s](   R	   R   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/versions.pyt   __str__m   s    c         C   sÆ   t  | |  j ƒ s t S|  j | j k rG t d |  j | j f ƒ ‚ n  |  j d k r_ t } n	 |  j } | j d k r€ t } n	 | j } t |  j	 |  j
 |  j | f | j	 | j
 | j | f ƒ } | S(   sG  
        Compare two versions, considering major versions, minor versions, micro
        versions, then prereleases.

        A version with a prerelease is always less than a version without a
        prerelease. If both versions have prereleases, they will be included in
        the comparison.

        @param other: Another version.
        @type other: L{Version}

        @return: NotImplemented when the other object is not a Version, or one
            of -1, 0, or 1.

        @raise IncomparableVersions: when the package names of the versions
            differ.
        s   %r != %rN(   t
   isinstanceR   t   NotImplementedR	   R   R   R   R    t   cmpR
   R   R   (   R   R   R   t   otherpret   x(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/versions.pyR   s   s(    					c         C   sq   d d l  m } | | ƒ j } xK | j D]@ } t | d ƒ r) | j d ƒ } | d k	 ri | j d ƒ Sq) q) Wd S(   sû   
        Given a readable file object which represents a .svn/entries file in
        format version 4, return the revision as a string.  We do this by
        reading first XML element in the document that has a 'revision'
        attribute.
        iÿÿÿÿ(   t   parset   getAttributet   revisiont   asciiN(   t   xml.dom.minidomR!   t   documentElementt
   childNodest   hasattrR"   R   t   encode(   R   t   entriesFileR!   t   doct   nodet   rev(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/versions.pyt   _parseSVNEntries_4    s    c         C   s.   | j  ƒ  | j  ƒ  | j  ƒ  | j  ƒ  j ƒ  S(   s‘   
        Given a readable file object which represents a .svn/entries file in
        format version 8, return the revision as a string.
        (   t   readlinet   strip(   R   R*   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/versions.pyt   _parseSVNEntries_8°   s    


c         C   s  t  j j |  j ƒ } | rt j j t j j | j ƒ d ƒ } t j j	 | ƒ sU d St j j | d ƒ } t j j	 | ƒ r­ t | ƒ j ƒ  j ƒ  } t |  d | d ƒ } n	 |  j } | d k rÆ d St j j | d ƒ } t | ƒ } y  z | | ƒ SWd | j ƒ  XWqd SXn  d S(   s?  
        Figure out the SVN revision number based on the existance of
        <package>/.svn/entries, and its contents. This requires discovering the
        format version from the 'format' file and parsing the entries file
        accordingly.

        @return: None or string containing SVN Revision number.
        s   .svnt   formatt   _parseSVNEntries_t   Unknownt   entriesN(   t   syst   modulest   getR	   t   ost   patht   joint   dirnamet   __file__t   existsR   t   filet   readR0   t   getattrt   _parseSVNEntriesTenPlust   close(   R   t   modt   svnt
   formatFileR2   t   parserR*   R5   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/versions.pyR   Á   s(    	$	c         C   s'   |  j  ƒ  } | d  k r d Sd | f S(   NR   s
    (SVN r%s)(   R   R   (   R   t   ver(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/versions.pyR   é   s    N(   R   R   R   R   R   R   R   R   R   R   R.   R1   t   _parseSVNEntries_9RB   R   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/versions.pyR   &   s   					-			(c         C   s   d |  j  |  j ƒ  f } | S(   s®   
    Get a friendly string for the given version object.

    @param version: A L{Version} object.
    @return: A string containing the package and short version number.
    s   %s %s(   R	   R   (   t   versiont   result(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/versions.pyt   getVersionStringñ   s    (	   R   R6   R9   t   objectR    t	   TypeErrorR   R   RL   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/versions.pyt   <module>	   s   	Ë