MCPcopy Create free account
hub / github.com/ZeroIntensity/pointers.py / __getattribute__

Method __getattribute__

src/pointers/structure.py:124–156  ·  view source on GitHub ↗
(self, name: str)

Source from the content-addressed store, hash-verified

122
123 @handle
124 def __getattribute__(self, name: str):
125 attr = super().__getattribute__(name)
126
127 with suppress(AttributeError):
128 hints = super().__getattribute__("_hints")
129
130 if (name in hints) and (type(attr)) is bytes:
131 attr = attempt_decode(attr)
132
133 if isinstance(attr, ctypes._Pointer): # type: ignore
134 value = attr.contents
135 ct = type(value)
136
137 if ct is ctypes.c_void_p:
138 add_ref(ct)
139 return VoidPointer(
140 ctypes.addressof(value),
141 ctypes.sizeof(value),
142 )
143
144 py_type = get_py(ct)
145 return TypedCPointer(
146 ctypes.addressof(value),
147 py_type,
148 ctypes.sizeof(value),
149 False,
150 )
151
152 if name in super().__getattribute__("_void_p"):
153 ct = ctypes.c_void_p(attr) # type: ignore
154 return VoidPointer(attr, ctypes.sizeof(ct)) # type: ignore
155
156 return attr
157
158 def __setattr__(self, name: str, value: Any):
159 if hasattr(self, "_struct"):

Callers

nothing calls this directly

Calls 5

attempt_decodeFunction · 0.85
add_refFunction · 0.85
VoidPointerClass · 0.85
get_pyFunction · 0.85
TypedCPointerClass · 0.85

Tested by

no test coverage detected