ó
@¾^Yc           @   s|   d  Z  d d l Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d Z e j d e j ƒ Z d	 e	 f d
 „  ƒ  YZ
 d „  Z d S(   s´   

PEP386-version comparison algorithm.

(c) Tarek Ziade and others
extracted unmodified from https://bitbucket.org/tarek/distutilsversion
licensed under the PSF license (i guess)

iÿÿÿÿNt   IrrationalVersionErrorc           B   s   e  Z d  Z RS(   s   This is an irrational version.(   t   __name__t
   __module__t   __doc__(    (    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyR       s   t   HugeMajorVersionNumErrorc           B   s   e  Z d  Z RS(   sû   An irrational version because the major version number is huge
    (often because a year or date was used).

    See `error_on_huge_major_num` option in `NormalizedVersion` for details.
    This guard can be disabled by setting that option False.
    (   R   R   R   (    (    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyR      s   t   fs’  
    ^
    (?P<version>\d+\.\d+)          # minimum 'N.N'
    (?P<extraversion>(?:\.\d+)*)   # any number of extra '.N' segments
    (?:
        (?P<prerel>[abc]|rc)       # 'a'=alpha, 'b'=beta, 'c'=release candidate
                                   # 'rc'= alias for release candidate
        (?P<prerelversion>\d+(?:\.\d+)*)
    )?
    (?P<postdev>(\.post(?P<post>\d+))?(\.dev(?P<dev>\d+))?)?
    $t   NormalizedVersionc           B   sª   e  Z d  Z e d „ Z e e e d „ ƒ Z e d „ Z e d d „ Z	 d „  Z
 e d „  ƒ Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sI  A rational version.

    Good:
        1.2         # equivalent to "1.2.0"
        1.2.0
        1.2a1
        1.2.3a2
        1.2.3b1
        1.2.3c1
        1.2.3.4
        TODO: fill this out

    Bad:
        1           # mininum two numbers
        1.2a        # release level must have a release serial
        1.2.3b
    c         C   s   |  j  | | ƒ d S(   sb  Create a NormalizedVersion instance from a version string.

        @param s {str} The version string.
        @param error_on_huge_major_num {bool} Whether to consider an
            apparent use of a year or full date as the major version number
            an error. Default True. One of the observed patterns on PyPI before
            the introduction of `NormalizedVersion` was version numbers like this:
                2009.01.03
                20040603
                2005.01
            This guard is here to strongly encourage the package author to
            use an alternate version, because a release deployed into PyPI
            and, e.g. downstream Linux package managers, will forever remove
            the possibility of using a version number like "1.0" (i.e.
            where the major number is less than that huge major number).
        N(   t   _parse(   t   selft   st   error_on_huge_major_num(    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyt   __init__L   s    c         C   s   |  |  j  | | | f ƒ ƒ S(   N(   t   parts_to_str(   t   clst   versiont
   prereleaset   devpost(    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyt
   from_parts_   s    c         C   s*  t  j | ƒ } | s$ t | ƒ ‚ n  | j ƒ  } g  } |  j | d | t d ƒ } | j d ƒ } | d k rŠ | |  j | d | ƒ 7} n  | j t	 | ƒ ƒ | j d ƒ } | d k	 rü | g } | |  j | j d ƒ | d d ƒ7} | j t	 | ƒ ƒ n | j t
 ƒ | j d	 ƒ rÉ| j d
 ƒ }	 | j d ƒ }
 g  } |	 d k	 r‹| j t
 d d
 t |	 ƒ g ƒ |
 d k r‹| j t
 d ƒ q‹n  |
 d k	 r³| j d t |
 ƒ g ƒ n  | j t	 | ƒ ƒ n | j t
 ƒ t	 | ƒ |  _ | r&|  j d d d k r&t d |  j d d | f ƒ ‚ n  d S(   s#   Parses a string version into parts.R   i   t   extraversiont    i   t   prerelt   prerelversiont   pad_zeros_lengtht   postdevt   postt   devi    i¼  sD   huge major version number, %r, which might cause future problems: %rN(   R   N(   t
   VERSION_REt   searchR    t	   groupdictt   _parse_numdotst   Falset   gett   Nonet   appendt   tuplet   FINAL_MARKERt   extendt   intt   partsR   (   R   R	   R
   t   matcht   groupsR&   t   blockR   R   R   R   R   (    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyR   d   sD    	
 i    c         C   sÈ   g  } xe | j  d ƒ D]T } t | ƒ d k rW | d d k rW t d | | f ƒ ‚ n  | j t | ƒ ƒ q W| rž x' | rš | d d k rš | j ƒ  qw Wn  x# t | ƒ | k  rÃ | j d ƒ q¡ W| S(   så  Parse 'N.N.N' sequences, return a list of ints.

        @param s {str} 'N.N.N..." sequence to be parsed
        @param full_ver_str {str} The full version string from which this
            comes. Used for error strings.
        @param drop_trailing_zeros {bool} Whether to drop trailing zeros
            from the returned list. Default True.
        @param pad_zeros_length {int} The length to which to pad the
            returned list with zeros, if necessary. Default 0.
        t   .i   i    t   0s>   cannot have leading zero in version number segment: '%s' in %riÿÿÿÿ(   t   splitt   lenR    R!   R%   t   pop(   R   R	   t   full_ver_strt   drop_trailing_zerosR   t   numst   n(    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyR   ’   s    "c         C   s   |  j  |  j ƒ S(   N(   R   R&   (   R   (    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyt   __str__¬   s    c         C   sö   | \ } } } d j  d „  | Dƒ ƒ } | t k	 rf | | d 7} | d j  d „  | d Dƒ ƒ 7} n  | rò | t k	 rò | d d k r• | d } n  d } xT | t | ƒ k  rî | d d k rÍ | d 7} n  | t | | ƒ 7} | d 7} qž Wn  | S(   sO   Transforms a version expressed in tuple into its string
        representation.R*   c         s   s   |  ] } t  | ƒ Vq d  S(   N(   t   str(   t   .0t   v(    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pys	   <genexpr>µ   s    i    c         s   s   |  ] } t  | ƒ Vq d  S(   N(   R4   (   R5   R6   (    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pys	   <genexpr>¸   s    i   R   i   (   t   joinR#   R-   R4   (   R   R&   t   mainR   R   R	   t   i(    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyR   ¯   s    $c         C   s   d |  j  j |  f S(   Ns   %s('%s')(   t	   __class__R   (   R   (    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyt   __repr__Ä   s    c         C   s,   t  d t |  ƒ j t | ƒ j f ƒ ‚ d  S(   Ns   cannot compare %s and %s(   t	   TypeErrort   typeR   (   R   t   other(    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyt   _cannot_compareÇ   s    c         C   s/   t  | t ƒ s |  j | ƒ n  |  j | j k S(   N(   t
   isinstanceR   R?   R&   (   R   R>   (    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyt   __eq__Ë   s    c         C   s/   t  | t ƒ s |  j | ƒ n  |  j | j k  S(   N(   R@   R   R?   R&   (   R   R>   (    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyt   __lt__Ð   s    c         C   s   |  j  | ƒ S(   N(   RA   (   R   R>   (    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyt   __ne__Õ   s    c         C   s   |  j  | ƒ p |  j | ƒ S(   N(   RB   RA   (   R   R>   (    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyt   __gt__Ø   s    c         C   s   |  j  | ƒ p |  j | ƒ S(   N(   RA   RB   (   R   R>   (    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyt   __le__Û   s    c         C   s   |  j  | ƒ p |  j | ƒ S(   N(   RA   RD   (   R   R>   (    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyt   __ge__Þ   s    (   R   R   R   t   TrueR   t   classmethodR#   R   R   R   R3   R   R;   R?   RA   RB   RC   RD   RE   RF   (    (    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyR   :   s$   .								c         C   s  y t  |  ƒ |  SWn t k
 r% n X|  j ƒ  } xS d2 d3 d4 d5 d6 d7 d8 d9 d: d; d< d= d> d? d@ f D] \ } } | j | | ƒ } qf Wt j d d | ƒ } t j d d | ƒ } t j d d | ƒ } t j d d | ƒ } t j d d | ƒ } | j d ƒ r| d  } n  t j d! d | ƒ } t j d" d# | ƒ } t j d$ d% | ƒ } t j d& d | ƒ } t j d' d( | ƒ } t j d) d( | ƒ } t j d* d
 | ƒ } t j d+ d, | ƒ } t j d- d% | ƒ } t j d. d/ | ƒ } t j d0 d1 | ƒ } y t  | ƒ | SWn t k
 rn XdA S(B   sè  Suggest a normalized version close to the given version string.

    If you have a version string that isn't rational (i.e. NormalizedVersion
    doesn't like it) then you might be able to get an equivalent (or close)
    rational version from this function.

    This does a number of simple normalizations to the given string, based
    on observation of versions currently in use on PyPI. Given a dump of
    those version during PyCon 2009, 4287 of them:
    - 2312 (53.93%) match NormalizedVersion without change
    - with the automatic suggestion
    - 3474 (81.04%) match when using this suggestion method

    @param s {str} An irrational version string.
    @returns A rational version string, or None, if couldn't determine one.
    s   -alphat   as   -betat   bt   alphat   betat   rct   cs   -finalR   s   -pres   -releases   .releases   -stablet   +R*   t   _t    s   .finalt   finals   pre$t   pre0s   dev$t   dev0s   ([abc|rc])[\-\.](\d+)$s   \1\2s   [\-\.](dev)[\-\.]?r?(\d+)$s   .\1\2s   [.~]?([abc])\.?s   \1R6   i   s   \b0+(\d+)(?!\d)s   (\d+[abc])$s   \g<1>0s   \.?(dev-r|dev\.r)\.?(\d+)$s   .dev\2s   -(a|b|c)(\d+)$s   [\.\-](dev|devel)$s   .dev0s   (?![\.\-])dev$s   (final|stable)$s   \.?(r|-|-r)\.?(\d+)$s   .post\2s   \.?(dev|git|bzr)\.?(\d+)$s   \.?(pre|preview|-c)(\d+)$s   c\g<2>s   p(\d+)$s   .post\1(   s   -alphaRI   (   s   -betaRJ   (   s   alphaRI   (   s   betaRJ   (   s   rcRN   (   s   -finalR   (   s   -preRN   (   s   -releaseR   (   s   .releaseR   (   s   -stableR   (   RO   R*   (   RP   R*   (   RQ   R   (   s   .finalR   (   s   finalR   N(   R   R    t   lowert   replacet   ret   subt
   startswithR    (   R	   t   rst   origt   repl(    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyt   suggest_normalized_versionâ   sJ    
			
(   R   (   R   RW   t	   ExceptionR    R   R#   t   compilet   VERBOSER   t   objectR   R]   (    (    (    s(   /tmp/pip-build-UnxK1c/tox/tox/_verlib.pyt   <module>	   s   
¨