U
    ˆjÃ  ã                   @   s    d Z dZddlmZ ddlmZ ddlmZmZ ddl	m
Z
mZ ddlmZmZ G dd	„ d	eƒZeeeed
œdd„Zdeee
dœdd„Zdeee
dœdd„ZdS )z*
Utility implementations of L{IResource}.
)Ú	errorPageÚnotFoundÚ	forbiddené    )Úcast)Úhttp)ÚIRenderableÚIRequest)Ú	IResourceÚResource)ÚrenderElementÚtagsc                       sN   e Zd ZdZeeeddœ‡ fdd„Zeedœdd„Z	e
eed	œd
d„Z‡  ZS )Ú
_ErrorPagea!  
    L{_ErrorPage} is a resource that responds to all requests with a particular
    (parameterized) HTTP status code and an HTML body containing some
    descriptive text. This is useful for rendering simple error pages.

    @see: L{twisted.web.pages.errorPage}

    @ivar _code: An integer HTTP status code which will be used for the
        response.

    @ivar _brief: A short string which will be included in the response body as
        the page title.

    @ivar _detail: A longer string which will be included in the response body.
    N©ÚcodeÚbriefÚdetailÚreturnc                    s    t ƒ  ¡  || _|| _|| _d S )N)ÚsuperÚ__init__Ú_codeÚ_briefÚ_detail)Úselfr   r   r   ©Ú	__class__© ú5/tmp/pip-unpacked-wheel-j5h_c8_q/twisted/web/pages.pyr   (   s    
z_ErrorPage.__init__)Úrequestr   c                 C   sb   |  | j¡ | dd¡ t|ttt t t 	| j› d| j
› �¡¡t t | j
¡t | j¡¡¡ƒƒS )zŠ
        Respond to all requests with the given HTTP status code and an HTML
        document containing the explanatory strings.
        s   content-types   text/html; charset=utf-8z - )ZsetResponseCoder   Z	setHeaderr   r   r   r   ÚhtmlÚheadÚtitler   ÚbodyÚh1Úpr   )r   r   r   r   r   Úrender.   s    þþûz_ErrorPage.render)Úpathr   r   c                 C   s   | S )z½
        Handle all requests for which L{_ErrorPage} lacks a child by returning
        this error page.

        @param path: A path segment.

        @param request: HTTP request
        r   )r   r%   r   r   r   r   ÚgetChildC   s    	z_ErrorPage.getChild)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚintÚstrr   r   Úobjectr$   Úbytesr
   r&   Ú__classcell__r   r   r   r   r      s   r   r   c                 C   s   t | ||ƒS )az  
    Build a resource that responds to all requests with a particular HTTP
    status code and an HTML body containing some descriptive text. This is
    useful for rendering simple error pages.

    The resource dynamically handles all paths below it. Use
    L{IResource.putChild()} to override a specific path.

    @param code: An integer HTTP status code which will be used for the
        response.

    @param brief: A short string which will be included in the response
        body as the page title.

    @param detail: A longer string which will be included in the
        response body.

    @returns: An L{IResource}
    )r   )r   r   r   r   r   r   r   O   s    r   úNo Such Resourceú%Sorry. No luck finding that resource.)r   Úmessager   c                 C   s   t tj| |ƒS )a  
    Generate an L{IResource} with a 404 Not Found status code.

    @see: L{twisted.web.pages.errorPage}

    @param brief: A short string displayed as the page title.

    @param message: A longer string displayed in the page body.

    @returns: An L{IResource}
    )r   r   Ú	NOT_FOUND©r   r2   r   r   r   r   f   s    r   úForbidden ResourceúSorry, resource is forbidden.c                 C   s   t tj| |ƒS )a  
    Generate an L{IResource} with a 403 Forbidden status code.

    @see: L{twisted.web.pages.errorPage}

    @param brief: A short string displayed as the page title.

    @param message: A longer string displayed in the page body.

    @returns: An L{IResource}
    )r   r   Ú	FORBIDDENr4   r   r   r   r   x   s    r   N)r0   r1   )r5   r6   )r*   Ú__all__Útypingr   Ztwisted.webr   Ztwisted.web.iwebr   r   Ztwisted.web.resourcer	   r
   Ztwisted.web.templater   r   r   r+   r,   r   r   r   r   r   r   r   Ú<module>   s,   8  þý   ÿ þ