a
    xˆ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ƒsždd„ ZerÄe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   úI/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/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\\\\Ú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    r7   c                    s6   ˆdu 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	� ~ˆ| i |¤Ž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)r9   ÚfilenameÚlineno)ÚappendÚhasattrr:   Ú__name__ÚinspectÚcurrentframeÚf_backÚjoinÚwarningsÚwarn_explicitÚformatÚ
__module__ÚgetfileÚf_codeÚf_lineno)ÚargsÚkwargsÚmsgr=   r>   Úframe©r9   Úfuncr   r8   r   r#   Úwrapper‚   s&    





ü	zdeprecated.<locals>.wrapper)r   r   r   )rU   r   r8   r9   rV   r   rT   r#   r   r   s
    r   ú2.10.0©r8   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_dictrX   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-   r0   r1   )ÚselfÚotherZcomparable_types©Úoperatorr   r#   rV   Ä   s    
ÿzcomparator.<locals>.wrapper)r   )r`   rV   r   r_   r#   Ú
comparatorÁ   s    ra   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 u rnd nt|ƒ| _|d u r„d nt|ƒ| _	d S )N©ÚmajorÚminorÚpatchr   z1{!r} is negative. A version can only be positive.rh   ri   rj   )
ÚitemsÚintÚ
ValueErrorrK   rb   rc   rd   Ústrre   rf   )	r]   rh   ri   rj   Ú
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).)rb   ©r]   r   r   r#   rh     s    zVersionInfo.majorc                 C   s   t dƒ‚d S )Nzattribute 'major' is readonly©ÚAttributeError©r]   rs   r   r   r#   rh     s    c                 C   s   | j S )z(The minor part of a version (read-only).)rc   ru   r   r   r#   ri     s    zVersionInfo.minorc                 C   s   t dƒ‚d S )Nzattribute 'minor' is readonlyrv   rx   r   r   r#   ri     s    c                 C   s   | j S )z(The patch part of a version (read-only).)rd   ru   r   r   r#   rj     s    zVersionInfo.patchc                 C   s   t dƒ‚d S )Nzattribute 'patch' is readonlyrv   rx   r   r   r#   rj   "  s    c                 C   s   | j S )z-The prerelease part of a version (read-only).)re   ru   r   r   r#   ro   &  s    zVersionInfo.prereleasec                 C   s   t dƒ‚d S )Nz"attribute 'prerelease' is readonlyrv   rx   r   r   r#   ro   +  s    c                 C   s   | j S )z(The build part of a version (read-only).)rf   ru   r   r   r#   rp   /  s    zVersionInfo.buildc                 C   s   t dƒ‚d S )Nzattribute 'build' is readonlyrv   rx   r   r   r#   rp   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)
        ©rh   ri   rj   ro   rp   ru   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)])
        rh   ri   rj   ro   rp   )ÚcollectionsÚOrderedDictrh   ri   rj   ro   rp   ru   r   r   r#   rY   H  s    ûÿzVersionInfo.to_dictzsemver.VersionInfo.to_tuplerW   ©r   r8   c                 C   s   |   ¡ S r'   ©rz   ru   r   r   r#   Ú_astuplec  s    zVersionInfo._astuplezsemver.VersionInfo.to_dictc                 C   s   |   ¡ S r'   )rY   ru   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Úsearchrn   rl   Ú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‚   )r1   rb   ©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‚   )r1   rb   rc   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‚   )r1   rb   rc   rd   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)r1   rŒ   re   rb   rc   rd   )r]   ÚtokenrŽ   ro   r   r   r#   r   ´  s    zVersionInfo.bump_prereleaserp   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')
        rp   r�   )r1   rŒ   rf   rb   rc   rd   re   )r]   r‘   rŽ   rp   r   r   r#   r   Æ  s    zVersionInfo.bump_buildc           	      C   sÖ   t | ƒ}t|tƒr| |¡}nRt|tƒr8|f i |¤Ž}n8t|ttfƒrP||Ž }n t||ƒsptd |j	t |ƒ¡ƒ‚|  
¡ dd… }| 
¡ dd… }t||ƒ}|r¢|S | j|j }}t||ƒ}|sÂdS |sÊdS |sÒd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‚   éÿÿÿÿ)r1   r-   Ústring_typesr   rZ   r[   r\   r0   rK   rD   rz   r   ro   Ú_nat_cmp)	r]   r^   rŽ   Úv1Zv2ÚxZrc1Zrc2Zrccmpr   r   r#   r   Ø  s6    




ÿÿ

zVersionInfo.comparec                 C   s®   h d£}||vr"t dj||d�ƒ‚| }|js2|jr~|dksp|dkrL|jdksp|dkr~|j|j  krldkr~n n|jddd	�S |d
v r–t|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`
        >   rh   rj   ro   ri   z<Invalid part. Expected one of {validparts}, but got {part!r})Ú
