a
    Nf                     @  s  d dl mZ d dlZd dlZddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ejrd dlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ G dd deZG dd deeZG dd deZG dd deZG dd deeZG dd deZG dd deZdS )    )annotationsN   )
BadRequest)HTTPException)cached_property)redirect)WSGIEnvironment)Request)Response   )
MapAdapter)Rulec                   @  s   e Zd ZdZdS )RoutingExceptionzxSpecial exceptions that require the application to redirect, notifying
    about missing urls, etc.

    :internal:
    N__name__
__module____qualname____doc__ r   r   T/var/www/ai-form-bot/venv/lib/python3.9/site-packages/werkzeug/routing/exceptions.pyr      s   r   c                      s@   e Zd ZdZdZddd fddZdd	d
ddddZ  ZS )RequestRedirectzRaise if the map requests a redirect. This is for example the case if
    `strict_slashes` are activated and an url that requires a trailing slash.

    The attribute `new_url` contains the absolute destination url.
    i4  strNone)new_urlreturnc                   s   t  | || _d S N)super__init__r   )selfr   	__class__r   r   r   %   s    zRequestRedirect.__init__Nz WSGIEnvironment | Request | Nonezdict[str, t.Any] | Noner
   )environscoper   c                 C  s   t | j| jS r   )r   r   code)r   r!   r"   r   r   r   get_response)   s    zRequestRedirect.get_response)NN)r   r   r   r   r#   r   r$   __classcell__r   r   r   r   r      s     r   c                      s,   e Zd ZdZdZddd fddZ  ZS )RequestPathzInternal exception.)	path_infor   r   )r'   r   c                   s   t    || _d S r   )r   r   r'   )r   r'   r   r   r   r   6   s    
zRequestPath.__init__)r   r   r   r   	__slots__r   r%   r   r   r   r   r&   1   s   r&   c                      s*   e Zd ZdZdddd fddZ  ZS )RequestAliasRedirectzAThis rule is an alias and wants to redirect to the canonical URL.t.Mapping[str, t.Any]t.Anyr   )matched_valuesendpointr   c                   s   t    || _|| _d S r   )r   r   r,   r-   )r   r,   r-   r   r   r   r   >   s    
zRequestAliasRedirect.__init__)r   r   r   r   r   r%   r   r   r   r   r)   ;   s   r)   c                      s`   e Zd ZdZddddddd fd	d
ZeddddZdddddZddddZ  Z	S )
BuildErrorz_Raised if the build system cannot find a URL for an endpoint with the
    values provided.
    Nr+   r*   z
str | NonezMapAdapter | Noner   )r-   valuesmethodadapterr   c                   s,   t  ||| || _|| _|| _|| _d S r   )r   r   r-   r/   r0   r1   )r   r-   r/   r0   r1   r   r   r   r   I   s
    zBuildError.__init__zRule | None)r   c                 C  s   |  | jS r   )closest_ruler1   r   r   r   r   	suggestedV   s    zBuildError.suggested)r1   r   c                   s4   ddd fdd}|r0|j jr0t|j j|dS d S )Nr   float)ruler   c                   s\   t dtd t| jt j  dtt jp0d	| j
 dt| joR j| jv  gS )Ng\(\?g{Gz?r   )sumdifflibZSequenceMatcherr   r-   ratioboolsetr/   issubset	argumentsmethodsr0   )r6   r3   r   r   _score_rule[   s    z,BuildError.closest_rule.<locals>._score_rule)key)mapZ_rulesmax)r   r1   r?   r   r3   r   r2   Z   s    zBuildError.closest_ruler   c                 C  s   d| j g}| jr(|d| jd | jrD|dt| j |d | jr| j | jj kr| jr| jjd ur| j| jjvr|dt| jjd | jjt	| jj
pdt	| j  }|r|d	t|d n|d
| jj d d|S )Nz!Could not build url for endpoint z ()z with values .z Did you mean to use methods ?r   z" Did you forget to specify values z Did you mean z	 instead? )r-   r0   appendr/   sortedr4   r>   r=   unionr;   defaultskeysjoin)r   messageZmissing_valuesr   r   r   __str__o   s<    


zBuildError.__str__)N)
r   r   r   r   r   r   r4   r2   rN   r%   r   r   r   r   r.   D   s   	 r.   c                   @  s   e Zd ZdZdS )WebsocketMismatchzThe only matched rule is either a WebSocket and the request is
    HTTP, or the rule is HTTP and the request is a WebSocket.
    Nr   r   r   r   r   rO      s   rO   c                   @  s"   e Zd ZdZddddddZdS )	NoMatchhave_match_forwebsocket_mismatchzset[str]r:   r   )rR   rS   r   c                 C  s   || _ || _d S r   rQ   )r   rR   rS   r   r   r   r      s    zNoMatch.__init__N)r   r   r   r(   r   r   r   r   r   rP      s   rP   )
__future__r   r8   typingt
exceptionsr   r   utilsr   r   TYPE_CHECKINGZ_typeshed.wsgir   Zwrappers.requestr	   Zwrappers.responser
   rA   r   rulesr   	Exceptionr   r   r&   r)   LookupErrorr.   rO   rP   r   r   r   r   <module>   s&   
	I