B
    }hb                 @   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   :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OptionalZ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.   r/   )r   r)   r-   r.   r/   )r   r   r   r   F   s
    zBuildError.__init__r
   )r   c             C   s   |  | jS )N)closest_ruler/   )r   r   r   r   	suggestedS   s    zBuildError.suggested)r/   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)   Zratioboolsetr-   issubset	argumentsmethodsr.   )r2   )r   r   r   _score_ruleX   s    z,BuildError.closest_rule.<locals>._score_rule)key)floatmapZ_rulesmax)r   r/   r:   r   )r   r   r0   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-   sortedr1   r9   r8   unionr6   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   r1   r0   rJ   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   rK      s   rK   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)rM   rN   r   c             C   s   || _ || _d S )N)rM   rN   )r   rM   rN   r   r   r   r      s    zNoMatch.__init__)	r   r   r   r&   r    Setr   r5   r   r   r   r   r   rL      s   rL   )r4   typingr    
exceptionsr   r   Zutilsr   r   ZTYPE_CHECKINGZ_typeshed.wsgir   r=   r	   Zrulesr
   Zwrappers.requestr   Zwrappers.responser   	Exceptionr   r   r$   r'   LookupErrorr,   rK   rL   r   r   r   r   <module>   s$   
	F