1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 from cproton import *
20
22
25
28
30 raise TypeError("does not support item assignment")
31
32 EMPTY_ATTRS = EmptyAttrs()
33
35
36 - def __init__(self, impl_or_constructor, get_context=None):
37 init = False
38 if callable(impl_or_constructor):
39
40 impl = impl_or_constructor()
41 if impl is None:
42 self.__dict__["_impl"] = impl
43 self.__dict__["_attrs"] = EMPTY_ATTRS
44 self.__dict__["_record"] = None
45 from proton import ProtonException
46 raise ProtonException("Wrapper failed to create wrapped object. Check for file descriptor or memory exhaustion.")
47 init = True
48 else:
49
50 impl = impl_or_constructor
51 pn_incref(impl)
52
53 if get_context:
54 record = get_context(impl)
55 attrs = pn_void2py(pn_record_get(record, PYCTX))
56 if attrs is None:
57 attrs = {}
58 pn_record_def(record, PYCTX, PN_PYREF)
59 pn_record_set(record, PYCTX, pn_py2void(attrs))
60 init = True
61 else:
62 attrs = EMPTY_ATTRS
63 init = False
64 record = None
65 self.__dict__["_impl"] = impl
66 self.__dict__["_attrs"] = attrs
67 self.__dict__["_record"] = record
68 if init: self._init()
69
71 attrs = self.__dict__["_attrs"]
72 if name in attrs:
73 return attrs[name]
74 else:
75 raise AttributeError(name + " not in _attrs")
76
78 if hasattr(self.__class__, name):
79 object.__setattr__(self, name, value)
80 else:
81 attrs = self.__dict__["_attrs"]
82 attrs[name] = value
83
85 attrs = self.__dict__["_attrs"]
86 if attrs:
87 del attrs[name]
88
90 return hash(addressof(self._impl))
91
93 if isinstance(other, Wrapper):
94 return addressof(self._impl) == addressof(other._impl)
95 return False
96
98 if isinstance(other, Wrapper):
99 return addressof(self._impl) != addressof(other._impl)
100 return True
101
103 pn_decref(self._impl)
104
106 return '<%s.%s 0x%x ~ 0x%x>' % (self.__class__.__module__,
107 self.__class__.__name__,
108 id(self), addressof(self._impl))
109
110
111 PYCTX = int(pn_py2void(Wrapper))
112 addressof = int
113