U
    ꥡc                     @   s  d Z ddlmZ ddlZddlZddlmZmZ ddlZddl	Z	ddl
Z
ddlZe
jd dkZe
jd dkZdZdZd	Zd
dgZdZdZdZeedsdd ZereefZeZeZdd Zdd Zn e efZe ZeZdd Zdd ZdXddZ!ddde"fddZ#e#dddd  Z$d!d" Z%G d#d$ d$e&Z'e#d%dd&d'd( Z(d)d* Z)e#ddd+d, Z*e#ddd-d. Z+e#d/d0d&d1d2 Z,e#d3d0d&d4d5 Z-e#d6dd&dYd7d8Z.e#ddd9d: Z/e#ddd;d< Z0e#ddd=d> Z1e#dddZd@dAZ2e#ddd[dCdDZ3e#dddEdF Z4e#dddGdH Z5dIdJ Z6dKdL Z7dMdN Z8dOdP Z9dQdR Z:dSdT Z;d\dUdVZ<e=dWkr~ddl>Z>e>?  dS )]z:Python helper for Semantic Versioning (http://semver.org/)    )print_functionN)wrapspartial      z2.13.0zKostiantyn Rybnikovzk-bx@k-bx.comzSebastien CelleszTom Schraitlezs.celles@gmail.com)
bump_build
bump_major
bump_minor
bump_patchbump_prereleasecompare
deprecatedfinalize_versionformat_versionmatchmax_vermin_verparseparse_version_inforeplacecmd_bump	cmd_checkcmd_comparecreateparsermainprocessSEMVER_SPEC_VERSIONVersionInfoz2.0.0cmpc                 C   s   | |k| |k  S )z6Return negative if a<b, zero if a==b, positive if a>b. abr   r   */tmp/pip-unpacked-wheel-wk009ffn/semver.pyr   >   s    c                 C   s
   |  dS )Nzlatin-1)encodesr   r   r#   r"   H   s    r"   c                 C   s   | S Nr   r%   r   r   r#   uK   s    r(   c                 C   s   | S r'   r   r%   r   r   r#   r"   T   s    c                 C   s   t | dddS )Nz\\z\\\\Zunicode_escape)unicoder   r%   r   r   r#   r(   X   s    utf-8strictc                 C   sX   t | ttfstdt|  tr:t | tr:| ||} ntrTt | trT| ||} | S )z
    Coerce *s* to `str`.

    For Python 2:
      - `unicode` -> encoded to `str`
      - `str` -> `str`

    For Python 3:
      - `str` -> `str`
      - `bytes` -> decoded to `str`
    znot expecting type '%s')	
isinstance	text_typebinary_type	TypeErrortypePY2r$   PY3decode)r&   encodingerrorsr   r   r#   
ensure_str\   s    r6   c                    s6   dkrt t dS t fdd}|S )a  
    Decorates a function to output a deprecation warning.

    :param func: the function to decorate (or None)
    :param str replace: the function to replace (use the full qualified
        name like ``semver.VersionInfo.bump_major``.
    :param str version: the first version when this function was deprecated.
    :param category: allow you to specify the deprecation warning class
        of your choice. By default, it's  :class:`DeprecationWarning`, but
        you can choose :class:`PendingDeprecationWarning` or a custom class.
    N)r   versioncategoryc                     s   dg}r| d | d r.| d n
| d tdrHjnj}pT|}t j}d|}tj	|j
j||d t|j|jd	 ~| |S )
Nz!Function '{m}.{f}' is deprecated.zDeprecated since version {v}. z*This function will be removed in semver 3.zUse {r!r} instead.z4Use the respective 'semver.VersionInfo.{r}' instead.__qualname__ )mfrv)r8   filenamelineno)appendhasattrr9   __name__inspectcurrentframef_backjoinwarningswarn_explicitformat
__module__getfilef_codef_lineno)argskwargsmsgr<   r=   framer8   funcr   r7   r   r#   wrapper   s&    





	zdeprecated.<locals>.wrapper)r   r   r   )rT   r   r7   r8   rU   r   rS   r#   r   r   s
    r   2.10.0r7   c                 C   s   t |  S )aK  
    Parse version to major, minor, patch, pre-release, build parts.

    .. deprecated:: 2.10.0
       Use :func:`semver.VersionInfo.parse` instead.

    :param version: version string
    :return: dictionary with the keys 'build', 'major', 'minor', 'patch',
             and 'prerelease'. The prerelease or build keys can be None
             if not provided
    :rtype: dict

    >>> ver = semver.parse('3.4.5-pre.2+build.4')
    >>> ver['major']
    3
    >>> ver['minor']
    4
    >>> ver['patch']
    5
    >>> ver['prerelease']
    'pre.2'
    >>> ver['build']
    'build.4'
    )r   r   to_dictrW   r   r   r#   r      s    r   c                    s   t   fdd}|S )z4Wrap a VersionInfo binary op method in a type-check.c                    s8   t tttttf}t||s.tdt||f  | |S )Nzother type %r must be in %r)	r   dicttuplelistr-   r.   r,   r/   r0   )selfotherZcomparable_typesoperatorr   r#   rU      s    
