# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

import mimetypes
import os
import posixpath
import stat

from django.contrib.staticfiles import finders
from django.http import Http404, HttpResponseRedirect, HttpResponseNotModified, FileResponse
from django.shortcuts import redirect
from django.utils.http import http_date
from urllib.parse import unquote
from django.views.static import was_modified_since
from django.utils.translation import ugettext_lazy as _


def index_serve(request):
    return redirect('/static/', permanent=True)


def static_serve(request, path):
    if not path:
        path = 'index.html'
    normalized_path = posixpath.normpath(unquote(path)).lstrip('/')
    absolute_path = finders.find(normalized_path)
    if not absolute_path:
        if path.endswith('/') or path == '':
            raise Http404("Directory indexes are not allowed here.")
        raise Http404("'%s' could not be found" % path)
    document_root, path = os.path.split(absolute_path)

    path = posixpath.normpath(unquote(path))
    path = path.lstrip('/')
    newpath = ''
    for part in path.split('/'):
        if not part:
            # Strip empty path components.
            continue
        drive, part = os.path.splitdrive(part)
        head, part = os.path.split(part)
        if part in (os.curdir, os.pardir):
            # Strip '.' and '..' in path.
            continue
        newpath = os.path.join(newpath, part).replace('\\', '/')
    if newpath and path != newpath:
        return HttpResponseRedirect(newpath)
    fullpath = os.path.join(document_root, newpath)
    if os.path.isdir(fullpath):
        fullpath = os.path.join(fullpath, 'index.html')
        if os.path.isdir(fullpath):
            raise Http404(_("Directory indexes are not allowed here."))
    if not os.path.exists(fullpath):
        raise Http404(_('"%(path)s" does not exist') % {'path': fullpath})
    # Respect the If-Modified-Since header.
    statobj = os.stat(fullpath)
    if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
                              statobj.st_mtime, statobj.st_size):
        return HttpResponseNotModified()
    content_type, encoding = mimetypes.guess_type(fullpath)
    content_type = content_type or 'application/octet-stream'
    response = FileResponse(open(fullpath, 'rb'), content_type=content_type)
    response["Last-Modified"] = http_date(statobj.st_mtime)
    if stat.S_ISREG(statobj.st_mode):
        response["Content-Length"] = statobj.st_size
    if encoding:
        response["Content-Encoding"] = encoding
    return response


7fe920974a57fb4155ae7ee6047e2291dea3ea9b
<mask token>

<mask token>


def static_serve(request, path):
    if not path:
        path = 'index.html'
    normalized_path = posixpath.normpath(unquote(path)).lstrip('/')
    absolute_path = finders.find(normalized_path)
    if not absolute_path:
        if path.endswith('/') or path == '':
            raise Http404('Directory indexes are not allowed here.')
        raise Http404("'%s' could not be found" % path)
    document_root, path = os.path.split(absolute_path)
    path = posixpath.normpath(unquote(path))
    path = path.lstrip('/')
    newpath = ''
    for part in path.split('/'):
        if not part:
            continue
        drive, part = os.path.splitdrive(part)
        head, part = os.path.split(part)
        if part in (os.curdir, os.pardir):
            continue
        newpath = os.path.join(newpath, part).replace('\\', '/')
    if newpath and path != newpath:
        return HttpResponseRedirect(newpath)
    fullpath = os.path.join(document_root, newpath)
    if os.path.isdir(fullpath):
        fullpath = os.path.join(fullpath, 'index.html')
        if os.path.isdir(fullpath):
            raise Http404(_('Directory indexes are not allowed here.'))
    if not os.path.exists(fullpath):
        raise Http404(_('"%(path)s" does not exist') % {'path': fullpath})
    statobj = os.stat(fullpath)
    if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
        statobj.st_mtime, statobj.st_size):
        return HttpResponseNotModified()
    content_type, encoding = mimetypes.guess_type(fullpath)
    content_type = content_type or 'application/octet-stream'
    response = FileResponse(open(fullpath, 'rb'), content_type=content_type)
    response['Last-Modified'] = http_date(statobj.st_mtime)
    if stat.S_ISREG(statobj.st_mode):
        response['Content-Length'] = statobj.st_size
    if encoding:
        response['Content-Encoding'] = encoding
    return response

<mask token>


def index_serve(request):
    return redirect('/static/', permanent=True)


def static_serve(request, path):
    if not path:
        path = 'index.html'
    normalized_path = posixpath.normpath(unquote(path)).lstrip('/')
    absolute_path = finders.find(normalized_path)
    if not absolute_path:
        if path.endswith('/') or path == '':
            raise Http404('Directory indexes are not allowed here.')
        raise Http404("'%s' could not be found" % path)
    document_root, path = os.path.split(absolute_path)
    path = posixpath.normpath(unquote(path))
    path = path.lstrip('/')
    newpath = ''
    for part in path.split('/'):
        if not part:
            continue
        drive, part = os.path.splitdrive(part)
        head, part = os.path.split(part)
        if part in (os.curdir, os.pardir):
            continue
        newpath = os.path.join(newpath, part).replace('\\', '/')
    if newpath and path != newpath:
        return HttpResponseRedirect(newpath)
    fullpath = os.path.join(document_root, newpath)
    if os.path.isdir(fullpath):
        fullpath = os.path.join(fullpath, 'index.html')
        if os.path.isdir(fullpath):
            raise Http404(_('Directory indexes are not allowed here.'))
    if not os.path.exists(fullpath):
        raise Http404(_('"%(path)s" does not exist') % {'path': fullpath})
    statobj = os.stat(fullpath)
    if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
        statobj.st_mtime, statobj.st_size):
        return HttpResponseNotModified()
    content_type, encoding = mimetypes.guess_type(fullpath)
    content_type = content_type or 'application/octet-stream'
    response = FileResponse(open(fullpath, 'rb'), content_type=content_type)
    response['Last-Modified'] = http_date(statobj.st_mtime)
    if stat.S_ISREG(statobj.st_mode):
        response['Content-Length'] = statobj.st_size
    if encoding:
        response['Content-Encoding'] = encoding
    return response

