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