zcomparator.<locals>.wrapper)r   )r_   rU   r   r^   r#   
comparator   s    r`   c                   @   s  e Zd ZdZdZedZedejZ	dVddZ
ed	d
 Zejdd
 Zedd Zejdd Zedd Zejdd Zedd Zejdd Zedd Zejdd Zdd Zdd Zeddddd  Zeje_ed!ddd"d# Zeje_d$d% Zed&d' Zd(d) Zd*d+ Zd,d- ZdWd/d0ZdXd2d3Zd4d5 ZdYd6d7Z e!d8d9 Z"e!d:d; Z#e!d<d= Z$e!d>d? Z%e!d@dA Z&e!dBdC Z'dDdE Z(dFdG Z)dHdI Z*dJdK Z+dLdM Z,dNdO Z-e.dPdQ Z/dRdS Z0e.dTdU Z1dS )Zr   a  
    A semver compatible version class.

    :param int major: version when you make incompatible API changes.
    :param int minor: version when you add functionality in
                      a backwards-compatible manner.
    :param int patch: version when you make backwards-compatible bug fixes.
    :param str prerelease: an optional prerelease string
    :param str build: an optional build string
    )_major_minor_patch_prerelease_buildz(?:[^\d]*(\d+)[^\d]*)+a  
            ^
            (?P<major>0|[1-9]\d*)
            \.
            (?P<minor>0|[1-9]\d*)
            \.
            (?P<patch>0|[1-9]\d*)
            (?:-(?P<prerelease>
                (?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)
                (?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*
            ))?
            (?:\+(?P<build>
                [0-9a-zA-Z-]+
                (?:\.[0-9a-zA-Z-]+)*
            ))?
            $
        r   Nc           	      C   s   |||d}|  D ].\}}t|}|||< |dk rtd|q|d | _|d | _|d | _|d krnd nt|| _|d krd nt|| _	d S )Nmajorminorpatchr   z1{!r} is negative. A version can only be positive.rg   rh   ri   )
itemsint
ValueErrorrJ   ra   rb   rc   strrd   re   )	r\   rg   rh   ri   
prereleasebuildversion_partsnamevaluer   r   r#   __init__   s     


zVersionInfo.__init__c                 C   s   | j S )z(The major part of a version (read-only).)ra   r\   r   r   r#   rg     s    zVersionInfo.majorc                 C   s   t dd S )Nzattribute 'major' is readonlyAttributeErrorr\   rr   r   r   r#   rg     s    c                 C   s   | j S )z(The minor part of a version (read-only).)rb   rt   r   r   r#   rh     s    zVersionInfo.minorc                 C   s   t dd S )Nzattribute 'minor' is readonlyru   rw   r   r   r#   rh     s    c                 C   s   | j S )z(The patch part of a version (read-only).)rc   rt   r   r   r#   ri     s    zVersionInfo.patchc                 C   s   t dd S )Nzattribute 'patch' is readonlyru   rw   r   r   r#   ri   "  s    c                 C   s   | j S )z-The prerelease part of a version (read-only).)rd   rt   r   r   r#   rn   &  s    zVersionInfo.prereleasec                 C   s   t dd S )Nz"attribute 'prerelease' is readonlyru   rw   r   r   r#   rn   +  s    c                 C   s   | j S )z(The build part of a version (read-only).)re   rt   r   r   r#   ro   /  s    zVersionInfo.buildc                 C   s   t dd S )Nzattribute 'build' is readonlyru   rw   r   r   r#   ro   4  s    c                 C   s   | j | j| j| j| jfS )ay  
        Convert the VersionInfo object to a tuple.

        .. versionadded:: 2.10.0
           Renamed ``VersionInfo._astuple`` to ``VersionInfo.to_tuple`` to
           make this function available in the public API.

        :return: a tuple with all the parts
        :rtype: tuple

        >>> semver.VersionInfo(5, 3, 1).to_tuple()
        (5, 3, 1, None, None)
        rg   rh   ri   rn   ro   rt   r   r   r#   to_tuple8  s    zVersionInfo.to_tuplec                 C   s2   t d| jfd| jfd| jfd| jfd| jffS )a:  
        Convert the VersionInfo object to an OrderedDict.

        .. versionadded:: 2.10.0
           Renamed ``VersionInfo._asdict`` to ``VersionInfo.to_dict`` to
           make this function available in the public API.

        :return: an OrderedDict with the keys in the order ``major``, ``minor``,
          ``patch``, ``prerelease``, and ``build``.
        :rtype: :class:`collections.OrderedDict`

        >>> semver.VersionInfo(3, 2, 1).to_dict()
        OrderedDict([('major', 3), ('minor', 2), ('patch', 1), ('prerelease', None), ('build', None)])
        rg   rh   ri   rn   ro   )collectionsOrderedDictrg   rh   ri   rn   ro   rt   r   r   r#   rX   H  s    zVersionInfo.to_dictzsemver.VersionInfo.to_tuplerV   r   r7   c                 C   s   |   S r'   ry   rt   r   r   r#   _astuplec  s    zVersionInfo._astuplezsemver.VersionInfo.to_dictc                 C   s   |   S r'   )rX   rt   r   r   r#   _asdicti  s    zVersionInfo._asdictc                 c   s   |   D ]
}|V  qdS )zImplement iter(self).Nr}   )r\   r>   r   r   r#   __iter__o  s    zVersionInfo.__iter__c                 C   sb   t j| }|r^tt|dd }|d\}}| dt|t| | | | |d  } | S )a  
        Look for the last sequence of number(s) in a string and increment.

        :param str string: the string to search for.
        :return: the incremented string

        Source:
        http://code.activestate.com/recipes/442460-increment-numbers-in-a-string/#c1
           N)	r   _LAST_NUMBERsearchrm   rk   groupspanmaxlen)stringr   Znext_startendr   r   r#   _increment_stringu  s    *zVersionInfo._increment_stringc                 C   s   t | }|| jd S )ag  
        Raise the major part of the version, return a new object but leave self
        untouched.

        :return: new object with the raised major part
        :rtype: :class:`VersionInfo`

        >>> ver = semver.VersionInfo.parse("3.4.5")
        >>> ver.bump_major()
        VersionInfo(major=4, minor=0, patch=0, prerelease=None, build=None)
        r   )r0   ra   r\   clsr   r   r#   r     s    zVersionInfo.bump_majorc                 C   s   t | }|| j| jd S )ag  
        Raise the minor part of the version, return a new object but leave self
        untouched.

        :return: new object with the raised minor part
        :rtype: :class:`VersionInfo`

        >>> ver = semver.VersionInfo.parse("3.4.5")
        >>> ver.bump_minor()
        VersionInfo(major=3, minor=5, patch=0, prerelease=None, build=None)
        r   )r0   ra   rb   r   r   r   r#   r	     s    zVersionInfo.bump_minorc                 C   s   t | }|| j| j| jd S )ag  
        Raise the patch part of the version, return a new object but leave self
        untouched.

        :return: new object with the raised patch part
        :rtype: :class:`VersionInfo`

        >>> ver = semver.VersionInfo.parse("3.4.5")
        >>> ver.bump_patch()
        VersionInfo(major=3, minor=4, patch=6, prerelease=None, build=None)
        r   )r0   ra   rb   rc   r   r   r   r#   r
     s    zVersionInfo.bump_patchrcc                 C   s4   t | }|| jp|pdd }|| j| j| j|S )a  
        Raise the prerelease part of the version, return a new object but leave
        self untouched.

        :param token: defaults to 'rc'
        :return: new object with the raised prerelease part
        :rtype: :class:`VersionInfo`

        >>> ver = semver.VersionInfo.parse("3.4.5-rc.1")
        >>> ver.bump_prerelease()
        VersionInfo(major=3, minor=4, patch=5, prerelease='rc.2', build=None)
        r   .0)r0   r   rd   ra   rb   rc   )r\   tokenr   rn   r   r   r#   r     s    zVersionInfo.bump_prereleasero   c                 C   s8   t | }|| jp|pdd }|| j| j| j| j|S )a  
        Raise the build part of the version, return a new object but leave self
        untouched.

        :param token: defaults to 'build'
        :return: new object with the raised build part
        :rtype: :class:`VersionInfo`

        >>> ver = semver.VersionInfo.parse("3.4.5-rc.1+build.9")
        >>> ver.bump_build()
        VersionInfo(major=3, minor=4, patch=5, prerelease='rc.1', build='build.10')
        ro   r   )r0   r   re   ra   rb   rc   rd   )r\   r   r   ro   r   r   r#   r     s    zVersionInfo.bump_buildc           	      C   s   t | }t|tr||}nNt|tr4|f |}n8t|ttfrL|| }n t||sltd|j	t || 
 dd }|
 dd }t||}|r|S | j|j }}t||}|sdS |sdS |sdS |S )aw  
        Compare self with other.

        :param other: the second version (can be string, a dict, tuple/list, or
             a VersionInfo instance)
        :return: The return value is negative if ver1 < ver2,
             zero if ver1 == ver2 and strictly positive if ver1 > ver2
        :rtype: int

        >>> semver.VersionInfo.parse("1.0.0").compare("2.0.0")
        -1
        >>> semver.VersionInfo.parse("2.0.0").compare("1.0.0")
        1
        >>> semver.VersionInfo.parse("2.0.0").compare("2.0.0")
        0
        >>> semver.VersionInfo.parse("2.0.0").compare(dict(major=2, minor=0, patch=0))
        0
        z'Expected str or {} instance, but got {}Nr   r   r   )r0   r,   string_typesr   rY   rZ   r[   r/   rJ   rC   ry   r   rn   _nat_cmp)	r\   r]   r   v1Zv2xZrc1Zrc2Zrccmpr   r   r#   r     s8    



 

zVersionInfo.comparec                 C   s   ddddh}||kr&t dj||d| }|js6|jr|dkst|dkrP|jdkst|dkr|j|j  krpdkrn n|jddd	S |d
krt|d|  S |js| }|	|S )a  
        Determines next version, preserving natural order.

        .. versionadded:: 2.10.0

        This function is taking prereleases into account.
        The "major", "minor", and "patch" raises the respective parts like
        the ``bump_*`` functions. The real difference is using the
        "preprelease" part. It gives you the next patch version of the prerelease,
        for example:

        >>> str(semver.VersionInfo.parse("0.1.4").next_version("prerelease"))
        '0.1.5-rc.1'

        :param part: One of "major", "minor", "patch", or "prerelease"
        :param prerelease_token: prefix string of prerelease, defaults to 'rc'
        :return: new object with the appropriate part raised
        :rtype: :class:`VersionInfo`
        rg   rh   ri   rn   z<Invalid part. Expected one of {validparts}, but got {part!r})
validpartspartr   N)rn   ro   rf   Zbump_)
rl   rJ   rn   ro   ri   rh   r   getattrr
   r   )r\   r   Zprerelease_tokenr   r7   r   r   r#   next_version  sB      
zVersionInfo.next_versionc                 C   s   |  |dkS Nr   r   r\   r]   r   r   r#   __eq__;  s    zVersionInfo.__eq__c                 C   s   |  |dkS r   r   r   r   r   r#   __ne__?  s    zVersionInfo.__ne__c                 C   s   |  |dk S r   r   r   r   r   r#   __lt__C  s    zVersionInfo.__lt__c                 C   s   |  |dkS r   r   r   r   r   r#   __le__G  s    zVersionInfo.__le__c                 C   s   |  |dkS r   r   r   r   r   r#   __gt__K  s    zVersionInfo.__gt__c                 C   s   |  |dkS r   r   r   r   r   r#   __ge__O  s    zVersionInfo.__ge__c                 C   s   t |trt||d }t |tr6|jdk	r6|jdk sJ|jdk	rR|jdk rRtdttdd |  | }t	|dkr|d }n|std|S )ap  
        self.__getitem__(index) <==> self[index]

        Implement getitem. If the part requested is undefined, or a part of the
        range requested is undefined, it will throw an index error.
        Negative indices are not supported

        :param Union[int, slice] index: a positive integer indicating the
               offset or a :func:`slice` object
        :raises: IndexError, if index is beyond the range or a part is None
        :return: the requested part of the version at position index

        >>> ver = semver.VersionInfo.parse("3.4.5")
        >>> ver[0], ver[1], ver[2]
        (3, 4, 5)
        r   Nr   z Version index cannot be negativec                 S   s   | d k	S r'   r   )pr   r   r#   <lambda>n      z)VersionInfo.__getitem__.<locals>.<lambda>zVersion part undefined)
r,   rk   slicer   stop
IndexErrorrZ   filterry   r   )r\   indexr   r   r   r#   __getitem__S  s&    

zVersionInfo.__getitem__c                 C   s.   d dd |   D }dt| j|f S )N, c                 s   s   | ]\}}d ||f V  qdS )z%s=%rNr   ).0keyvalr   r   r#   	<genexpr>w  s     z'VersionInfo.__repr__.<locals>.<genexpr>z%s(%s))rG   rX   rj   r0   rC   )r\   r&   r   r   r#   __repr__v  s    zVersionInfo.__repr__c                 C   s@   d| j | j| jf }| jr(|d| j 7 }| jr<|d| j 7 }|S )z	str(self)z%d.%d.%dz-%sz+%srx   )r\   r7   r   r   r#   __str__z  s    zVersionInfo.__str__c                 C   s   t |  d d S )N   )hashry   rt   r   r   r#   __hash__  s    zVersionInfo.__hash__c                 C   s   t | }|| j| j| jS )a  
        Remove any prerelease and build metadata from the version.

        :return: a new instance with the finalized version string
        :rtype: :class:`VersionInfo`

        >>> str(semver.VersionInfo.parse('1.2.3-rc.5').finalize_version())
        '1.2.3'
        )r0   rg   rh   ri   r   r   r   r#   r     s    
zVersionInfo.finalize_versionc                 C   s   |dd }|dkr"|dd }n2|rH|d dkrH|d }|dd }nt d| dd	d
dddd}|| }| |}||kS )aB  
        Compare self to match a match expression.

        :param str match_expr: operator and version; valid operators are
              <   smaller than
              >   greater than
              >=  greator or equal than
              <=  smaller or equal than
              ==  equal
              !=  not equal
        :return: True if the expression matches the version, otherwise False
        :rtype: bool

        >>> semver.VersionInfo.parse("2.0.0").match(">=1.0.0")
        True
        >>> semver.VersionInfo.parse("1.0.0").match(">1.0.0")
        False
        Nr   )>=<===!=r   )><r   z}match_expr parameter should be in format <op><ver>, where <op> is one of ['<', '>', '==', '<=', '>=', '!=']. You provided: %r)r   )r   )r   )r   r   )r   r   )r   r   )r   r   r   r   r   r   )rl   r   )r\   
match_exprprefixZmatch_versionZpossibilities_dictpossibilitiescmp_resr   r   r#   r     s*    	
zVersionInfo.matchc                 C   sf   | j t|}|dkr$td| | }t|d |d< t|d |d< t|d |d< | f |S )a  
        Parse version string to a VersionInfo instance.

        :param version: version string
        :return: a :class:`VersionInfo` instance
        :raises: :class:`ValueError`
        :rtype: :class:`VersionInfo`

        .. versionchanged:: 2.11.0
           Changed method from static to classmethod to
           allow subclasses.

        >>> semver.VersionInfo.parse('3.4.5-pre.2+build.4')
        VersionInfo(major=3, minor=4, patch=5, prerelease='pre.2', build='build.4')
        Nz%s is not valid SemVer stringrg   rh   ri   )_REGEXr   r6   rl   	groupdictrk   )r   r7   r   rp   r   r   r#   r     s    zVersionInfo.parsec                 K   sj   |   }|| ztf |W S  tk
rd   t|t|    }dt|d|f }t|Y nX dS )a   
        Replace one or more parts of a version and return a new
        :class:`VersionInfo` object, but leave self untouched

        .. versionadded:: 2.9.0
           Added :func:`VersionInfo.replace`

        :param dict parts: the parts to be updated. Valid keys are:
          ``major``, ``minor``, ``patch``, ``prerelease``, or ``build``
        :return: the new :class:`VersionInfo` object with the changed
          parts
        :raises: :class:`TypeError`, if ``parts`` contains invalid keys
        z3replace() got %d unexpected keyword argument(s): %sr   N)rX   updater   r/   setr   rG   )r\   partsr7   Zunknownkeyserrorr   r   r#   r     s    
zVersionInfo.replacec                 C   s,   z|  | W dS  tk
r&   Y dS X dS )a  
        Check if the string is a valid semver version.

        .. versionadded:: 2.9.1

        :param str version: the version string to check
        :return: True if the version string is a valid semver version, False
                 otherwise.
        :rtype: bool
        TFN)r   rl   )r   r7   r   r   r#   isvalid  s
    
zVersionInfo.isvalid)r   r   NN)r   )ro   )r   )2rC   rK   r9   __doc__	__slots__recompiler   VERBOSEr   rs   propertyrg   setterrh   ri   rn   ro   ry   rX   r   r~   r   r   staticmethodr   r   r	   r
   r   r   r   r   r`   r   r   r   r   r   r   r   r   r   r   r   r   classmethodr   r   r   r   r   r   r#   r      s   


















