U
    /v¶h�  ã                   @  sò   U d dl mZ d dlZd dlZd dlZd dlmZ ejrDddl	m
Z
 G dd„ deƒZG dd	„ d	ƒZG d
d„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZeeeeeeedœZded< dS )é    )ÚannotationsN)Úquoteé   )ÚMapc                   @  s   e Zd ZdZdS )ÚValidationErrorzˆValidation error.  If a rule converter raises this exception the rule
    does not match the current URL and the next URL is tried.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   ú?/tmp/pip-unpacked-wheel-c3xdgso7/werkzeug/routing/converters.pyr      s   r   c                      sh   e Zd ZdZdZdZdZdddœ‡ fdd	„Zd
ddddœdd„Zdddœdd„Z	dddœdd„Z
‡  ZS )ÚBaseConverterz�Base class for all converters.

    .. versionchanged:: 2.3
        ``part_isolating`` defaults to ``False`` if ``regex`` contains a ``/``.
    z[^/]+éd   Tút.AnyÚNone)ÚkwargsÚreturnc                   s2   t ƒ jf |Ž d| jkr.d| jkr.d| jk| _d S )NÚregexÚpart_isolatingú/)ÚsuperÚ__init_subclass__Ú__dict__r   r   )Úclsr   ©Ú	__class__r   r   r      s    zBaseConverter.__init_subclass__r   )ÚmapÚargsr   r   c                 O  s
   || _ d S ©N)r   )Úselfr   r   r   r   r   r   Ú__init__%   s    zBaseConverter.__init__Ústr©Úvaluer   c                 C  s   |S r   r   ©r   r#   r   r   r   Ú	to_python(   s    zBaseConverter.to_pythonc                 C  s   t t|ƒdd�S )Nz!$&'()*+,/:;=@)Úsafe)r   r!   r$   r   r   r   Úto_url+   s    zBaseConverter.to_url)r   r   r	   r
   r   Úweightr   r   r    r%   r'   Ú__classcell__r   r   r   r   r      s   r   c                      s0   e Zd ZdZdddddddœ‡ fd	d
„Z‡  ZS )ÚUnicodeConvertera  This converter is the default converter and accepts any string but
    only one path segment.  Thus the string can not include a slash.

    This is the default validator.

    Example::

        Rule('/pages/<page>'),
        Rule('/<string(length=2):lang_code>')

    :param map: the :class:`Map`.
    :param minlength: the minimum length of the string.  Must be greater
                      or equal 1.
    :param maxlength: the maximum length of the string.
    :param length: the exact length of the string.
    r   Nr   Úintú
int | Noner   )r   Ú	minlengthÚ	maxlengthÚlengthr   c                   sf   t ƒ  |¡ |d k	r&dt|ƒ› d�}n0|d kr4d}ntt|ƒƒ}dt|ƒ› d|› d�}d|› �| _d S )NÚ{Ú}Ú ú,z[^/])r   r    r+   r!   r   )r   r   r-   r.   r/   Zlength_regexZmaxlength_valuer   r   r   r    B   s    zUnicodeConverter.__init__)r   NN)r   r   r	   r
   r    r)   r   r   r   r   r*   0   s
      ûr*   c                      s:   e Zd ZdZddddœ‡ fdd„Zddd	œd
d„Z‡  ZS )ÚAnyConvertera€  Matches one of the items provided.  Items can either be Python
    identifiers or strings::

        Rule('/<any(about, help, imprint, class, "foo,bar"):page_name>')

    :param map: the :class:`Map`.
    :param items: this function accepts the possible items as positional
                  arguments.

    .. versionchanged:: 2.2
        Value is validated when building a URL.
    r   r!   r   )r   Úitemsr   c                   s8   t ƒ  |¡ t|ƒ| _dd dd„ |D ƒ¡› d�| _d S )Nz(?:ú|c                 S  s   g | ]}t  |¡‘qS r   )ÚreÚescape)Ú.0Úxr   r   r   Ú
