-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathobjects.py
More file actions
42 lines (32 loc) · 1.03 KB
/
objects.py
File metadata and controls
42 lines (32 loc) · 1.03 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
"""
botogram.shared.objects
Underlying objects for the shared memory
Copyright (C) 2015 Pietro Albini <pietro@pietroalbini.io>
Released under the MIT license
"""
_None = object()
class SharedObject:
"""A shared object"""
def __init__(self, id, type, value=_None, standalone=False):
self.id = id
self.type = type
self.standalone = standalone
self.children = set()
self.parents = set()
if type == "dict":
self.content = dict()
elif type == "lock":
self.content = False
else:
raise TypeError("Unsupported type: %s" % type)
def add_child(self, object):
"""Add a child object"""
# Add a dual link between objects
self.children.add(object)
object.parents.add(self)
def remove_child(self, object):
"""Remove a child object"""
if object in self.children:
# Remove the dual link
self.children.remove(object)
object.parents.remove(self)