3
0





#	/
r   zsemver.VersionInfo.parser|   c                 C   s
   t | S )aH  
    Parse version string to a VersionInfo instance.

    .. deprecated:: 2.10.0
       Use :func:`semver.VersionInfo.parse` instead.

    .. versionadded:: 2.7.2
       Added :func:`semver.parse_version_info`

    :param version: version string
    :return: a :class:`VersionInfo` instance
    :rtype: :class:`VersionInfo`

    >>> version_info = semver.VersionInfo.parse("3.4.5-pre.2+build.4")
    >>> version_info.major
    3
    >>> version_info.minor
    4
    >>> version_info.patch
    5
    >>> version_info.prerelease
    'pre.2'
    >>> version_info.build
    'build.4'
    )r   r   rW   r   r   r#   r     s    r   c           	         s   dd   fdd}dd }| p"d|p(d } }|| || }}t ||D ]"\}}|||}|dkrJ|  S qJtt| t|S )	Nc                 S   s   t d| rt| S | S )Nz^[0-9]+$)r   r   rk   )textr   r   r#   convert,  s    z_nat_cmp.<locals>.convertc                    s    fdd|  dD S )Nc                    s   g | ]} |qS r   r   )r   cr   r   r#   
<listcomp>0  s     z/_nat_cmp.<locals>.split_key.<locals>.<listcomp>.)split)r   r   r   r#   	split_key/  s    z_nat_cmp.<locals>.split_keyc                 S   sH   t | trt |trt| |S t | tr,dS t |tr:dS t| |S d S )Nr   r   )r,   rk   r   r    r   r   r#   cmp_prerelease_tag2  s    


