ó
è¾bc           @   sÈ   d  Z  d d l Z d d l Z d d l Z e j d ƒ Z e j d ƒ Z e j d ƒ Z d „  Z	 i e j
 d 6e j d 6e j d	 6e j d
 6e j d 6e j d 6Z d d d „  ƒ  YZ d a d „  Z d S(   sB   Module for parsing and testing package version predicate strings.
iÿÿÿÿNs'   (?i)^\s*([a-z_]\w*(?:\.[a-z_]\w*)*)(.*)s   ^\s*\((.*)\)\s*$s%   ^\s*(<=|>=|<|>|!=|==)\s*([^\s,]+)\s*$c         C   sP   t  j |  ƒ } | s( t d |  ƒ ‚ n  | j ƒ  \ } } | t j j | ƒ f S(   sV   Parse a single version comparison.

    Return (comparison string, StrictVersion)
    s"   bad package restriction syntax: %r(   t   re_splitComparisont   matcht
   ValueErrort   groupst	   distutilst   versiont   StrictVersion(   t   predt   rest   compt   verStr(    (    s0   /usr/lib/python2.7/distutils/versionpredicate.pyt   splitUp   s
    t   <s   <=s   ==t   >s   >=s   !=t   VersionPredicatec           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s»  Parse and test package version predicates.

    >>> v = VersionPredicate('pyepat.abc (>1.0, <3333.3a1, !=1555.1b3)')

    The `name` attribute provides the full dotted name that is given::

    >>> v.name
    'pyepat.abc'

    The str() of a `VersionPredicate` provides a normalized
    human-readable version of the expression::

    >>> print v
    pyepat.abc (> 1.0, < 3333.3a1, != 1555.1b3)

    The `satisfied_by()` method can be used to determine with a given
    version number is included in the set described by the version
    restrictions::

    >>> v.satisfied_by('1.1')
    True
    >>> v.satisfied_by('1.4')
    True
    >>> v.satisfied_by('1.0')
    False
    >>> v.satisfied_by('4444.4')
    False
    >>> v.satisfied_by('1555.1b3')
    False

    `VersionPredicate` is flexible in accepting extra whitespace::

    >>> v = VersionPredicate(' pat( ==  0.1  )  ')
    >>> v.name
    'pat'
    >>> v.satisfied_by('0.1')
    True
    >>> v.satisfied_by('0.2')
    False

    If any version numbers passed in do not conform to the
    restrictions of `StrictVersion`, a `ValueError` is raised::

    >>> v = VersionPredicate('p1.p2.p3.p4(>=1.0, <=1.3a1, !=1.2zb3)')
    Traceback (most recent call last):
      ...
    ValueError: invalid version number '1.2zb3'

    It the module or package name given does not conform to what's
    allowed as a legal module or package name, `ValueError` is
    raised::

    >>> v = VersionPredicate('foo-bar')
    Traceback (most recent call last):
      ...
    ValueError: expected parenthesized list: '-bar'

    >>> v = VersionPredicate('foo bar (12.21)')
    Traceback (most recent call last):
      ...
    ValueError: expected parenthesized list: 'bar (12.21)'

    c         C   sÿ   | j  ƒ  } | s! t d ƒ ‚ n  t j | ƒ } | sI t d | ƒ ‚ n  | j ƒ  \ |  _ } | j  ƒ  } | rò t j | ƒ } | s˜ t d | ƒ ‚ n  | j ƒ  d } g  | j d ƒ D] } t | ƒ ^ q¸ |  _	 |  j	 sû t d | ƒ ‚ qû n	 g  |  _	 d S(   s*   Parse a version predicate string.
        s   empty package restrictions   bad package name in %rs   expected parenthesized list: %ri    t   ,s   empty parenthesized list in %rN(
   t   stripR   t   re_validPackageR   R   t   namet   re_parent   splitR   R   (   t   selft   versionPredicateStrR   t   parent   strt   aPred(    (    s0   /usr/lib/python2.7/distutils/versionpredicate.pyt   __init___   s$    +	c         C   s`   |  j  rU g  |  j  D]  \ } } | d t | ƒ ^ q } |  j d d j | ƒ d S|  j Sd  S(   Nt    s    (s   , t   )(   R   R   R   t   join(   R   t   condt   vert   seq(    (    s0   /usr/lib/python2.7/distutils/versionpredicate.pyt   __str__z   s    	0c         C   s5   x. |  j  D]# \ } } t | | | ƒ s
 t Sq
 Wt S(   sÏ   True if version is compatible with all the predicates in self.
        The parameter version must be acceptable to the StrictVersion
        constructor.  It may be either a string or StrictVersion.
        (   R   t   compmapt   Falset   True(   R   R   R   R   (    (    s0   /usr/lib/python2.7/distutils/versionpredicate.pyt   satisfied_by   s    (   t   __name__t
   __module__t   __doc__R   R!   R%   (    (    (    s0   /usr/lib/python2.7/distutils/versionpredicate.pyR      s   ?		c         C   s•   t  d k r t j d ƒ a  n  |  j ƒ  }  t  j |  ƒ } | sR t d |  ƒ ‚ n  | j d ƒ pd d } | r‚ t j	 j
 | ƒ } n  | j d ƒ | f S(   s9  Return the name and optional version number of a provision.

    The version number, if given, will be returned as a `StrictVersion`
    instance, otherwise it will be `None`.

    >>> split_provision('mypkg')
    ('mypkg', None)
    >>> split_provision(' mypkg( 1.2 ) ')
    ('mypkg', StrictVersion ('1.2'))
    s=   ([a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*)(?:\s*\(\s*([^)\s]+)\s*\))?$s"   illegal provides specification: %ri   i   N(   t   _provision_rxt   Nonet   ret   compileR   R   R   t   groupR   R   R   (   t   valuet   mR   (    (    s0   /usr/lib/python2.7/distutils/versionpredicate.pyt   split_provisionŽ   s    (    (   R(   R+   t   distutils.versionR   t   operatorR,   R   R   R    R   t   ltt   let   eqt   gtt   get   neR"   R   R*   R)   R0   (    (    (    s0   /usr/lib/python2.7/distutils/versionpredicate.pyt   <module>   s   	!!n