a
    LcòfÞ  ã                   @   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d„Z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_lazyFc           	      C   sÌ   t  |¡ d¡}tt||ƒƒ}| ¡ r@|r4t||ƒS ttdƒƒ‚| 	¡ s\ttdƒd|i ƒ‚| 
¡ }t| j d¡|jƒs~tƒ S t t|ƒ¡\}}|p–d}t| d¡|d�}t|jƒ|jd	< |rÈ||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ÚpathZ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_sinceZMETAÚgetÚst_mtimer   Ú	mimetypesÚ
guess_typeÚstrr   Úopenr   Úheaders)	Úrequestr   Zdocument_rootZshow_indexesÚfullpathZstatobjr   ÚencodingÚresponse© r(   úP/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/django/views/static.pyÚserve   s(    
ÿ
r*   aŽ  
{% load i18n %}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Language" content="en-us">
    <meta name="robots" content="NONE,NOARCHIVE">
    <title>{% blocktranslate %}Index of {{ directory }}{% endblocktranslate %}</title>
  </head>
  <body>
    <h1>{% blocktranslate %}Index of {{ directory }}{% endblocktranslate %}</h1>
    <ul>
      {% if directory != "/" %}
      <li><a href="../">../</a></li>
      {% endif %}
      {% for f in file_list %}
      <li><a href="{{ f|urlencode }}">{{ f }}</a></li>
      {% endfor %}
    </ul>
  </body>
</html>
zIndex of %(directory)sc                 C   s¬   zt  ddg¡}W n, ty>   tddid� t¡}tƒ }Y n0 i }g }| ¡ D ]8}|j 	d¡sPt
| |¡ƒ}| ¡ r~|d7 }| |¡ qP| | d |dœ¡ t| |¡ƒS )	Nzstatic/directory_index.htmlzstatic/directory_indexZi18nzdjango.templatetags.i18n)Ú	librariesÚ.r   )Ú	directoryÚ	file_list)r
   Zselect_templater	   r   Zfrom_stringÚ DEFAULT_DIRECTORY_INDEX_TEMPLATEr   ÚiterdirÚnameÚ
startswithr!   Úrelative_tor   ÚappendÚupdater   Úrender)r   r%   ÚtÚcÚfilesÚfÚurlr(   r(   r)   r   R   s2    þÿÿþÿr   c              	   C   sF   z(| du rt ‚t| ƒ}t|ƒ|kr&t ‚W n t tfy@   Y dS 0 dS )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ÚmtimeZheader_mtimer(   r(   r)   r   q   s    r   )NF)Nr   )Ú__doc__r   r   Úpathlibr   Zdjango.httpr   r   r   r   Zdjango.templater   r   r	   r
   Zdjango.utils._osr   Zdjango.utils.httpr   r   Zdjango.utils.translationr   r   r   r*   r/   Ztemplate_translatabler   r   r(   r(   r(   r)   Ú<module>   s   
'