z$_nat_cmp.<locals>.cmp_prerelease_tag r   )zipr   r   )	r!   r"   r   r   Za_partsZb_partsZsub_aZsub_bZ
cmp_resultr   r   r#   r   +  s    


r   c                 C   s   t | }||S )a  
    Compare two versions strings.

    :param ver1: version string 1
    :param ver2: version string 2
    :return: The return value is negative if ver1 < ver2,
             zero if ver1 == ver2 and strictly positive if ver1 > ver2
    :rtype: int

    >>> semver.compare("1.0.0", "2.0.0")
    -1
    >>> semver.compare("2.0.0", "1.0.0")
    1
    >>> semver.compare("2.0.0", "2.0.0")
    0
    )r   r   r   )ver1ver2r   r   r   r#   r   F  s    
r   c                 C   s   t | }||S )a  
    Compare two versions strings through a comparison.

    :param str version: a version string
    :param str match_expr: operator and version; valid operators are
          <   smaller than
          >   greater than
          >=  greator or equal than
          <=  smaller or equal than
          ==  equal
          !=  not equal
    :return: True if the expression matches the version, otherwise False
    :rtype: bool

    >>> semver.match("2.0.0", ">=1.0.0")
    True
    >>> semver.match("1.0.0", ">1.0.0")
    False
    )r   r   r   )r7   r   verr   r   r#   r   \  s    
