-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathnode.py
More file actions
48 lines (38 loc) · 1.21 KB
/
node.py
File metadata and controls
48 lines (38 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from .util import quote_string
class Node:
"""
A node within the garph.
"""
def __init__(self, node_id=None, alias=None, label=None, properties=None):
"""
Create a new node
"""
self.id = node_id
self.alias = alias
self.label = label
self.properties = properties or {}
def toString(self):
res = ''
if self.properties:
props = ','.join(
f'{key}:{quote_string(val)}'
for key, val in sorted(self.properties.items()))
res = f'{{{props}}}'
return res
def __str__(self):
label = f':{self.label}' if label else ''
return f'({self.alias or ""}{label} {self.toString()})'
def __eq__(self, rhs):
# Quick positive check, if both IDs are set.
if self.id and self.id == rhs.id:
return True
# Label should match.
if self.label != rhs.label:
return False
# Quick check for number of properties.
if len(self.properties) != len(rhs.properties):
return False
# Compare properties.
if self.properties != rhs.properties:
return False
return True