U
    dZ                     @  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   )
MapAdapter)Rule)Request)Responsec                   @  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   ?/tmp/pip-unpacked-wheel-m99gisyz/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 | 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   5   s    
zRequestPath.__init__)r   r   r   r   	__slots__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  ZS )RequestAliasRedirectzAThis rule is an alias and wants to redirect to the canonical URL.t.Mapping[str, t.Any]r   r   )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.   r/   r0   )r   r,   r.   r/   r0   r   r   r   r   H   s
    zBuildError.__init__zRule | None)r   c                 C  s   |  | jS r   )closest_ruler0   r   r   r   r   	suggestedU   s    zBuildError.suggested)r0   r   c                   s4   ddd fdd}|r0|j jr0t|j j|dS d S )Nr   float)ruler   c                   sT   t dtd | j j  dtt jp(d| j	 dt| j
oJ j| j
k gS )Ng\(\?g{Gz?r   )sumdifflibZSequenceMatcherr,   Zratioboolsetr.   issubset	argumentsmethodsr/   )r5   r2   r   r   _score_ruleZ   s      z,BuildError.closest_rule.<locals>._score_rule)key)mapZ_rulesmax)r   r0   r=   r   r2   r   r1   Y   s    zBuildError.closest_rulec                 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 k	r| j| jjk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,   r/   appendr.   sortedr3   r<   r;   unionr9   defaultskeysjoin)r   messageZmissing_valuesr   r   r   __str__k   s8    

zBuildError.__str__)N)
r   r   r   r   r   r   r3   r1   rL   r%   r   r   r   r   r-   C   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   rM      s   rM   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]r8   r   )rP   rQ   r   c                 C  s   || _ || _d S r   rO   )r   rP   rQ   r   r   r   r      s    zNoMatch.__init__N)r   r   r   r(   r   r   r   r   r   rN      s   rN   )
__future__r   r7   typingt
exceptionsr   r   utilsr   r   TYPE_CHECKINGZ_typeshed.wsgir   r?   r
   rulesr   Zwrappers.requestr   Zwrappers.responser   	Exceptionr   r   r&   r)   LookupErrorr-   rM   rN   r   r   r   r   <module>   s&   
	F