r   r   z2.10.2c                 C   sH   t | trt| } nt | ts&t | |}|dkr@t| S |S dS )a  
    Returns the greater version of two versions strings.

    :param ver1: version string 1
    :param ver2: version string 2
    :return: the greater version of the two
    :rtype: :class:`VersionInfo`

    >>> semver.max_ver("1.0.0", "2.0.0")
    '2.0.0'
    r   N)r,   r   r   r   r/   r   rm   r   r   r   r   r   r#   r   u  s    


r   minc                 C   s,   t | } | |}|dkr$t| S |S dS )a  
    Returns the smaller version of two versions strings.

    :param ver1: version string 1
    :param ver2: version string 2
    :return: the smaller version of the two
    :rtype: :class:`VersionInfo`

    >>> semver.min_ver("1.0.0", "2.0.0")
    '1.0.0'
    r   N)r   r   r   rm   r   r   r   r#   r     s
    

r   zstr(versionobject)c                 C   s   t t| ||||S )a\  
    Format a version string according to the Semantic Versioning specification.

    .. deprecated:: 2.10.0
       Use ``str(VersionInfo(VERSION)`` instead.

    :param int major: the required major part of a version
    :param int minor: the required minor part of a version
    :param int patch: the required patch part of a version
    :param str prerelease: the optional prerelease part of a version
    :param str build: the optional build part of a version
    :return: the formatted string
    :rtype: str

    >>> semver.format_version(3, 4, 5, 'pre.2', 'build.4')
    '3.4.5-pre.2+build.4'
    )rm   r   rx   r   r   r#   r     s    r   c                 C   s   t t|  S )a  
    Raise the major part of the version string.

    .. deprecated:: 2.10.0
       Use :func:`semver.VersionInfo.bump_major` instead.

    :param: version string
    :return: the raised version string
    :rtype: str

    >>> semver.bump_major("3.4.5")
    '4.0.0'
    )rm   r   r   r   rW   r   r   r#   r     s    r   c                 C   s   t t|  S )a  
    Raise the minor part of the version string.

    .. deprecated:: 2.10.0
       Use :func:`semver.VersionInfo.bump_minor` instead.

    :param: version string
    :return: the raised version string
    :rtype: str

    >>> semver.bump_minor("3.4.5")
    '3.5.0'
    )rm   r   r   r	   rW   r   r   r#   r	     s    r	   c                 C   s   t t|  S )a  
    Raise the patch part of the version string.

    .. deprecated:: 2.10.0
       Use :func:`semver.VersionInfo.bump_patch` instead.

    :param: version string
    :return: the raised version string
    :rtype: str

    >>> semver.bump_patch("3.4.5")
    '3.4.6'
    )rm   r   r   r
   rW   r   r   r#   r
     s    r
   r   c                 C   s   t t| |S )aU  
    Raise the prerelease part of the version string.

    .. deprecated:: 2.10.0
       Use :func:`semver.VersionInfo.bump_prerelease` instead.

    :param version: version string
    :param token: defaults to 'rc'
    :return: the raised version string
    :rtype: str

    >>> semver.bump_prerelease('3.4.5', 'dev')
    '3.4.5-dev.1'
    )rm   r   r   r   r7   r   r   r   r#   r     s    r   ro   c                 C   s   t t| |S )aW  
    Raise the build part of the version string.

    .. deprecated:: 2.10.0
       Use :func:`semver.VersionInfo.bump_build` instead.

    :param version: version string
    :param token: defaults to 'build'
    :return: the raised version string
    :rtype: str

    >>> semver.bump_build('3.4.5-rc.1+build.9')
    '3.4.5-rc.1+build.10'
    )rm   r   r   r   r   r   r   r#   r     s    r   c                 C   s   t | }t| S )a  
    Remove any prerelease and build metadata from the version string.

    .. deprecated:: 2.10.0
       Use :func:`semver.VersionInfo.finalize_version` instead.

    .. versionadded:: 2.7.9
       Added :func:`finalize_version`

    :param version: version string
    :return: the finalized version string
    :rtype: str

    >>> semver.finalize_version('1.2.3-rc.5')
    '1.2.3'
    )r   r   rm   r   )r7   Zverinfor   r   r#   r     s    
