def load_doc(self, docid): url = urlparse.urljoin(self.root_url,"/bokeh/getdocapikey/%s" % docid) resp = self.http_session.get(url, verify=False) if resp.status_code == 401: raise Exception('HTTP Unauthorized accessing DocID "%s"' % docid) apikey = utils.get_json(resp) if 'apikey' in apikey: self.docid = docid self.apikey = apikey['apikey'] logger.info('got read write apikey') else: self.docid = docid self.apikey = apikey['readonlyapikey'] logger.info('got read only apikey') self.load_all() plotcontext = self.load_type('PlotContext') if len(plotcontext): temp = plotcontext[0] if len(plotcontext) > 1: logger.warning( "Found more than one PlotContext for doc ID %s; " \ "Using PlotContext ID %s" % (self.docid, temp._id)) plotcontext = temp else: logger.warning("Unable to load PlotContext for doc ID %s" % self.docid) plotcontext = PlotContext() self.store_obj(plotcontext) self.plotcontext = plotcontext return
def make_doc(self, title): url = urlparse.urljoin(self.root_url,"/bokeh/doc/") data = protocol.serialize_web({'title' : title}) response = self.http_session.post(url, data=data, verify=False) if response.status_code == 409: raise DataIntegrityException self.userinfo = utils.get_json(response)
def load_doc(self, docid): url = urlparse.urljoin(self.root_url,"/bokeh/getdocapikey/%s" % docid) resp = self.http_session.get(url, verify=False) if resp.status_code == 401: raise Exception('HTTP Unauthorized accessing DocID "%s"' % docid) apikey = utils.get_json(resp) if 'apikey' in apikey: self.docid = docid self.apikey = apikey['apikey'] logger.info('got read write apikey') else: self.docid = docid self.apikey = apikey['readonlyapikey'] logger.info('got read only apikey') url = urlparse.urljoin(self.root_url, "/bokeh/bb/") # TODO: Load the full document. For now, just load the PlotContext url = urlparse.urljoin(self.base_url, self.docid+"/PlotContext/") attrs = protocol.deserialize_json(self.http_session.get(url).content) if len(attrs) == 0: logger.warning("Unable to load PlotContext for doc ID %s" % self.docid) else: self.plotcontext = PlotServerSession.PlotContext(id=attrs[0]["id"]) if len(attrs) > 1: logger.warning("Found more than one PlotContext for doc ID %s; " \ "Using PlotContext ID %s" % (self.docid, attrs[0]["id"])) return
def __init__(self, username=None, serverloc=None, userapikey="nokey"): # This logic is based on ContinuumModelsClient.__init__ and # mpl.PlotClient.__init__. There is some merged functionality here # since a Session is meant to capture the little bit of lower-level # logic in PlotClient (i.e. avoiding handling of things like # _newxyplot()), but also build in the functionality of the # ContinuumModelsClient. self.username = username self.root_url = serverloc self.http_session = requests.session() self.http_session.headers.update({ 'content-type':'application/json', 'BOKEHUSER-API-KEY' : userapikey, 'BOKEHUSER' : username}) if self.root_url: url = urlparse.urljoin(self.root_url, '/bokeh/userinfo/') self.userinfo = utils.get_json(self.http_session.get(url, verify=False)) else: logger.info('Not using a server, plots will only work in embedded mode') self.userinfo = None self.docid = None self.plotcontext = None self.apikey = None self.bbclient = None # reference to a ContinuumModelsClient self.base_url = urlparse.urljoin(self.root_url, "/bokeh/bb/") super(PlotServerSession, self).__init__()
def remove_doc(self, title): matching = [x for x in self.userinfo["docs"] if x.get("title") == title] docid = matching[0]["docid"] url = urlparse.urljoin(self.root_url, "/bokeh/doc/%s/" % docid) response = self.http_session.delete(url, verify=False) if response.status_code == 409: raise DataIntegrityException self.userinfo = utils.get_json(response)
def load_doc(self, docid): url = urlparse.urljoin(self.root_url, "/bokeh/getdocapikey/%s" % docid) resp = self.session.get(url, verify=False) if resp.status_code == 401: raise Exception, 'unauthorized' apikey = get_json(resp) if 'apikey' in apikey: self.docid = docid self.apikey = apikey['apikey'] print 'got read write apikey' else: self.docid = docid self.apikey = apikey['readonlyapikey'] print 'got read only apikey' self.models = {} url = urlparse.urljoin(self.root_url, "/bokeh/bb/") self.bbclient = bbmodel.ContinuumModelsClient(docid, url, self.apikey) interactive_contexts = self.bbclient.fetch(typename='PlotContext') if len(interactive_contexts) > 1: print 'warning, multiple plot contexts here...' self.ic = interactive_contexts[0]
def load_doc(self, docid): url = urlparse.urljoin(self.root_url,"/bokeh/getdocapikey/%s" % docid) resp = self.session.get(url, verify=False) if resp.status_code == 401: raise Exception, 'unauthorized' apikey = get_json(resp) if 'apikey' in apikey: self.docid = docid self.apikey = apikey['apikey'] print 'got read write apikey' else: self.docid = docid self.apikey = apikey['readonlyapikey'] print 'got read only apikey' self.models = {} url = urlparse.urljoin(self.root_url, "/bokeh/bb/") self.bbclient = bbmodel.ContinuumModelsClient( docid, url, self.apikey) interactive_contexts = self.bbclient.fetch( typename='PlotContext') if len(interactive_contexts) > 1: print 'warning, multiple plot contexts here...' self.ic = interactive_contexts[0]
def test_with_method(self): self.assertTrue(utils.get_json(DummyRequestCallable()))
def test_with_property(self): self.assertTrue(utils.get_json(DummyRequestProperty()))
def update_userinfo(self): url = urlparse.urljoin(self.root_url, '/bokeh/userinfo/') self.userinfo = get_json(self.session.get(url, verify=False))
def test_with_method(self): from bokeh.utils import get_json self.assertTrue(get_json(DummyRequestCallable()))
def test_with_property(self): from bokeh.utils import get_json self.assertTrue(get_json(DummyRequestProperty()))