def setup(self, backend, backbone_storage, servermodel_storage, authentication): self.backend = backend self.backbone_storage = backbone_storage self.servermodel_storage = servermodel_storage self.authentication = authentication self.bokehjsdir = settings.bokehjsdir() self.bokehjssrcdir = settings.bokehjssrcdir()
def setup(self, backend, backbone_storage, servermodel_storage, authentication, datamanager): self.datamanager = datamanager self.backend = backend self.backbone_storage = backbone_storage self.servermodel_storage = servermodel_storage self.authentication = authentication def auth(auth, docid): doc = docs.Doc.load(self.servermodel_storage, docid) status = mconv.can_write_doc_api(doc, auth, self) return status self.bokehjsdir = settings.bokehjsdir() self.bokehjssrcdir = settings.bokehjssrcdir()
def includeme(config): # app routes documentcontext = config.registry.documentcontext config.add_route( 'bokeh.gc', '/bokeh/bb/{docid}/gc', factory=documentcontext ) config.add_route( 'bokeh.bulk_upsert', '/bokeh/bb/{docid}/bulkupsert', factory=documentcontext, ) config.add_route( 'bokeh.create', '/bokeh/bb/{docid}/{typename}/', ) config.add_route( 'bokeh.bulkget_wo_typename', '/bokeh/bb/{docid}/', factory=documentcontext, ) config.add_route( 'bokeh.bulkget_w_typename', '/bokeh/bb/{docid}/{typename}/', factory=documentcontext, ) config.add_route( 'bokeh.handle_model', '/bokeh/bb/{docid}/{typename}/{id}/', factory=documentcontext, ) config.add_route( 'bokeh.login', '/bokeh/login') config.add_route( 'bokeh.loginfromapikey', '/bokeh/loginfromapikey') config.add_route( 'bokeh.register', '/bokeh/register') config.add_route( 'bokeh.logout', '/bokeh/logout') config.add_route( 'bokeh.publish', '/bokeh/{docid}/publish', factory=documentcontext, ) config.add_route( 'bokeh.root', '/') config.add_route( 'bokeh.index', '/bokeh/') config.add_route( 'bokeh.favicon', '/bokeh/favicon.ico') config.add_route( 'bokeh.docs', '/bokeh/doc/') config.add_route( 'bokeh.doc', '/bokeh/doc/{docid}/', factory=documentcontext, ) config.add_route( 'bokeh.getdocapikey', '/bokeh/getdocapikey/{docid}', factory=documentcontext, ) config.add_route( 'bokeh.userinfo', '/bokeh/userinfo/') config.add_route( 'bokeh.info', '/bokeh/bokehinfo/{docid}/', factory=documentcontext, ) config.add_route( 'bokeh.showdoc', '/bokeh/doc/{title}/show') config.add_route( 'bokeh.sampleerror', '/bokeh/sampleerror') config.add_route( 'bokeh.autoloadjs', '/bokeh/autoload.js/{elementid}' ) config.add_route( 'bokeh.objinfo', '/bokeh/objinfo/{docid}/{objid}', factory=documentcontext, ) config.add_route( 'bokeh.showobj', '/bokeh/doc/{docid}/{objid}', factory=documentcontext, ) config.add_route( 'bokeh.wsurl', '/bokeh/wsurl/') config.add_route( 'bokeh.ping', '/bokeh/ping') config.add_route( 'bokeh.generatejs', '/bokeh/jsgenerate/{parentname}/{modulename}/{classname}') jsdir = bokeh_settings.bokehjsdir() jssrcdir = bokeh_settings.bokehjssrcdir() # static views config.add_static_view('bokehjs/static', jsdir, cache_max_age=3600) if jssrcdir is not None: config.add_static_view('bokehjs/src', jssrcdir, cache_max_age=3600) config.add_static_view( 'static', 'pyramid_bokehserver:static', cache_max_age=3600) # notfound view (append_slash needed for /doc vs. doc/ etc) config.add_notfound_view(notfound, append_slash=True) # scan config.scan('.')
def getapp(settings): # settings should be a bokehserver.settings.Settings """ This function returns a Pyramid WSGI application representing the Bokeh server. """ config = Configurator(settings={}) config.registry.bokehserver_settings = settings backend = settings.model_backend if backend['type'] == 'redis': import redis rhost = backend.get('redis_host', '127.0.0.1') rport = backend.get('redis_port', REDIS_PORT) bbstorage = RedisBackboneStorage( redis.Redis(host=rhost, port=rport, db=2) ) servermodel_storage = RedisServerModelStorage( redis.Redis(host=rhost, port=rport, db=3) ) elif backend['type'] == 'memory': bbstorage = InMemoryBackboneStorage() servermodel_storage = InMemoryServerModelStorage() elif backend['type'] == 'shelve': bbstorage = ShelveBackboneStorage() servermodel_storage = ShelveServerModelStorage() if settings.multi_user: default_username = None else: default_username = '******' authentication = BokehAuthenticationPolicy( default_username=default_username, ) authorization = BokehAuthorizationPolicy() url_prefix = settings.url_prefix publisher = Publisher(settings.ctx, settings.pub_zmqaddr, Queue()) for script in settings.scripts: script_dir = os.path.dirname(script) if script_dir not in sys.path: print ("adding %s to python path" % script_dir) sys.path.append(script_dir) print ("importing and scanning %s" % script) mod = imp.load_source("_bokeh_app", script) if hasattr(mod, 'includeme'): config.include(mod) else: config.scan(mod) config.registry.url_prefix = url_prefix config.registry.publisher = publisher config.registry.wsmanager = websocket.WebSocketManager() config.registry.backend = backend config.registry.servermodel_storage = servermodel_storage config.registry.backbone_storage = bbstorage config.registry.authentication = authentication config.registry.authorization = authorization config.registry.bokehjsdir = bokeh_settings.bokehjsdir() config.registry.bokehjssrcdir = bokeh_settings.bokehjssrcdir() config.registry.documentcontext = DocumentContext config.registry.default_username = default_username # add a ``request.current_user()`` API config.add_request_method(current_user) # add a ``request.current_document()`` API config.add_request_method(current_document) # configure a session factory for request.session access and # SessionAuthenticationPolicy usage session_factory = SignedCookieSessionFactory(settings.secret_key) config.set_session_factory(session_factory) # do jinja2 setup; files ending in .html and .js will be considered # jinja2 templates config.include('pyramid_jinja2') config.add_jinja2_renderer('.html') config.add_jinja2_renderer('.js') # register routes and default views config.include('.views') # set up default declarative security context config.set_root_factory(RootContext) # set up view-time security policies config.set_authentication_policy(authentication) config.set_authorization_policy(authorization) # return a WSGI application return config.make_wsgi_app()