📄 component-example.py
字号:
from twisted.python.components import getAdapter, registerAdapter, Interfaceclass IA(Interface): # Define an interface that implements def a(self): # a sample method method, "a". "A sample method."class A: # define an adapter class __implements__ = IA # that implements our IA interface def __init__(self, original): # keep track of the object being wrapped self.original = original def a(self): # define the method required by our print 'a', # interface, and have it print 'a' self.original.b() # then call back to the object we're adaptingclass B: # the hapless B class doesn't know anything def b(self): # about its adapter, and it defines one print 'b' # method which displays 'b'registerAdapter(A, B, IA) # register A to adapt B for interface IAadapter = getAdapter(B(), IA, None) # adapt a new B instance with an A instanceadapter.a() # call the method defined by interface IA
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -