B
    d                 @   s   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 )    N   )
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   M/var/www/html/venv/lib/python3.7/site-packages/werkzeug/routing/exceptions.pyr      s   r   c                   sR   e Zd ZdZdZedd fddZdejej	d  eje
 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  N)new_urlreturnc                s   t  | || _d S )N)super__init__r   )selfr   )	__class__r   r   r   "   s    zRequestRedirect.__init__)r   r   r   )environscoper   c             C   s   t | j| jS )N)r   r   code)r   r   r   r   r   r   get_response&   s    zRequestRedirect.get_response)NN)r   r   r   r   r   strr   tOptionalUniondictr   __classcell__r   r   )r   r   r      s    r   c                   s,   e Zd ZdZdZedd fddZ  ZS )RequestPathzInternal exception.)	path_infoN)r&   r   c                s   t    || _d S )N)r   r   r&   )r   r&   )r   r   r   r   3   s    
zRequestPath.__init__)r   r   r   r   	__slots__r   r   r$   r   r   )r   r   r%   .   s   r%   c                   s6   e Zd ZdZejeejf edd fddZ  Z	S )RequestAliasRedirectzAThis rule is an alias and wants to redirect to the canonical URL.N)matched_valuesendpointr   c                s   t    || _|| _d S )N)r   r   r)   r*   )r   r)   r*   )r   r   r   r   ;   s    
zRequestAliasRedirect.__init__)
r   r   r   r   r    Mappingr   Anyr   r$   r   r   )r   r   r(   8   s   r(   c                   s   e Zd ZdZdeejeejf eje ejd dd fddZ	e
ejd dd	d
Zejd ejd dddZe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*   valuesmethodadapterr   c                s,   t  ||| || _|| _|| _|| _d S )N)r   r   r*   r.   r/   r0   )r   r*   r.   r/   r0   )r   r   r   r   F   s
    zBuildError.__init__r
   )r   c             C   s   |  | jS )N)closest_ruler0   )r   r   r   r   	suggestedS   s    zBuildError.suggested)r0   r   c                s4   dt d fdd}|r0|jjr0t|jj|dS d S )Nr
   )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*   ratioboolsetr.   issubset	argumentsmethodsr/   )r3   )r   r   r   _score_ruleX   s    z,BuildError.closest_rule.<locals>._score_rule)key)floatmapZ_rulesmax)r   r0   r<   r   )r   r   r1   W   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.   sortedr2   r;   r:   unionr8   defaultskeysjoin)r   messageZmissing_valuesr   r   r   __str__i   s*    
zBuildError.__str__)N)r   r   r   r   r   r    r+   r,   r!   r   r   r2   r1   rL   r$   r   r   )r   r   r-   A   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.
    N)r   r   r   r   r   r   r   r   rM      s   rM   c               @   s(   e Zd ZdZeje eddddZdS )NoMatch)have_match_forwebsocket_mismatchN)rO   rP   r   c             C   s   || _ || _d S )N)rO   rP   )r   rO   rP   r   r   r   r      s    zNoMatch.__init__)	r   r   r   r'   r    Setr   r7   r   r   r   r   r   rN      s   rN   )r5   typingr    
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