update & fix

This commit is contained in:
bkfox
2023-06-22 02:08:52 +02:00
parent 93e57d746c
commit a289e1ef05
6 changed files with 23 additions and 117 deletions

View File

@ -86,7 +86,7 @@ class WrapperMixin:
ns_target = getattr(ns, ns_attr, None)
if self.target is ns_target:
return
elif self.target is not None:
elif self.target is not None and self.ns:
raise RuntimeError(
"self target already injected. It must be "
"`release` before `inject`."
@ -97,12 +97,14 @@ class WrapperMixin:
self.ns = ns
self.ns_attr = ns_attr
return self
def release(self):
"""Remove injection from previously injected parent, reset target."""
if self.ns_target is self.interface:
setattr(self.ns, self.ns_attr, self.target)
self.target = None
return self
class SpoofMixin:
@ -190,6 +192,16 @@ class Interface:
self.interface = interface
super().__init__(**kwargs)
def clone(self, **kwargs):
"""Return an Interface copying some values from self."""
kwargs.update(
{
"target": self.target,
"funcs": self.funcs,
}
)
return type(self.interface)(_imeta_kw=kwargs)._imeta
def __getitem__(self, name):
return self.traces[name]