def proxy_for(self, proxy_for_id): """Return a view on this blip that will proxy for the specified id. A shallow copy of the current blip is returned with the proxy_for_id set. Any modifications made to this copy will be done using the proxy_for_id, i.e. the robot+<proxy_for_id>@appspot.com address will be used. """ util.check_is_valid_proxy_for_id(proxy_for_id) operation_queue = self._operation_queue.proxy_for(proxy_for_id) res = Blip(json={}, other_blips={}, operation_queue=operation_queue) res._blip_id = self._blip_id res._child_blip_ids = self._child_blip_ids res._content = self._content res._contributors = self._contributors res._creator = self._creator res._last_modified_time = self._last_modified_time res._version = self._version res._parent_blip_id = self._parent_blip_id res._wave_id = self._wave_id res._wavelet_id = self._wavelet_id res._other_blips = self._other_blips res._annotations = self._annotations res._elements = self._elements res.raw_data = self.raw_data return res
def proxy_for(self, proxy_for_id): """Return a view on this wavelet that will proxy for the specified id. A shallow copy of the current wavelet is returned with the proxy_for_id set. Any modifications made to this copy will be done using the proxy_for_id, i.e. the robot+<proxy_for_id>@appspot.com address will be used. If the wavelet was retrieved using the Active Robot API, that is by fetch_wavelet, then the address of the robot must be added to the wavelet by setting wavelet.robot_address before calling proxy_for(). """ util.check_is_valid_proxy_for_id(proxy_for_id) self.add_proxying_participant(proxy_for_id) operation_queue = self.get_operation_queue().proxy_for(proxy_for_id) res = Wavelet(json={}, blips={}, root_thread=None, operation_queue=operation_queue) res._wave_id = self._wave_id res._wavelet_id = self._wavelet_id res._creator = self._creator res._creation_time = self._creation_time res._data_documents = self._data_documents res._last_modified_time = self._last_modified_time res._participants = self._participants res._title = self._title res._raw_data = self._raw_data res._blips = self._blips res._root_blip = self._root_blip res._root_thread = self._root_thread return res
def fetch_wavelet(self, wave_id, wavelet_id=None, proxy_for_id=None, raw_deltas_from_version=-1, return_raw_snapshot=False): """Use the REST interface to fetch a wave and return it. The returned wavelet contains a snapshot of the state of the wavelet at that point. It can be used to modify the wavelet, but the wavelet might change in between, so treat carefully. Also note that the wavelet returned has its own operation queue. It the responsibility of the caller to make sure this wavelet gets submited to the server, either by calling robot.submit() or by calling .submit_with() on the returned wavelet. Args: wave_id: the wave id wavelet_id: the wavelet_id proxy_for_id: on whose behalf to execute the operation raw_deltas_from_version: If specified, return a raw dump of the delta history of this wavelet, starting at the given version. This may return only part of the history; use additional requests with higher raw_deltas_from_version parameters to get the rest. return_raw_snapshot: if true, return the raw data for this wavelet. """ util.check_is_valid_proxy_for_id(proxy_for_id) if not wavelet_id: domain, id = wave_id.split('!', 1) wavelet_id = domain + '!conv+root' operation_queue = ops.OperationQueue(proxy_for_id) operation_queue.robot_fetch_wave(wave_id, wavelet_id, raw_deltas_from_version, return_raw_snapshot) result = self._first_rpc_result(self.make_rpc(operation_queue)) return self._wavelet_from_json(result, ops.OperationQueue(proxy_for_id))
def fetch_wavelet(self, wave_id, wavelet_id=None, proxy_for_id=None): """Use the REST interface to fetch a wave and return it. The returned wavelet contains a snapshot of the state of the wavelet at that point. It can be used to modify the wavelet, but the wavelet might change in between, so treat carefully. Also note that the wavelet returned has its own operation queue. It the responsibility of the caller to make sure this wavelet gets submited to the server, either by calling robot.submit() or by calling .submit_with() on the returned wavelet. """ util.check_is_valid_proxy_for_id(proxy_for_id) if not wavelet_id: domain, id = wave_id.split('!', 1) wavelet_id = domain + '!conv+root' operation_queue = ops.OperationQueue(proxy_for_id) operation_queue.robot_fetch_wave(wave_id, wavelet_id) result = self._first_rpc_result(self.make_rpc(operation_queue)) return self._wavelet_from_json(result, ops.OperationQueue(proxy_for_id))
def blind_wavelet(self, json, proxy_for_id=None): """Construct a blind wave from a json string. Call this method if you have a snapshot of a wave that you want to operate on outside of an event. Since the wave might have changed since you last saw it, you should take care to submit operations that are as safe as possible. Args: json: a json object or string containing at least a key wavelet defining the wavelet and a key blips defining the blips in the view. proxy_for_id: the proxying information that will be set on the wavelet's operation queue. Returns: A new wavelet with its own operation queue. It the responsibility of the caller to make sure this wavelet gets submited to the server, either by calling robot.submit() or by calling .submit_with() on the returned wavelet. """ util.check_is_valid_proxy_for_id(proxy_for_id) return self._wavelet_from_json(json, ops.OperationQueue(proxy_for_id))
def new_wave(self, domain, participants=None, message='', proxy_for_id=None, submit=False): """Create a new wave with the initial participants on it. A new wave is returned with its own operation queue. It the responsibility of the caller to make sure this wave gets submitted to the server, either by calling robot.submit() or by calling .submit_with() on the returned wave. Args: domain: the domain to create the wavelet on. This should in general correspond to the domain of the incoming wavelet. (wavelet.domain). Exceptions are situations where the robot is calling new_wave outside of an event or when the server is handling multiple domains. participants: initial participants on the wave. The robot as the creator of the wave is always added. message: a string that will be passed back to the robot when the WAVELET_CREATOR event is fired. This is a lightweight way to pass around state. submit: if true, use the active gateway to make a round trip to the server. This will return immediately an actual waveid/waveletid and blipId for the root blip. """ util.check_is_valid_proxy_for_id(proxy_for_id) operation_queue = ops.OperationQueue(proxy_for_id) if not isinstance(message, basestring): message = simplejson.dumps(message) # Create temporary wavelet data blip_data, wavelet_data = operation_queue.robot_create_wavelet( domain=domain, participants=participants, message=message) # Create temporary blips dictionary blips = {} root_blip = blip.Blip(blip_data, blips, operation_queue) blips[root_blip.blip_id] = root_blip if submit: # Submit operation to server and return actual wave/blip IDs temp_wavelet = wavelet.Wavelet(wavelet_data, blips=blips, root_thread=None, operation_queue=operation_queue) result = self._first_rpc_result(self.submit(temp_wavelet)) if isinstance(result, list): result = result[0] if 'blipId' in result: blip_data['blipId'] = result['blipId'] wavelet_data['rootBlipId'] = result['blipId'] for field in 'waveId', 'waveletId': if field in result: wavelet_data[field] = result[field] blip_data[field] = result[field] blips = {} root_blip = blip.Blip(blip_data, blips, operation_queue) blips[root_blip.blip_id] = root_blip root_thread = wavelet.BlipThread('', -1, [root_blip.blip_id], blips, operation_queue) new_wavelet = wavelet.Wavelet(wavelet_data, blips=blips, root_thread=root_thread, operation_queue=operation_queue) return new_wavelet