/usr/lib/python3/dist-packages/flask_multistatic.py is in python3-flaskext.multistatic 1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | # -*- coding: utf-8 -*-
"""
(c) 2015 - Copyright Red Hat Inc.
Author: Pierre-Yves Chibon <pingou@pingoured.fr>
Distributed under License GPLv3 or later
You can find a copy of this license on the website
http://www.gnu.org/licenses/gpl.html
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
"""
import os
import sys
from flask import Flask
from flask.helpers import send_from_directory
from werkzeug.exceptions import NotFound
PY2 = sys.version_info[0] == 2
if PY2:
string_types = (str, unicode)
else:
string_types = (str,)
class MultiStaticFlask(Flask):
''' This class inherit from the main Flask application object and
override few methods to allow flask to support having multiple folders
serving static content.
'''
def _get_static_folder(self):
if self._static_folder is not None:
return [os.path.join(self.root_path, folder)
for folder in self._static_folder]
def _set_static_folder(self, value):
folders = value
if isinstance(folders, string_types):
folders = [value]
self._static_folder = folders
static_folder = property(_get_static_folder, _set_static_folder)
del _get_static_folder, _set_static_folder
# Use the last entry in the list of static folder as it should be what
# contains most of the files
def _get_static_url_path(self):
if self._static_url_path is not None:
return self._static_url_path
if self.static_folder is not None:
return '/' + os.path.basename(self.static_folder[-1])
def _set_static_url_path(self, value):
self._static_url_path = value
static_url_path = property(_get_static_url_path, _set_static_url_path)
del _get_static_url_path, _set_static_url_path
def send_static_file(self, filename):
"""Function used internally to send static files from the static
folder to the browser.
.. versionadded:: 0.5
"""
if not self.has_static_folder:
raise RuntimeError('No static folder for this object')
# Ensure get_send_file_max_age is called in all cases.
# Here, we ensure get_send_file_max_age is called for Blueprints.
cache_timeout = self.get_send_file_max_age(filename)
folders = self.static_folder
if isinstance(self.static_folder, string_types):
folders = [self.static_folder]
for directory in folders:
try:
return send_from_directory(
directory, filename, cache_timeout=cache_timeout)
except NotFound:
pass
raise NotFound()
|