Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.assertTrue(n.dirty)
clean_node(n)
sub.delete()
self.assertTrue(n.dirty)
def test_delete(self):
n = node.Node(type_=node.NodeType.Note)
clean_node(n)
n.delete()
self.assertTrue(n.timestamps.deleted)
self.assertTrue(n.dirty)
# FIXME: Node is not done
class TestElement(node.Element, node.TimestampsMixin):
def __init__(self):
super(TestElement, self).__init__()
self.timestamps = node.NodeTimestamps(0)
class TimestampsMixinTests(unittest.TestCase):
def test_touch(self):
n = TestElement()
n.touch()
self.assertTrue(n.dirty)
self.assertTrue(n.timestamps.updated > node.NodeTimestamps.int_to_dt(0))
self.assertTrue(n.timestamps.edited == node.NodeTimestamps.int_to_dt(0))
n.touch(True)
self.assertTrue(n.timestamps.updated > node.NodeTimestamps.int_to_dt(0))
self.assertTrue(n.timestamps.edited > node.NodeTimestamps.int_to_dt(0))
@property
def edited(self):
"""Get the user edited datetime.
Returns:
datetime.datetime: Datetime.
"""
return self._edited
@edited.setter
def edited(self, value):
self._edited = value
self._dirty = True
class NodeSettings(Element):
"""Represents the settings associated with a :class:`TopLevelNode`."""
def __init__(self):
super(NodeSettings, self).__init__()
self._new_listitem_placement = NewListItemPlacementValue.Bottom
self._graveyard_state = GraveyardStateValue.Collapsed
self._checked_listitems_policy = CheckedListItemsPolicyValue.Graveyard
def _load(self, raw):
super(NodeSettings, self)._load(raw)
self._new_listitem_placement = NewListItemPlacementValue(raw['newListItemPlacement'])
self._graveyard_state = GraveyardStateValue(raw['graveyardState'])
self._checked_listitems_policy = CheckedListItemsPolicyValue(raw['checkedListItemsPolicy'])
def save(self, clean=True):
ret = super(NodeSettings, self).save(clean)
ret['newListItemPlacement'] = self._new_listitem_placement.value
blob = bcls()
blob.load(raw)
return blob
def _load(self, raw):
super(Blob, self)._load(raw)
self.blob = self.from_json(raw.get('blob'))
def save(self, clean=True):
ret = super(Blob, self).save(clean)
if self.blob is not None:
ret['blob'] = self.blob.save(clean)
return ret
class Label(Element, TimestampsMixin):
"""Represents a label."""
def __init__(self):
super(Label, self).__init__()
create_time = time.time()
self.id = self._generateId(create_time)
self._name = ''
self.timestamps = NodeTimestamps(create_time)
self._merged = NodeTimestamps.int_to_dt(0)
@classmethod
def _generateId(cls, tz):
return 'tag.%s.%x' % (
''.join([random.choice('abcdefghijklmnopqrstuvwxyz0123456789') for _ in range(12)]),
int(tz * 1000)
self._extraction_status = raw.get('extraction_status')
drawing_info = None
if 'drawingInfo' in raw:
drawing_info = NodeDrawingInfo()
drawing_info.load(raw['drawingInfo'])
self._drawing_info = drawing_info
def save(self, clean=True):
ret = super(NodeDrawing, self).save(clean)
ret['extracted_text'] = self._extracted_text
ret['extraction_status'] = self._extraction_status
if self._drawing_info is not None:
ret['drawingInfo'] = self._drawing_info.save(clean)
return ret
class NodeDrawingInfo(Element):
"""Represents information about a drawing blob."""
def __init__(self):
super(NodeDrawingInfo, self).__init__()
self.drawing_id = ''
self.snapshot = NodeImage()
self._snapshot_fingerprint = ''
self._thumbnail_generated_time = NodeTimestamps.int_to_dt(0)
self._ink_hash = ''
self._snapshot_proto_fprint = ''
def _load(self, raw):
super(NodeDrawingInfo, self)._load(raw)
self.drawing_id = raw['drawingId']
self.snapshot.load(raw['snapshotData'])
self._snapshot_fingerprint = raw['snapshotFingerprint'] if 'snapshotFingerprint' in raw else self._snapshot_fingerprint
self._thumbnail_generated_time = NodeTimestamps.str_to_dt(raw['thumbnailGeneratedTime']) if 'thumbnailGeneratedTime' in raw else NodeTimestamps.int_to_dt(0)
if email in self._collaborators:
if self._collaborators[email] == ShareRequestValue.Add:
del self._collaborators[email]
else:
self._collaborators[email] = ShareRequestValue.Remove
self._dirty = True
def all(self):
"""Get all collaborators.
Returns:
List[str]: Collaborators.
"""
return [email for email, action in self._collaborators.items() if action in [RoleValue.Owner, RoleValue.User, ShareRequestValue.Add]]
class NodeLabels(Element):
"""Represents the labels on a :class:`TopLevelNode`."""
def __init__(self):
super(NodeLabels, self).__init__()
self._labels = {}
def __len__(self):
return len(self._labels)
def _load(self, raw):
# Parent method not called.
if raw and isinstance(raw[-1], bool):
self._dirty = raw.pop()
else:
self._dirty = False
self._labels = {}
for raw_label in raw:
@property
def checked_listitems_policy(self):
"""Get the policy for checked listitems.
Returns:
gkeepapi.node.CheckedListItemsPolicyValue: Policy.
"""
return self._checked_listitems_policy
@checked_listitems_policy.setter
def checked_listitems_policy(self, value):
self._checked_listitems_policy = value
self._dirty = True
class NodeCollaborators(Element):
"""Represents the collaborators on a :class:`TopLevelNode`."""
def __init__(self):
super(NodeCollaborators, self).__init__()
self._collaborators = {}
def __len__(self):
return len(self._collaborators)
def load(self, collaborators_raw, requests_raw): # pylint: disable=arguments-differ
# Parent method not called.
if requests_raw and isinstance(requests_raw[-1], bool):
self._dirty = requests_raw.pop()
else:
self._dirty = False
self._collaborators = {}
for collaborator in collaborators_raw:
"""
return self._checked
@checked.setter
def checked(self, value):
self._checked = value
self.touch(True)
def __str__(self):
return u'%s%s %s' % (
' ' if self.indented else '',
u'☑' if self.checked else u'☐',
self.text
)
class NodeBlob(Element):
"""Represents a blob descriptor."""
_TYPE = None
def __init__(self, type_=None):
super(NodeBlob, self).__init__()
self.blob_id = None
self.type = type_
self._media_id = None
self._mimetype = ''
self._is_uploaded = False
def _load(self, raw):
super(NodeBlob, self)._load(raw)
# Verify this is a valid type
BlobType(raw['type'])
self.blob_id = raw.get('blob_id')
self._media_id = raw.get('media_id')
if clean:
self._dirty = False
else:
ret['_dirty'] = self._dirty
return ret
@property
def dirty(self):
"""Get dirty state.
Returns:
str: Whether this element is dirty.
"""
return self._dirty
class Annotation(Element):
"""Note annotations base class."""
def __init__(self):
super(Annotation, self).__init__()
self.id = self._generateAnnotationId()
def _load(self, raw):
super(Annotation, self)._load(raw)
self.id = raw.get('id')
def save(self, clean=True):
ret = {}
if self.id is not None:
ret = super(Annotation, self).save(clean)
if self.id is not None:
ret['id'] = self.id
return ret
ret['context'] = context
return ret
def all(self):
"""Get all sub annotations.
Returns:
List[gkeepapi.node.Annotation]: Sub Annotations.
"""
return self._entries.values()
@property
def dirty(self):
return super(Context, self).dirty or any((annotation.dirty for annotation in self._entries.values()))
class NodeAnnotations(Element):
"""Represents the annotation container on a :class:`TopLevelNode`."""
def __init__(self):
super(NodeAnnotations, self).__init__()
self._annotations = {}
def __len__(self):
return len(self._annotations)
@classmethod
def from_json(cls, raw):
"""Helper to construct an annotation from a dict.
Args:
raw (dict): Raw annotation representation.
Returns:
return self.timestamps.trashed is not None and self.timestamps.trashed > NodeTimestamps.int_to_dt(0)
@property
def deleted(self):
"""Get the deleted state.
Returns:
bool: Whether this item is deleted.
"""
return self.timestamps.deleted is not None and self.timestamps.deleted > NodeTimestamps.int_to_dt(0)
def delete(self):
"""Mark the item as deleted."""
self.timestamps.deleted = datetime.datetime.utcnow()
class Node(Element, TimestampsMixin):
"""Node base class."""
def __init__(self, id_=None, type_=None, parent_id=None):
super(Node, self).__init__()
create_time = time.time()
self.parent = None
self.id = self._generateId(create_time) if id_ is None else id_
self.server_id = None
self.parent_id = parent_id
self.type = type_
self._sort = random.randint(1000000000, 9999999999)
self._version = None
self._text = ''
self._children = {}
self.timestamps = NodeTimestamps(create_time)