Ejemplo n.º 1
0
    def DeleteAnnotationsInRange(self, r, name):
        """Clears all of the annotations within a given range with a given key.

    Args:
      r: A Range specifying the range to delete.
      name: Annotation key type to clear.
    """
        self.__context.builder.DocumentAnnotationDelete(
            self._blip.waveId, self._blip.waveletId, self._blip.blipId,
            r.start, r.end, name)
        res = []
        for a in self._blip.annotations:
            if a.name != name or r.start > a.range.end or r.end < a.range.start:
                res.append(a)
            elif r.start < a.range.start and r.end > a.range.end:
                continue
            else:
                if a.range.start < r.start:
                    res.append(
                        document.Annotation(
                            name, a.value,
                            document.Range(a.range.start, r.start)))
                if a.range.end > r.end:
                    a.range.start = r.end
                    res.append(a)
        self._blip.annotations = res
Ejemplo n.º 2
0
    def __init__(self, json):
        """Inits this blip with JSON data.

    Args:
      json: JSON data dictionary from Wave server.
    """
        self.blipId = json.get('blipId')
        self.childBlipIds = set(json.get('childBlipIds', []))
        self.content = json.get('content', '')
        self.contributors = set(json.get('contributors', []))
        self.creator = json.get('creator')
        self.lastModifiedTime = json.get('lastModifiedTime', 0)
        self.parentBlipId = json.get('parentBlipId')
        self.waveId = json.get('waveId')
        self.waveletId = json.get('waveletId')
        self.annotations = []
        for annotation in json.get('annotations', []):
            r = document.Range(annotation['range']['start'],
                               annotation['range']['end'])
            self.annotations.append(
                document.Annotation(annotation['name'],
                                    annotation['value'],
                                    r=r))
        self.document = Document(self)
        self.elements = {}
        json_elements = json.get('elements', {})
        for elem in json_elements:
            self.elements[elem] = document.ElementFromJson(json_elements[elem])
        self.raw_data = json
Ejemplo n.º 3
0
def CreateBlipData(data):
  """Construct blip data from the raw incoming wire protocol.

  TODO(davidbyttow): Automate this based on naming like the Serialize methods.

  Args:
    data: Serialized data from server.

  Returns:
    Instance of BlipData based on the fields.
  """
  blip_data = BlipData()
  blip_data.annotations = []
  for annotation in data['annotations']:
    r = document.Range(annotation['range']['start'],
                       annotation['range']['end'])
    blip_data.annotations.append(document.Annotation(annotation['name'],
                                                     annotation['value'],
                                                     r=r))
  blip_data.child_blip_ids = set(data['childBlipIds'])
  blip_data.content = data['content']
  blip_data.contributors = set(data['contributors'])
  blip_data.creator = data['creator']
  blip_data.elements = data['elements']
  blip_data.last_modified_time = data['lastModifiedTime']
  blip_data.parent_blip_id = data['parentBlipId']
  blip_data.blip_id = data['blipId']
  blip_data.version = data['version']
  blip_data.wave_id = data['waveId']
  blip_data.wavelet_id = data['waveletId']
  return blip_data
Ejemplo n.º 4
0
    def AnnotateDocument(self, name, value):
        """Annotates the entire document.

    Args:
      name: A string as the key for this annotation.
      value: The value of this annotation.
    """
        b = self.__context.builder
        b.DocumentAnnotationSetNoRange(self._blip.waveId, self._blip.waveletId,
                                       self._blip.blipId, name, value)
        r = document.Range(0, len(self._blip.content))
        self._blip.annotations.append(document.Annotation(name, value, r))
Ejemplo n.º 5
0
    def SetAnnotation(self, r, name, value):
        """Sets an annotation on a given range.

    Args:
      r: A Range specifying the range to set the annotation.
      name: A string as the key for this annotation.
      value: The value of this annotaton.
    """
        self.__context.builder.DocumentAnnotationSet(self._blip.waveId,
                                                     self._blip.waveletId,
                                                     self._blip.blipId,
                                                     r.start, r.end, name,
                                                     value)
        self._blip.annotations.append(document.Annotation(name, value, r))
Ejemplo n.º 6
0
  def DocumentAnnotationSetNoRange(self, wave_id, wavelet_id, blip_id,
                                   name, value):
    """Requests to set an annotation on an entire document.

    Args:
      wave_id: The wave id owning that this operation is applied to.
      wavelet_id: The wavelet id that this operation is applied to.
      blip_id: The blip id that this operation is applied to.
      name: Annotation key name to clear.
      value: The value of the annotation.
    """
    annotation = document.Annotation(name, value, None)
    self.AddNewOperation(DOCUMENT_ANNOTATION_SET_NORANGE, wave_id, wavelet_id,
                         blip_id=blip_id,
                         prop=annotation)
Ejemplo n.º 7
0
  def DocumentAnnotationSet(self, wave_id, wavelet_id, blip_id, start, end,
                            name, value):
    """Set a specified annotation of a given range with a specific key.

    Args:
      wave_id: The wave id owning that this operation is applied to.
      wavelet_id: The wavelet id that this operation is applied to.
      blip_id: The blip id that this operation is applied to.
      start: Start position of the range.
      end: End position of the range.
      name: Annotation key name to clear.
      value: The value of the annotation across this range.
    """
    annotation = document.Annotation(name, value, document.Range(start, end))
    self.AddNewOperation(DOCUMENT_ANNOTATION_SET, wave_id, wavelet_id,
                         blip_id=blip_id,
                         prop=annotation)
Ejemplo n.º 8
0
 def testFields(self):
     annotation = document.Annotation('key', 'value', document.Range(2, 3))
     self.assertEquals('key', annotation.name)
     self.assertEquals('value', annotation.value)
     self.assertEquals(2, annotation.range.start)
     self.assertEquals(3, annotation.range.end)
Ejemplo n.º 9
0
 def testDefaults(self):
     annotation = document.Annotation('key', 'value')
     self.assertEquals(document.Range().start, annotation.range.start)
     self.assertEquals(document.Range().end, annotation.range.end)