#-----------------------------------------------------------------------------# Copyright (c) Anaconda, Inc., and Bokeh Contributors.# All rights reserved.## The full license is in the file LICENSE.txt, distributed with this software.#-----------------------------------------------------------------------------''' Provide a request handler that returns a page displaying a document.'''#-----------------------------------------------------------------------------# Boilerplate#-----------------------------------------------------------------------------from__future__importannotationsimportlogging# isort:skiplog=logging.getLogger(__name__)#-----------------------------------------------------------------------------# Imports#-----------------------------------------------------------------------------# External importsfromtornado.webimportStaticFileHandler# Bokeh importsfrombokeh.settingsimportsettings#-----------------------------------------------------------------------------# Globals and constants#-----------------------------------------------------------------------------__all__=('StaticHandler',)#-----------------------------------------------------------------------------# General API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Dev API#-----------------------------------------------------------------------------
[docs]classStaticHandler(StaticFileHandler):''' Implements a custom Tornado static file handler for BokehJS JavaScript and CSS resources. '''def__init__(self,tornado_app,*args,**kw)->None:kw['path']=settings.bokehjs_path()# Note: tornado_app is stored as self.applicationsuper().__init__(tornado_app,*args,**kw)# We aren't using tornado's built-in static_path function# because it relies on TornadoApplication's autoconfigured# static handler instead of our custom one. We have a# custom one because we think we might want to serve# static files from multiple paths at once in the future.@classmethoddefappend_version(cls,path:str)->str:# This version is cached on the StaticFileHandler class,# keyed by absolute filesystem path, and only invalidated# on an explicit StaticFileHandler.reset(). The reset is# automatic on every request if you set static_hash_cache=False# in TornadoApplication kwargs. In dev mode rely on dev tools# to manage caching. This improves the ability to debug code.ifsettings.dev:returnpathelse:version=StaticFileHandler.get_version(dict(static_path=settings.bokehjs_path()),path)returnf"{path}?v={version}"