forked from nyaoouo/FFxivPythonTrigger2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttrContainer.py
More file actions
37 lines (26 loc) · 899 Bytes
/
Copy pathAttrContainer.py
File metadata and controls
37 lines (26 loc) · 899 Bytes
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
class AttributeExistsException(Exception):
def __init__(self, name):
self.name = name
def __str__(self):
return "Attribute '%s' already exists" % self.name
class AttributeNotFoundException(Exception):
def __init__(self, name):
self.name = name
def __str__(self):
return "Attribute '%s' not found" % self.name
class AttrContainer(object):
def __init__(self):
self.attrs=dict()
def register(self, name, obj):
if name in self.attrs :
raise AttributeExistsException(name)
self.attrs[name] = obj
def unregister(self, name):
if name in self.attrs:
del self.attrs[name]
def __getitem__(self, name):
if name not in self.attrs:
raise AttributeNotFoundException(name)
return self.attrs[name]
def __getattr__(self,name):
return self[name]