def download(filepath):
root.authorized()
return static_file(filepath, root='download', download=filepath)
python类static_file()的实例源码
def static_handler(path):
return bottle.static_file(
path,
root=os.path.join(os.path.dirname(__file__), '..', 'static'))
def callback(path):
"""Serve static files"""
return static_file(path, root=views_path)
def get_favicon():
"""Serve favicon"""
return static_file('favicon.ico', root=views_path)
def css(filepath):
return static_file(filepath, root='honeyd/utilities/http/css/')
# main page
def default_handler():
return bottle.static_file('app.html', root=os.path.join(conf['rootdir'], 'frontend') )
def static_bin_handler(file):
return bottle.static_file(file, root=os.path.join(conf['rootdir'], 'frontend'))
def static_css_handler(path):
return bottle.static_file(path, root=os.path.join(conf['rootdir'], 'frontend', 'css'))
def static_font_handler(path):
return bottle.static_file(path, root=os.path.join(conf['rootdir'], 'frontend', 'fonts'))
def static_js_handler(path):
return bottle.static_file(path, root=os.path.join(conf['rootdir'], 'frontend', 'js'))
def favicon_handler():
return bottle.static_file('favicon.ico', root=os.path.join(conf['rootdir'], 'frontend', 'img'))
def download(filename, dlname):
print "requesting: " + filename
return bottle.static_file(filename, root=tempfile.gettempdir(), download=dlname)
### LOW-LEVEL
def get(jobname='woot'):
"""Get a queue job in .dba format."""
base, name = os.path.split(_get_path(jobname))
return bottle.static_file(name, root=base, mimetype='application/json')
def get_library(jobname):
"""Get a library job in .dba format."""
base, name = os.path.split(_get_path(jobname, library=True))
return bottle.static_file(name, root=base, mimetype='application/json')
def server_static(filename):
""" route to the css and static files"""
if ".." in filename:
return HTTPError(status=403)
return bottle.static_file(filename, root='%s/static' % get_config('api', 'view-path', '/etc/softfire/views'))
#########
# Utils #
#########
def server_static(path):
return bottle.static_file(path, root="./")
def server_captures(path):
try:
return bottle.static_file(path, root="./temp")
except OSError as err:
logging.error("Error accessing static file: {message}".format(message=err.strerror))
return None
def get_index():
return static_file("index.html", root="static")
def js_dynamic(path):
response.headers['Expires'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT",
time.gmtime(time.time() + 60 * 60 * 24 * 2))
response.headers['Cache-control'] = "public"
response.headers['Content-Type'] = "text/javascript; charset=UTF-8"
try:
# static files are not rendered
if "static" not in path and "mootools" not in path:
t = env.get_template("js/%s" % path)
return t.render()
else:
return static_file(path, root=join(PROJECT_DIR, "media", "js"))
except:
return HTTPError(404, "Not Found")
def server_static(path):
response.headers['Expires'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT",
time.gmtime(time.time() + 60 * 60 * 24 * 7))
response.headers['Cache-control'] = "public"
return static_file(path, root=join(PROJECT_DIR, "media"))