validpartsÚpartrj   ri   r   rh   N)ro   rp   rg   Zbump_)
rm   rK   ro   rp   rj   ri   r   Úgetattrr
   r   )r]   r˜   Zprerelease_tokenr—   r8   r   r   r#   Únext_version  s6    ÿÿÿþþýýý
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ur6|jdk sJ|jdurR|jdk rRtdƒ‚ttdd„ |  ¡ | ƒƒ}t	|ƒdkr‚|d }n|sŽt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 uS r'   r   )Úpr   r   r#   Ú<lambda>n  ó    z)VersionInfo.__getitem__.<locals>.<lambda>zVersion part undefined)
r-   rl   ÚslicerŠ   ÚstopÚ
IndexErrorr[   Úfilterrz   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  r¦   z'VersionInfo.__repr__.<locals>.<genexpr>z%s(%s))rH   rY   rk   r1   rD   )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+%sry   )r]   r8   r   r   r#   Ú__str__z  s    zVersionInfo.__str__c                 C   s   t |  ¡ d d… ƒS )Né   )Úhashrz   ru   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'
        )r1   rh   ri   rj   r�   r   r   r#   r   †  s    
zVersionInfo.finalize_versionc                 C   s€   |dd… }|dv r"|dd… }n2|rH|d dv rH|d }|dd… }nt d| ƒ‚dd	d
ddddœ}|| }|  |¡}||v 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¸   )rm   r   )r]   Ú
match_exprÚprefixZmatch_versionZpossibilities_dictÚpossibilitiesÚcmp_resr   r   r#   r   “  s*    ýÿú	
zVersionInfo.matchc                 C   sj   | j  t|ƒ¡}|du r$td| ƒ‚| ¡ }t|d ƒ|d< t|d ƒ|d< t|d ƒ|d< | f i |¤Ž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 stringrh   ri   rj   )Ú_REGEXr   r7   rm   Ú	groupdictrl   )rŽ   r8   r   rq   r   r   r#   r   Â  s    zVersionInfo.parsec                 K   sl   |   ¡ }| |¡ ztf i |¤ŽW S  tyf   t|ƒt|   ¡ ƒ }dt|ƒd |¡f }t|ƒ‚Y n0 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)rY   Úupdater   r0   Úsetrˆ   rH   )r]   Úpartsr8   ZunknownkeysÚerrorr   r   r#   r   à  s    
þzVersionInfo.replacec                 C   s*   z|   |¡ W dS  ty$   Y dS 0 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   rm   )rŽ   r8   r   r   r#   Úisvalidú  s
    
zVersionInfo.isvalid)r   r   NN)r�   )rp   )r�   )2rD   rL   r:   Ú__doc__Ú	__slots__ÚreÚcompilerƒ   ÚVERBOSErÁ   rt   Úpropertyrh   Úsetterri   rj   ro   rp   rz   rY   r   r   r€   r�   ÚstaticmethodrŒ   r   r	   r
   r   r   r   rš   ra   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   rX   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   rl   )Ú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  r¦   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-   rl   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   )r8   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   r0   r   rn   ©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   rn   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'
    )rn   r   ry   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'
    )rn   r   r   r   rX   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'
    )rn   r   r   r	   rX   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'
    )rn   r   r   r
   rX   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'
    )rn   r   r   r   ©r8   r‘   r   r   r#   r   î  s    r   rp   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'
    )rn   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   rn   r   )r8   Zverinfor   r   r#   r     s    
r   c                 K   s   t t | ¡jf i |¤Žƒ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'
    )rn   r   r   r   )r8   rÅ   r   r   r#   r   *  s    r   c                 C   sP   ddddddœ}| j du 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   ry   NÚbumpz-h)râ   ÚparserÚ
parse_argsr   r   r8   r™   rn   )rP   ZmaptablerÞ   rU   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Ç   r8   rm   ©rP   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`
    )rn   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   r8   rn   rš   r˜   )rP   r8   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	--versionr8   z	%(prog)s )Úactionr8   r   zCompare two versions)Úhelp)rU   ræ   zFirst versionrç   zSecond versionrâ   zBumps a versionzBump commands)ÚtitleÚdestrh   z"Bump the major part of the versionri   z"Bump the minor part of the versionrj   z"Bump the patch part of the versionro   z'Bump the prerelease part of the versionrp   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   ˆ  sB    
ÿûÿÿÿ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
    rU   )rC   rã   Ú
print_helpÚ
SystemExitrU   rå   r   r   r#   r   ¾  s    

r   c              
   C   sv   z6t ƒ }|j| d�}||_t|ƒ}|dur2t|ƒ W dS  ttfyp } ztd|tjd� W Y d}~dS d}~0 0 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   Úprintrm   r0   ÚsysÚstderr)Zcliargsrã   rP   ÚresultÚerrr   r   r#   r   Ñ  s    r   Ú__main__)r+   r,   )NN)r�   )rp   )N)@rÈ   Ú
__future__r   rð   r{   Ú	functoolsr   r   rE   rÊ   rý   rI   Úversion_infor2   r3   rô   Ú
__author__Ú__author_email__Z__maintainer__Z__maintainer_email__Ú__all__r   rC   Ú__builtins__r   rn   Úbytesr“   r.   r/   r"   r(   r*   r7   ÚDeprecationWarningr   r   ra   Úobjectr   r   r”   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   rè   r   r   r   rD   ÚdoctestÚtestmodr   r   r   r#   Ú<module>   sš   !


2
    A













6

