Beispiel #1
0
	def test_urljoin(self):
		from bokeh.utils import urljoin
		result1 = urljoin('http://www.bokeh.com','test/')
		self.assertEqual(result1, 'http://www.bokeh.com/test/')
		result2 = urljoin('http://www.bokeh.com','test1/','test2/','test3/','bokeh.html')
		self.assertEqual(result2,'http://www.bokeh.com/test1/test2/test3/bokeh.html')
		result3 = urljoin('http://www.notbokeh.com','http://www.bokeh.com/','test1/','bokeh1.squig')
		self.assertEqual(result3,'http://www.bokeh.com/test1/bokeh1.squig')
Beispiel #2
0
 def test_urljoin(self):
     from bokeh.utils import urljoin
     result1 = urljoin('http://www.bokeh.com', 'test/')
     self.assertEqual(result1, 'http://www.bokeh.com/test/')
     result2 = urljoin('http://www.bokeh.com', 'test1/', 'test2/',
                       'test3/', 'bokeh.html')
     self.assertEqual(result2, 'http://www.bokeh.com/test1/test2/test3/bokeh.html')
     result3 = urljoin('http://www.notbokeh.com', 'http://www.bokeh.com/',
                       'test1/', 'bokeh1.squig')
     self.assertEqual(result3, 'http://www.bokeh.com/test1/bokeh1.squig')
Beispiel #3
0
 def store_callbacks(self, to_store):
     all_data = self.callbacks_json(to_store)
     url = utils.urljoin(self.base_url, self.docid + "/", "callbacks")
     all_data = self.serialize(all_data)
     self.http_session.post(url, data=all_data)
     for m in to_store:
         m._callbacks_dirty = False
Beispiel #4
0
 def store_callbacks(self, to_store):
     all_data = self.callbacks_json(to_store)
     url = utils.urljoin(self.base_url, self.docid + "/", "callbacks")
     all_data = self.serialize(all_data)
     self.http_session.post(url, data=all_data)
     for m in to_store:
         m._callbacks_dirty = False
Beispiel #5
0
 def load_obj(self, ref, asdict=False, modelattrs={}):
     """loads an object from the server.
     if asdict:
         only the json is returned.
     else:
         update the existing copy in _models if it is present
         instantiate a new one if it is not
         and make sure to convert all references into models
     in the conversion from json to objects, sometimes references
     to models need to be resolved.  If there are any json attributes
     being processed, you can pass them in as modelattrs
     """
     typename = ref["type"]
     ref_id = ref["id"]
     url = utils.urljoin(self.base_url, self.docid + "/" + ref["type"] +\
                         "/" + ref["id"] + "/")
     attr = protocol.deserialize_json(self.http_session.get(url).content)
     if not asdict:
         m = PlotObject.get_obj(typename, attr)
         self.add(m)
         m.finalize(self._models)
         m.dirty = False
         return m
     else:
         return attr
Beispiel #6
0
 def load_all_callbacks(self, get_json=False):
     """get_json = return json of callbacks, rather than
     loading them into models
     """
     url = utils.urljoin(self.base_url, self.docid + "/", "callbacks")
     data = protocol.deserialize_json(self.http_session.get(url).content)
     if get_json:
         return data
     self.load_callbacks_json(data)
Beispiel #7
0
 def load_all_callbacks(self, get_json=False):
     """get_json = return json of callbacks, rather than
     loading them into models
     """
     url = utils.urljoin(self.base_url, self.docid + "/", "callbacks")
     data = protocol.deserialize_json(self.http_session.get(url).content)
     if get_json:
         return data
     self.load_callbacks_json(data)
Beispiel #8
0
 def load_type(self, typename, asdict=False):
     url = utils.urljoin(self.base_url, self.docid + "/", typename + "/")
     attrs = protocol.deserialize_json(self.http_session.get(url).content)
     if not asdict:
         models = self.load_attrs(typename, attrs)
         for m in models:
             m._dirty = False
         return models
     else:
         models = attrs
     return models
Beispiel #9
0
 def load_type(self, typename, asdict=False):
     url = utils.urljoin(self.base_url, self.docid +"/", typename + "/")
     attrs = protocol.deserialize_json(self.http_session.get(url).content)
     if not asdict:
         models = self.load_attrs(typename, attrs)
         for m in models:
             m._dirty = False
         return models
     else:
         models = attrs
     return models
Beispiel #10
0
 def load_all(self, asdict=False):
     """the json coming out of this looks different than that coming
     out of load_type, because it contains id, type, attributes, whereas
     the other one just contains attributes directly
     """
     url = utils.urljoin(self.base_url, self.docid + "/")
     attrs = protocol.deserialize_json(self.http_session.get(url).content)
     if not asdict:
         models = self.load_broadcast_attrs(attrs)
         for m in models:
             m._dirty = False
         return models
     else:
         models = attrs
     return models
Beispiel #11
0
 def load_all(self, asdict=False):
     """the json coming out of this looks different than that coming
     out of load_type, because it contains id, type, attributes, whereas
     the other one just contains attributes directly
     """
     url = utils.urljoin(self.base_url, self.docid +"/")
     attrs = protocol.deserialize_json(self.http_session.get(url).content)
     if not asdict:
         models = self.load_broadcast_attrs(attrs)
         for m in models:
             m._dirty = False
         return models
     else:
         models = attrs
     return models
Beispiel #12
0
 def store_all(self):
     models = []
     # Look for the Plot to stick into here. PlotContexts only
     # want things with a corresponding BokehJS View, so Plots and
     # GridPlots for now.
     theplot = [x for x in self._models if isinstance(x, Plot)][0]
     self.plotcontext.children = [theplot]
     for m in list(self._models) + [self.plotcontext]:
         ref = self.get_ref(m)
         ref["attributes"] = m.vm_serialize()
         # FIXME: Is this part really necessary? It shows up in the 
         # bbclient-based JSON serializations, but I don't understand
         # why it's necessary.
         ref["attributes"].update({"id": ref["id"], "doc": self.docid})
         models.append(ref)
     data = self.serialize(models)
     url = utils.urljoin(self.base_url, self.docid + "/", "bulkupsert")
     self.http_session.post(url, data=data)
Beispiel #13
0
    def store_obj(self, obj, ref=None):
        """ Uploads the object state and attributes to the server represented
        by this session.

        **ref** is a dict containing keys "type" and "id"; by default, the
        ref is retrieved/computed from **obj** itself.
        """
        jsondata = self.serialize(obj)
        if ref is not None and "type" in ref and "id" in ref:
            jsondata.update(ref)
        else:
            raise ValueError("ref needs to have both 'type' and 'id' keys")
        # This is copied from ContinuumModelsClient.buffer_sync(), .update(),
        # and .upsert_all().
        # TODO: Handle the include_hidden stuff.
        url = utils.urljoin(self.base_url, self.docid + "/" + jsondata["type"] +\
                "/" + jsondata["id"] + "/")
        self.http_session.put(url, data=jsondata)
Beispiel #14
0
 def store_broadcast_attrs(self, attrs):
     data = self.serialize(attrs)
     url = utils.urljoin(self.base_url, self.docid + "/", "bulkupsert")
     self.http_session.post(url, data=data)
Beispiel #15
0
 def store_broadcast_attrs(self, attrs):
     data = self.serialize(attrs)
     url = utils.urljoin(self.base_url, self.docid + "/", "bulkupsert")
     self.http_session.post(url, data=data)