Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
a, b = generate_save_load(lambda: node.Node(type_=node.NodeType.Note))
self.assertEqual(a, b)
notes = self._keep.all()
if len(self._labels) > 0:
notes = list(
filter(lambda n: set(self._labels).intersection(set(map(lambda l: str(l), n.labels.all()))), notes))
if len(self._titles) > 0:
notes = list(filter(lambda n: str(n.title) in self._titles, notes))
self._notes = []
for note in notes:
note_type = note.type
title = str(note.title)
lines = list(map(lambda n: str(n), note.text.split("\n")))
color = note.color.name
checked = []
unchecked = []
children = []
if note_type == NodeType.List:
checked = list(map(lambda n: str(n), note.checked))
unchecked = list(map(lambda n: str(n), note.unchecked))
children = list(
map(lambda c: GoogleKeepSensor.map_node(c), filter(lambda c: not c.indented, note.items)))
parsed_note = GoogleKeepSensor.make_note(str(note_type), title, lines, children, checked, unchecked, color)
self._notes.append(parsed_note)
@merged.setter
def merged(self, value):
self._merged = value
self.touch()
@property
def dirty(self):
return super(Label, self).dirty or self.timestamps.dirty
def __str__(self):
return self.name
_type_map = {
NodeType.Note: Note,
NodeType.List: List,
NodeType.ListItem: ListItem,
NodeType.Blob: Blob,
}
def from_json(raw):
"""Helper to construct a node from a dict.
Args:
raw (dict): Raw node representation.
Returns:
Node: A Node object or None.
"""
ncls = None
_type = raw.get('type')
try:
def _load(self, raw):
super(Node, self)._load(raw)
# Verify this is a valid type
NodeType(raw['type'])
if raw['kind'] not in ['notes#node']:
logger.warning('Unknown node kind: %s', raw['kind'])
if 'mergeConflict' in raw:
raise exception.MergeException(raw)
self.id = raw['id']
self.server_id = raw['serverId'] if 'serverId' in raw else self.server_id
self.parent_id = raw['parentId']
self._sort = raw['sortValue'] if 'sortValue' in raw else self.sort
self._version = raw['baseVersion'] if 'baseVersion' in raw else self._version
self._text = raw['text'] if 'text' in raw else self._text
self.timestamps.load(raw['timestamps'])
self.settings.load(raw['nodeSettings'])
self.annotations.load(raw['annotationsGroup'])
@property
def dirty(self):
return super(TopLevelNode, self).dirty or self.labels.dirty or self.collaborators.dirty
@property
def blobs(self):
"""Get all media blobs.
Returns:
list[gkeepapi.node.Blob]: Media blobs.
"""
return [node for node in self.children if isinstance(node, Blob)]
class Note(TopLevelNode):
"""Represents a Google Keep note."""
_TYPE = NodeType.Note
def __init__(self, **kwargs):
super(Note, self).__init__(type_=self._TYPE, **kwargs)
def _get_text_node(self):
node = None
for child_node in self.children:
if isinstance(child_node, ListItem):
node = child_node
break
return node
@property
def text(self):
node = self._get_text_node()
def __init__(self, parent_id=None, parent_server_id=None, super_list_item_id=None, **kwargs):
super(ListItem, self).__init__(type_=NodeType.ListItem, parent_id=parent_id, **kwargs)
self.parent_item = None
self.parent_server_id = parent_server_id
self.super_list_item_id = super_list_item_id
self.prev_super_list_item_id = None
self._subitems = {}
self._checked = False
def merged(self, value):
self._merged = value
self.touch()
@property
def dirty(self):
return super(Label, self).dirty or self.timestamps.dirty
def __str__(self):
return self.name
_type_map = {
NodeType.Note: Note,
NodeType.List: List,
NodeType.ListItem: ListItem,
NodeType.Blob: Blob,
}
def from_json(raw):
"""Helper to construct a node from a dict.
Args:
raw (dict): Raw node representation.
Returns:
Node: A Node object or None.
"""
ncls = None
_type = raw.get('type')
try:
ncls = _type_map[NodeType(_type)]
except (KeyError, ValueError) as e:
def from_json(raw):
"""Helper to construct a node from a dict.
Args:
raw (dict): Raw node representation.
Returns:
Node: A Node object or None.
"""
ncls = None
_type = raw.get('type')
try:
ncls = _type_map[NodeType(_type)]
except (KeyError, ValueError) as e:
logger.warning('Unknown node type: %s', _type)
if DEBUG:
raise_from(exception.ParseException('Parse error for %s' % (_type), raw), e)
return None
node = ncls()
node.load(raw)
return node