o
    uvXjt  ã                   @   sœ   d dl mZ d dlmZmZmZmZ d dlmZm	Z	m
Z
mZ d dlmZ dZdZdZdZeefd	d
„ƒZeefdd„ƒZeefdd„ƒZeefdd„ƒZdS )é    )Úquote)ÚHttpResponseBadRequestÚHttpResponseForbiddenÚHttpResponseNotFoundÚHttpResponseServerError)ÚContextÚEngineÚTemplateDoesNotExistÚloader)Úrequires_csrf_tokenz404.htmlz403.htmlz400.htmlz500.htmlc           	   	   C   s²   |j j}z|jd }W n ttfy   Y nw t|tƒr|}t| jƒ|dœ}zt	 
|¡}| || ¡}d}W n tyR   |tkrA‚ tƒ  d¡}| t|ƒ¡}d}Y nw t||d�S )a‚  
    Default 404 handler.

    Templates: :template:`404.html`
    Context:
        request_path
            The path of the requested URL (e.g., '/app/pages/bad_page/'). It's
            quoted to prevent a content injection attack.
        exception
            The message from the exception which triggered the 404 (if one was
            supplied), or the exception class name
    r   )Úrequest_pathÚ	exceptionNzM<h1>Not Found</h1><p>The requested resource was not found on this server.</p>ú	text/html©Úcontent_type)Ú	__class__Ú__name__ÚargsÚAttributeErrorÚ
IndexErrorÚ
isinstanceÚstrr   Úpathr
   Úget_templateÚrenderr	   ÚERROR_404_TEMPLATE_NAMEr   Úfrom_stringr   r   )	Úrequestr   Útemplate_nameÚexception_reprÚmessageÚcontextÚtemplateÚbodyr   © r$   úR/var/www/html/myproject/venv/lib/python3.10/site-packages/django/views/defaults.pyÚpage_not_found   s2   ÿ
þ
ÿör&   c                 C   sD   zt  |¡}W n ty   |tkr‚ tddd� Y S w t| ¡ ƒS )zS
    500 error handler.

    Templates: :template:`500.html`
    Context: None
    z<h1>Server Error (500)</h1>r   r   )r
   r   r	   ÚERROR_500_TEMPLATE_NAMEr   r   )r   r   r"   r$   r$   r%   Úserver_errorA   s   ür(   c                 C   sD   zt  |¡}W n ty   |tkr‚ tddd� Y S w t| ¡ ƒS )zS
    400 error handler.

    Templates: :template:`400.html`
    Context: None
    z<h1>Bad Request (400)</h1>r   r   )r
   r   r	   ÚERROR_400_TEMPLATE_NAMEr   r   ©r   r   r   r"   r$   r$   r%   Úbad_requestS   s   ür+   c                 C   sR   zt  |¡}W n ty   |tkr‚ tddd� Y S w t|j| dt|ƒid�ƒS )zæ
    Permission denied (403) handler.

    Templates: :template:`403.html`
    Context: None

    If the template does not exist, an Http403 response containing the text
    "403 Forbidden" (as per RFC 7231) will be returned.
    z<h1>403 Forbidden</h1>r   r   r   )r   r!   )r
   r   r	   ÚERROR_403_TEMPLATE_NAMEr   r   r   r*   r$   r$   r%   Úpermission_deniedi   s   üÿr-   N)Úurllib.parser   Údjango.httpr   r   r   r   Údjango.templater   r   r	   r
   Údjango.views.decorators.csrfr   r   r,   r)   r'   r&   r(   r+   r-   r$   r$   r$   r%   Ú<module>   s     -