3
g                 @   s   d Z ddl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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 j|jd}tt||}|j r@|r4t||S ttd|j	 s\ttdd|i |j
 }t| jjd|j|jst S tjt|\}}|pd}t|j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_mtimest_sizer   	mimetypes
guess_typestrr   openr   headers)	requestr   Zdocument_rootZshow_indexesfullpathZstatobjr   encodingresponse r)   Q/var/www/tester-filtro-web/env/lib/python3.6/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   yt jddg}W n. tk
r@   tddidjt}t }Y nX i }g }xD|j D ]8}|jj	dsTt
|j|}|j r|d7 }|j| qTW |j| d |d t|j|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   S   s&    
r   c             C   sx   yX| dkrt tjd| tj}t|d }|d }|rFt||krFt t||krVt W n tt tfk
rr   dS X dS )aI  
    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.

    size
      This is the size of the item we're talking about.
    Nz^([^;]+)(; length=([0-9]+))?$      TF)
ValueErrorrematch
IGNORECASEr   intAttributeErrorOverflowError)headermtimesizematchesZheader_mtimeZ
header_lenr)   r)   r*   r   l   s    r   )NF)Nr   r   )__doc__r    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+   r0   Ztemplate_translatabler   r   r)   r)   r)   r*   <module>   s   
<