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 from proton import ProtonException
43 raise ProtonException("Wrapper failed to create wrapped object. Check for file descriptor or memory exhaustion.")
44 init = True
45 else:
46
47 impl = impl_or_constructor
48 pn_incref(impl)
49
50 if get_context:
51 record = get_context(impl)
52 attrs = pn_void2py(pn_record_get(record, PYCTX))
53 if attrs is None:
54 attrs = {}
55 pn_record_def(record, PYCTX, PN_PYREF)
56 pn_record_set(record, PYCTX, pn_py2void(attrs))
57 init = True
58 else:
59 attrs = EMPTY_ATTRS
60 init = False
61 record = None
62 self.__dict__["_impl"] = impl
63 self.__dict__["_attrs"] = attrs
64 self.__dict__["_record"] = record
65 if init: self._init()
66
68 attrs = self.__dict__["_attrs"]
69 if name in attrs:
70 return attrs[name]
71 else:
72 raise AttributeError(name + " not in _attrs")
73
75 if hasattr(self.__class__, name):
76 object.__setattr__(self, name, value)
77 else:
78 attrs = self.__dict__["_attrs"]
79 attrs[name] = value
80
82 attrs = self.__dict__["_attrs"]
83 if attrs:
84 del attrs[name]
85
87 return hash(addressof(self._impl))
88
90 if isinstance(other, Wrapper):
91 return addressof(self._impl) == addressof(other._impl)
92 return False
93
95 if isinstance(other, Wrapper):
96 return addressof(self._impl) != addressof(other._impl)
97 return True
98
100 pn_decref(self._impl)
101
103 return '<%s.%s 0x%x ~ 0x%x>' % (self.__class__.__module__,
104 self.__class__.__name__,
105 id(self), addressof(self._impl))
106
107
108 if pn_py2void(Wrapper) is Wrapper:
109 PYCTX = Wrapper
110 import java.lang.System
111 addressof = java.lang.System.identityHashCode
112 else:
113 PYCTX = int(pn_py2void(Wrapper))
114 addressof = int
115