o
    {,h                     @   s   d Z ddlZddlZ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dlmZmZ ddlmZ dd	lmZ d
d ZdddZedZdd ZdddZdS )z
Views and functions for serving static files. These are only to be used
during development, and SHOULD NOT be used in a production setting.
    N)Path)FileResponseHttp404HttpResponseHttpResponseNotModified)ContextEngineTemplateDoesNotExistloader)	safe_join)	http_dateparse_http_date)gettext)gettext_lazyc                 C   s   t tjd |  S )z
    Return a path to a builtin template.

    Avoid calling this function at the module level or in a class-definition
    because __file__ may not exist, e.g. in frozen environments.
    	templates)r   __file__parent)name r   I/var/www/html/rh/venv/lib/python3.10/site-packages/django/views/static.pybuiltin_template_path   s   r   Fc           	      C   s   t |d}tt||}| r |rt||S ttd|	 s.ttdd|i |
 }t| jd|js?t S tt|\}}|pKd}t|d|d}t|j|jd	< |rd||jd
< |S )aF  
    Serve static files below a given point in the directory structure.

    To use, put a URL pattern such as::

        from django.views.static import serve

        path('<path:path>', serve, {'document_root': '/path/to/my/files/'})

    in your URLconf. You must provide the ``document_root`` param. You may
    also set ``show_indexes`` to ``True`` if you'd like to serve a basic index
    of the directory.  This index view will use the template hardcoded below,
    but if you'd like to override it, you can create a template called
    ``static/directory_index.html``.
    /z'Directory indexes are not allowed here.u   “%(path)s” does not existpathHTTP_IF_MODIFIED_SINCEzapplication/octet-streamrb)content_typezLast-ModifiedzContent-Encoding)	posixpathnormpathlstripr   r   is_dirdirectory_indexr   _existsstatwas_modified_sinceMETAgetst_mtimer   	mimetypes
guess_typestrr   openr   headers)	requestr   document_rootshow_indexesfullpathstatobjr   encodingresponser   r   r   serve   s(   

r4   zIndex of %(directory)sc                 C   s   z	t ddg}W n0 ty9   tdjdd}tddid| }W d    n1 s/w   Y  t }Y nw i }g }|	 D ]}|j
d	s^t||}| rY|d
7 }|| qB|| d
 |d t||S )Nzstatic/directory_index.htmlzstatic/directory_indexzdirectory_index.htmlzutf-8)r2   i18nzdjango.templatetags.i18n)	libraries.r   )	directory	file_list)r
   select_templater	   r   r+   r   from_stringreadr   iterdirr   
startswithr*   relative_tor   appendupdater   render)r   r0   tfhcfilesfurlr   r   r   r    G   s:   

r    c              	   C   sD   z| du rt t| }t||krt W dS  t tfy!   Y dS w )a  
    Was something modified since the user last downloaded it?

    header
      This is the value of the If-Modified-Since header.  If this is None,
      I'll just return True.

    mtime
      This is the modification time of the item we're talking about.
    NTF)
ValueErrorr   intOverflowError)headermtimeheader_mtimer   r   r   r$   g   s   r$   )NF)Nr   )__doc__r(   r   pathlibr   django.httpr   r   r   r   django.templater   r   r	   r
   django.utils._osr   django.utils.httpr   r   django.utils.translationr   r!   r   r   r4   template_translatabler    r$   r   r   r   r   <module>   s    

( 