r   c                 K   s   t t| jf |S )a^  
    Replace one or more parts of a version and return the new string.

    .. deprecated:: 2.10.0
       Use :func:`semver.VersionInfo.replace` instead.

    .. versionadded:: 2.9.0
       Added :func:`replace`

    :param str version: the version string to replace
    :param dict parts: the parts to be updated. Valid keys are:
      ``major``, ``minor``, ``patch``, ``prerelease``, or ``build``
    :return: the replaced version string
    :raises: TypeError, if ``parts`` contains invalid keys
    :rtype: str

    >>> import semver
    >>> semver.replace("1.2.3", major=2, patch=10)
    '2.2.10'
    )rm   r   r   r   )r7   r   r   r   r#   r   *  s    r   c                 C   sP   dddddd}| j dkr*| jdd	g t| j}t||| j  }t| S )
z
    Subcommand: Bumps a version.

    Synopsis: bump <PART> <VERSION>
    <PART> can be major, minor, patch, prerelease, or build

    :param args: The parsed arguments
    :type args: :class:`argparse.Namespace`
    :return: the new, bumped version
    r   r	   r
   r   r   rx   Nbumpz-h)r   parser
parse_argsr   r   r7   r   rm   )rO   Zmaptabler   rT   r   r   r#   r   D  s    
r   c                 C   s"   t | jrdS td| j dS )z
    Subcommand: Checks if a string is a valid semver version.

    Synopsis: check <VERSION>

    :param args: The parsed arguments
    :type args: :class:`argparse.Namespace`
    NzInvalid version %r)r   r   r7   rl   rO   r   r   r#   r   a  s    	r   c                 C   s   t t| j| jS )z
    Subcommand: Compare two versions

    Synopsis: compare <VERSION1> <VERSION2>

    :param args: The parsed arguments
    :type args: :class:`argparse.Namespace`
    )rm   r   version1version2r   r   r   r#   r   o  s    	r   c                 C   s   t | j}t|| jS )z
    Subcommand: Determines the next version, taking prereleases into account.

    Synopsis: nextver <VERSION> <PART>

    :param args: The parsed arguments
    :type args: :class:`argparse.Namespace`
    )r   r   r7   rm   r   r   )rO   r7   r   r   r#   cmd_nextver{  s    	r   c                  C   s>  t jttd} | jdddt d |  }|jddd}|jt	d	 |jd
