-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
46 lines (34 loc) · 1.12 KB
/
utils.py
File metadata and controls
46 lines (34 loc) · 1.12 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
import SSS
class Note:
def __init__(self, text="", name="", subnotes=None, father=None):
if subnotes is None:
subnotes = []
subnotes: list[Note]
self.text = text
self.name = name
self.subnotes = subnotes
self.father = father
def addchild(self, *args, **kwargs):
self.subnotes.append(Note(*args, father=self, **kwargs))
tag_text = "text".encode("UTF-8")
tag_name = "name".encode("UTF-8")
def getroot(note: Note):
if note.father is None:
return note
getroot(note.father)
def note_to_sss(note: Note):
SSSObj = SSS.SSSObject()
SSSObj.named_fields[tag_text] = note.text.encode("UTF-8")
SSSObj.named_fields[tag_name] = note.name.encode("UTF-8")
for sub in note.subnotes:
SSSObj.fields.append(note_to_sss(sub))
return SSSObj
def sss_to_note(sssobj: SSS.SSSObject, father=None):
n = sssobj.named_fields
note = Note(
name=n[tag_name].decode("UTF-8"),
text=n[tag_text].decode("UTF-8"),
father=father
)
note.subnotes = [sss_to_note(sub, note) for sub in sssobj.fields]
return note