/usr/lib/python3/dist-packages/twisted/python/__pycache__
Edit: /usr/lib/python3/dist-packages/twisted/python/__pycache__/components.cpython-310.pyc (14364B)
o
bw7 @ s d Z ddlmZ ddlmZ ddlmZmZ ddlm Z ddl
mZ e Zda
dd Zd d
Zdd Zd
d Zee dd ZeZG dd dZG dd dZG dd deZd ddZG dd dZG dd dZg dZdS )!a
Component architecture for Twisted, based on Zope3 components.
Using the Zope3 API directly is strongly recommended. Everything
you need is in the top-level of the zope.interface package, e.g.::
from zope.interface import Interface, implementer
class IFoo(Interface):
pass
@implementer(IFoo)
class Foo:
pass
print(IFoo.implementedBy(Foo)) # True
print(IFoo.providedBy(Foo())) # True
L{twisted.python.components.registerAdapter} from this module may be used to
add to Twisted's global adapter registry.
L{twisted.python.components.proxyForInterface} is a factory for classes
which allow access to only the parts of another class defined by a specified
interface.
)StringIO)Dict)declarations interface)AdapterRegistry)reflectc G sz t }|sJ dt|tjst|}|D ]}||g|}|dur,ts,td| dq|D ]}| |g|d| q/dS )a
Register an adapter class.
An adapter class is expected to implement the given interface, by
adapting instances implementing 'origInterface'. An adapter class's
__init__ method should accept one parameter, an instance implementing
'origInterface'.
zYou need to pass an InterfaceNzan adapter (z) was already registered. )
globalRegistry
isinstancer InterfaceClassr
implementedBy
registeredALLOW_DUPLICATES
ValueErrorregister)adapterFactory
origInterfaceinterfaceClassesselfinterfaceClassfactory r ;/usr/lib/python3/dist-packages/twisted/python/components.pyregisterAdapter2 s
r c C s6 t }t| tjs
t| } || |}|du r|}|S )zReturn registered adapter for a given class and interface.
Note that is tied to the *Twisted* global registry, and will
thus not find adapters registered elsewhere.
N)r r
r r r r lookup1)
fromInterfacetoInterfacedefaultr r r r r getAdapterFactoryJ s
r c s" | j fdd}tj| |S )z
Add an adapter hook which will attempt to look up adapters in the given
registry.
@type registry: L{zope.interface.adapter.AdapterRegistry}
@return: The hook which was added, for later use with L{_removeHook}.
c s$ t || }|d u rd S ||S N)r
providedBy)ifaceobr lookupr r _hookd s z_addHook.
._hook)r r
adapter_hooksappend)registryr% r r# r _addHookY s r) c C s t j| dS )z
Remove a previously added adapter hook.
@param hook: An object previously returned by a call to L{_addHook}. This
will be removed from the list of adapter hooks.
N)r r&