<listcomp>f   s     z)AnyConverter.__init__.<locals>.<listcomp>ú))r   r    Úsetr5   Újoinr   )r   r   r5   r   r   r   r    c   s    
zAnyConverter.__init__r   r"   c                 C  sD   || j krt|ƒS d dd„ t| j ƒD ƒ¡}td|› d|› �ƒ‚d S )Nz, c                 s  s   | ]}d |› d �V  qdS )ú'Nr   )r9   Úitemr   r   r   Ú	<genexpr>l   s     z&AnyConverter.to_url.<locals>.<genexpr>r?   z' is not one of )r5   r!   r>   ÚsortedÚ
ValueError)r   r#   Zvalid_valuesr   r   r   r'   h   s    
zAnyConverter.to_url)r   r   r	   r
   r    r'   r)   r   r   r   r   r4   U   s   r4   c                   @  s   e Zd ZdZdZdZdZdS )ÚPathConverterzñLike the default :class:`UnicodeConverter`, but it also matches
    slashes.  This is useful for wikis and similar applications::

        Rule('/<path:wikipage>')
        Rule('/<path:wikipage>/edit')

    :param map: the :class:`Map`.
    Fz[^/].*?éÈ   N)r   r   r	   r
   r   r   r(   r   r   r   r   rD   p   s   	rD   c                      sv   e Zd ZU dZdZeZded< ddd	d
d
dddœ‡ fdd„Zdddœdd„Z	dddœdd„Z
eddœdd„ƒZ‡  ZS )ÚNumberConverterzKBaseclass for `IntegerConverter` and `FloatConverter`.

    :internal:
    é2   zt.Callable[[t.Any], t.Any]Únum_convertr   NFr   r+   r,   Úboolr   )r   Úfixed_digitsÚminÚmaxÚsignedr   c                   s4   |r| j | _tƒ  |¡ || _|| _|| _|| _d S r   )Úsigned_regexr   r   r    rJ   rK   rL   rM   )r   r   rJ   rK   rL   rM   r   r   r   r    ˆ   s    zNumberConverter.__init__r!   r   r"   c                 C  sV   | j rt|ƒ| j krtƒ ‚|  |¡}| jd k	r8|| jk sL| jd k	rR|| jkrRtƒ ‚|S r   )rJ   Úlenr   rH   rK   rL   )r   r#   Z	value_numr   r   r   r%   ˜   s    
ÿÿzNumberConverter.to_pythonc                 C  s$   t |  |¡ƒ}| jr | | j¡}|S r   )r!   rH   rJ   Úzfill)r   r#   Z	value_strr   r   r   r'   ¢   s    zNumberConverter.to_url)r   c                 C  s   d| j › �S )Nz-?)r   )r   r   r   r   rN   ¨   s    zNumberConverter.signed_regex)r   NNF)r   r   r	   r
   r(   r+   rH   Ú__annotations__r    r%   r'   ÚpropertyrN   r)   r   r   r   r   rF      s   
    ú
rF   c                   @  s   e Zd ZdZdZdS )ÚIntegerConvertera­  This converter only accepts integer values::

        Rule("/page/<int:page>")

    By default it only accepts unsigned, positive values. The ``signed``
    parameter will enable signed, negative values. ::

        Rule("/page/<int(signed=True):page>")

    :param map: The :class:`Map`.
    :param fixed_digits: The number of fixed digits in the URL. If you
        set this to ``4`` for example, the rule will only match if the
        URL looks like ``/0001/``. The default is variable length.
    :param min: The minimal value.
    :param max: The maximal value.
    :param signed: Allow signed (negative) values.

    .. versionadded:: 0.15
        The ``signed`` parameter.
    z\d+N)r   r   r	   r
   r   r   r   r   r   rS   ­   s   rS   c                      s8   e Zd ZdZdZeZddddddd	œ‡ fd
d„Z‡  ZS )ÚFloatConverteraù  This converter only accepts floating point values::

        Rule("/probability/<float:probability>")

    By default it only accepts unsigned, positive values. The ``signed``
    parameter will enable signed, negative values. ::

        Rule("/offset/<float(signed=True):offset>")

    :param map: The :class:`Map`.
    :param min: The minimal value.
    :param max: The maximal value.
    :param signed: Allow signed (negative) values.

    .. versionadded:: 0.15
        The ``signed`` parameter.
    z\d+\.\d+NFr   zfloat | NonerI   r   )r   rK   rL   rM   r   c                   s   t ƒ j||||d� d S )N)rK   rL   rM   )r   r    )r   r   rK   rL   rM   r   r   r   r    Ü   s    zFloatConverter.__init__)NNF)	r   r   r	   r
   r   ÚfloatrH   r    r)   r   r   r   r   rT   Æ   s      ûrT   c                   @  s4   e Zd ZdZdZdddœdd„Zdddœdd	„Zd
S )ÚUUIDConverterz™This converter only accepts UUID strings::

        Rule('/object/<uuid:identifier>')

    .. versionadded:: 0.10

    :param map: the :class:`Map`.
    zK[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}r!   z	uuid.UUIDr"   c                 C  s
   t  |¡S r   )ÚuuidÚUUIDr$   r   r   r   r%   õ   s    zUUIDConverter.to_pythonc                 C  s   t |ƒS r   )r!   r$   r   r   r   r'   ø   s    zUUIDConverter.to_urlN)r   r   r	   r
   r   r%   r'   r   r   r   r   rV   æ   s
   
ÿrV   )ÚdefaultÚstringÚanyÚpathr+   rU   rW   z#t.Mapping[str, type[BaseConverter]]ÚDEFAULT_CONVERTERS)Ú
__future__r   r7   ÚtypingÚtrW   Úurllib.parser   ÚTYPE_CHECKINGr   r   rC   r   r   r*   r4   rD   rF   rS   rT   rV   r]   rQ   r   r   r   r   Ú<module>   s0    %. ù