o
    '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r"d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 )ValidationErrorzValidation 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   W/var/www/html/olx_land/venv/lib/python3.10/site-packages/werkzeug/routing/converters.pyr      s    r   c                      sL   e Zd ZdZdZdZdZd fd	d
ZdddZdddZ	dddZ
  ZS )BaseConverterzBase class for all converters.

    .. versionchanged:: 2.3
        ``part_isolating`` defaults to ``False`` if ``regex`` contains a ``/``.
    z[^/]+d   Tkwargst.AnyreturnNonec                   s>   t  jdi | d| jv rd| jvrd| jv| _d S d S d S )Nregexpart_isolating/r   )super__init_subclass____dict__r   r   )clsr   	__class__r   r   r      s   zBaseConverter.__init_subclass__mapr   argsc                 O  s
   || _ d S N)r   )selfr   r   r   r   r   r   __init__%      
zBaseConverter.__init__valuestrc                 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   r   r   r   r   r   r   r   r"   r#   r   r   r"   r   r   r#   )r   r   r	   r
   r   weightr   r   r    r%   r'   __classcell__r   r   r   r   r      s    

r   c                      s*   e Zd ZdZ			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   r   	minlengthint	maxlength
int | Nonelengthr   r   c                   sf   t  | |d urdt| d}n|d u rd}ntt|}dt| d| d}d| | _d S )N{} ,z[^/])r   r    r.   r#   r   )r   r   r-   r/   r1   length_regexmaxlength_valuer   r   r   r    B   s   zUnicodeConverter.__init__)r   NN)
r   r   r-   r.   r/   r0   r1   r0   r   r   )r   r   r	   r
   r    r+   r   r   r   r   r,   0   s    r,   c                      s,   e Zd ZdZd fdd	Z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   itemsr#   r   r   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    setr9   joinr   )r   r   r9   r   r   r   r    c   s   
"zAnyConverter.__init__r"   r   c                 C  s@   || j v r	t|S ddd t| j D }td| d| )Nz, c                 s  s    | ]	}d | d V  qdS )'Nr   )r=   itemr   r   r   	<genexpr>l   s    z&AnyConverter.to_url.<locals>.<genexpr>rC   z' is not one of )r9   r#   rB   sorted
ValueError)r   r"   valid_valuesr   r   r   r'   h   s   
zAnyConverter.to_url)r   r   r9   r#   r   r   r)   )r   r   r	   r
   r    r'   r+   r   r   r   r   r8   U   s    r8   c                   @  s   e Zd ZdZdZdZdZdS )PathConverterzLike 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   rI   p   s
    	rI   c                      s`   e Zd ZU dZdZeZded< 				dd fddZd ddZ	d!ddZ
ed"ddZ  ZS )#NumberConverterzKBaseclass for `IntegerConverter` and `FloatConverter`.

    :internal:
    2   zt.Callable[[t.Any], t.Any]num_convertr   NFr   r   fixed_digitsr.   minr0   maxsignedboolr   r   c                   s4   |r| j | _t | || _|| _|| _|| _d S r   )signed_regexr   r   r    rN   rO   rP   rQ   )r   r   rN   rO   rP   rQ   r   r   r   r       s   
zNumberConverter.__init__r"   r#   r   c                 C  sV   | j rt|| j krt | |}| jd ur|| jk s&| jd ur)|| jkr)t |S r   )rN   lenr   rM   rO   rP   )r   r"   	value_numr   r   r   r%      s   
zNumberConverter.to_pythonc                 C  s$   t | |}| jr|| j}|S r   )r#   rM   rN   zfill)r   r"   	value_strr   r   r   r'      s   zNumberConverter.to_urlc                 C  s   d| j  S )Nz-?)r   )r   r   r   r   rS      s   zNumberConverter.signed_regex)r   NNF)r   r   rN   r.   rO   r0   rP   r0   rQ   rR   r   r   r(   r)   )r   r#   )r   r   r	   r
   r*   r.   rM   __annotations__r    r%   r'   propertyrS   r+   r   r   r   r   rK      s   
 


rK   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   rZ      s    rZ   c                      s2   e Zd ZdZdZeZ			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   r   rO   float | NonerP   rQ   rR   r   r   c                   s   t  j||||d d S )N)rO   rP   rQ   )r   r    )r   r   rO   rP   rQ   r   r   r   r       s   zFloatConverter.__init__)NNF)
r   r   rO   r\   rP   r\   rQ   rR   r   r   )	r   r   r	   r
   r   floatrM   r    r+   r   r   r   r   r[      s    r[   c                   @  s(   e Zd ZdZdZdddZdd	d
ZdS )UUIDConverterzThis 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"   r#   r   	uuid.UUIDc                 C  s
   t |S r   )uuidUUIDr$   r   r   r   r%      r!   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	   r
   r   r%   r'   r   r   r   r   r^      s    

r^   )defaultstringanypathr.   r]   r`   z#t.Mapping[str, type[BaseConverter]]DEFAULT_CONVERTERS)
__future__r   r;   typingtr`   urllib.parser   TYPE_CHECKINGr   r   rG   r   r   r,   r8   rI   rK   rZ   r[   r^   rf   rX   r   r   r   r   <module>   s0    %. 