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   úS/var/www/html/premium_crap/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    

( 