U
    /v¶hî  ã                   @  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rŽd 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   ú?/tmp/pip-unpacked-wheel-c3xdgso7/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 )ÚRequestRedirectzÜRaise 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kƒ gƒS )Ng\�Âõ(\ï?g{®Gáz„?r   )ÚsumÚdifflibZSequenceMatcherr   r-   Z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 k	rœ| j| jjkrœ| dt| jjƒ›d�¡ | jj t	| jj
p°dƒ¡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   s8    
ÿ
þýÿÿþÿzBuildError.__str__)N)
r   r   r   r   r   r   r4   r2   rM   r%   r   r   r   r   r.   D   s   	 ûr.   c                   @  s   e Zd ZdZdS )ÚWebsocketMismatchz�The 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   rN   �   s   rN   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]r9   r   )rQ   rR   r   c                 C  s   || _ || _d S r   rP   )r   rQ   rR   r   r   r   r   –   s    zNoMatch.__init__N)r   r   r   r(   r   r   r   r   r   rO   “   s   rO   )Ú
__future__r   r8   ÚtypingÚtÚ
exceptionsr   r   Úutilsr   r   ÚTYPE_CHECKINGZ_typeshed.wsgir   Zwrappers.requestr	   Zwrappers.responser
   r@   r   Úrulesr   Ú	Exceptionr   r   r&   r)   ÚLookupErrorr.   rN   rO   r   r   r   r   Ú<module>   s&   
	I