from __future__ import absolute_import, unicode_literals
import mimetypes
import os
import posixpath
import stat
from django.contrib.staticfiles import finders
from django.http import Http404, HttpResponseRedirect, HttpResponseNotModified, FileResponse
from django.shortcuts import redirect
from django.utils.http import http_date
from urllib.parse import unquote
from django.views.static import was_modified_since
from django.utils.translation import ugettext_lazy as _


def index_serve(request):
    return redirect('/static/', permanent=True)


def static_serve(request, path):
    if not path:
        path = 'index.html'
    normalized_path = posixpath.normpath(unquote(path)).lstrip('/')
    absolute_path = finders.find(normalized_path)
    if not absolute_path:
        if path.endswith('/') or path == '':
            raise Http404('Directory indexes are not allowed here.')
        raise Http404("'%s' could not be found" % path)
    document_root, path = os.path.split(absolute_path)
    path = posixpath.normpath(unquote(path))
    path = path.lstrip('/')
    newpath = ''
    for part in path.split('/'):
        if not part:
            continue
        drive, part = os.path.splitdrive(part)
        head, part = os.path.split(part)
        if part in (os.curdir, os.pardir):
            continue
        newpath = os.path.join(newpath, part).replace('\\', '/')
    if newpath and path != newpath:
        return HttpResponseRedirect(newpath)
    fullpath = os.path.join(document_root, newpath)
    if os.path.isdir(fullpath):
        fullpath = os.path.join(fullpath, 'index.html')
        if os.path.isdir(fullpath):
            raise Http404(_('Directory indexes are not allowed here.'))
    if not os.path.exists(fullpath):
        raise Http404(_('"%(path)s" does not exist') % {'path': fullpath})
    statobj = os.stat(fullpath)
    if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
        statobj.st_mtime, statobj.st_size):
        return HttpResponseNotModified()
    content_type, encoding = mimetypes.guess_type(fullpath)
    content_type = content_type or 'application/octet-stream'
    response = FileResponse(open(fullpath, 'rb'), content_type=content_type)
    response['Last-Modified'] = http_date(statobj.st_mtime)
    if stat.S_ISREG(statobj.st_mode):
        response['Content-Length'] = statobj.st_size
    if encoding:
        response['Content-Encoding'] = encoding
    return response

# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

import mimetypes
import os
import posixpath
import stat

from django.contrib.staticfiles import finders
from django.http import Http404, HttpResponseRedirect, HttpResponseNotModified, FileResponse
from django.shortcuts import redirect
from django.utils.http import http_date
from urllib.parse import unquote
from django.views.static import was_modified_since
from django.utils.translation import ugettext_lazy as _


def index_serve(request):
    return redirect('/static/', permanent=True)


def static_serve(request, path):
    if not path:
        path = 'index.html'
    normalized_path = posixpath.normpath(unquote(path)).lstrip('/')
    absolute_path = finders.find(normalized_path)
    if not absolute_path:
        if path.endswith('/') or path == '':
            raise Http404("Directory indexes are not allowed here.")
        raise Http404("'%s' could not be found" % path)
    document_root, path = os.path.split(absolute_path)

    path = posixpath.normpath(unquote(path))
    path = path.lstrip('/')
    newpath = ''
    for part in path.split('/'):
        if not part:
            # Strip empty path components.
            continue
        drive, part = os.path.splitdrive(part)
        head, part = os.path.split(part)
        if part in (os.curdir, os.pardir):
            # Strip '.' and '..' in path.
            continue
        newpath = os.path.join(newpath, part).replace('\\', '/')
    if newpath and path != newpath:
        return HttpResponseRedirect(newpath)
    fullpath = os.path.join(document_root, newpath)
    if os.path.isdir(fullpath):
        fullpath = os.path.join(fullpath, 'index.html')
        if os.path.isdir(fullpath):
            raise Http404(_("Directory indexes are not allowed here."))
    if not os.path.exists(fullpath):
        raise Http404(_('"%(path)s" does not exist') % {'path': fullpath})
    # Respect the If-Modified-Since header.
    statobj = os.stat(fullpath)
    if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
                              statobj.st_mtime, statobj.st_size):
        return HttpResponseNotModified()
    content_type, encoding = mimetypes.guess_type(fullpath)
    content_type = content_type or 'application/octet-stream'
    response = FileResponse(open(fullpath, 'rb'), content_type=content_type)
    response["Last-Modified"] = http_date(statobj.st_mtime)
    if stat.S_ISREG(statobj.st_mode):
        response["Content-Length"] = statobj.st_size
    if encoding:
        response["Content-Encoding"] = encoding
    return response