dd |jddd |jddd}|jt
d	 |jddd}|jddd|jddd|jddd|jddd|jdddfD ]}|jddd q|jddd}|jtd	 |jddd |jd d!d}|jtd	 |jddd |jd"d#d | S )$z
    Create an :class:`argparse.ArgumentParser` instance.

    :return: parser instance
    :rtype: :class:`argparse.ArgumentParser`
    )progdescriptionz	--versionr7   z	%(prog)s )actionr7   r   zCompare two versions)help)rT   r   zFirst versionr   zSecond versionr   zBumps a versionzBump commands)titledestrg   z"Bump the major part of the versionrh   z"Bump the minor part of the versionri   z"Bump the patch part of the versionrn   z'Bump the prerelease part of the versionro   z"Bump the build part of the versionzVersion to raisecheckz,Checks if a string is a valid semver versionzVersion to checkZnextverz=Determines the next version, taking prereleases into account.r   z1One of 'major', 'minor', 'patch', or 'prerelease')argparseArgumentParser__package__r   add_argument__version__add_subparsers
add_parserset_defaultsr   r   r   r   )r   r&   Zparser_compareZparser_bumpZsbr   Zparser_checkZparser_nextverr   r   r#   r     sL         r   c                 C   s$   t | ds| j  t | | S )a  
    Process the input from the CLI.

    :param args: The parsed arguments
    :type args: :class:`argparse.Namespace`
    :param parser: the parser instance
    :type parser: :class:`argparse.ArgumentParser`
    :return: result of the selected action
    :rtype: str
    rT   )rB   r   
print_help
SystemExitrT   r   r   r   r#   r     s    

r   c              
   C   sx   z6t  }|j| d}||_t|}|dk	r2t| W dS  ttfk
rr } ztd|tjd W Y dS d}~X Y nX dS )z
    Entry point for the application script.

    :param list cliargs: Arguments to parse or None (=use :class:`sys.argv`)
    :return: error code
    :rtype: int
    r   Nr   ERROR)filer   )	r   r   r   r   printrl   r/   sysstderr)Zcliargsr   rO   resulterrr   r   r#   r     s    r   __main__)r*   r+   )NN)r   )ro   )N)@r   
__future__r   r   rz   	functoolsr   r   rD   r   r   rH   version_infor1   r2   r   
__author____author_email__Z__maintainer__Z__maintainer_email____all__r   rB   __builtins__r   rm   bytesr   r-   r.   r"   r(   r)   r6   DeprecationWarningr   r   r`   objectr   r   r   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   rC   doctesttestmodr   r   r   r#   <module>   s   !


2
    A













6

