MCPcopy Create free account
hub / github.com/twisted/twisted / getComponent

Method getComponent

src/twisted/python/components.py:258–287  ·  view source on GitHub ↗

Create or retrieve an adapter for the given interface. If such an adapter has already been created, retrieve it from the cache that this instance keeps of all its adapters. Adapters created through this mechanism may safely store system-specific state. If you want

(self, interface, default=None)

Source from the content-addressed store, hash-verified

256 return l
257
258 def getComponent(self, interface, default=None):
259 """Create or retrieve an adapter for the given interface.
260
261 If such an adapter has already been created, retrieve it from the cache
262 that this instance keeps of all its adapters. Adapters created through
263 this mechanism may safely store system-specific state.
264
265 If you want to register an adapter that will be created through
266 getComponent, but you don't require (or don't want) your adapter to be
267 cached and kept alive for the lifetime of this Componentized object,
268 set the attribute 'temporaryAdapter' to True on your adapter class.
269
270 If you want to automatically register an adapter for all appropriate
271 interfaces (with addComponent), set the attribute 'multiComponent' to
272 True on your adapter class.
273 """
274 k = reflect.qual(interface)
275 if k in self._adapterCache:
276 return self._adapterCache[k]
277 else:
278 adapter = interface.__adapt__(self)
279 if adapter is not None and not (
280 hasattr(adapter, "temporaryAdapter") and adapter.temporaryAdapter
281 ):
282 self._adapterCache[k] = adapter
283 if hasattr(adapter, "multiComponent") and adapter.multiComponent:
284 self.addComponent(adapter)
285 if adapter is None:
286 return default
287 return adapter
288
289 def __conform__(self, interface):
290 return self.getComponent(interface)

Callers 12

__conform__Method · 0.95
test_setAdapterMethod · 0.95
test_addAdapterMethod · 0.95
test_setComponentMethod · 0.95
test_unsetComponentMethod · 0.95
testComponentizedMethod · 0.80
testMultiAdapterMethod · 0.80
startMethod · 0.80
getSessionMethod · 0.80

Calls 1

addComponentMethod · 0.95

Tested by 9

test_setAdapterMethod · 0.76
test_addAdapterMethod · 0.76
test_setComponentMethod · 0.76
test_unsetComponentMethod · 0.76
testComponentizedMethod · 0.64
testMultiAdapterMethod · 0.64