在扭曲Python從傳輸讀取,數據被寫入到一個協議的傳輸,但通過覆蓋dataReceived方法接收。是否有從交通工具讀書的模式?使用inlineCallbacks
模式在扭曲的Python
例如執行狀態時,這將是有益的:
class SomeProtocol(Protocol):
@defer.inlineCallbacks
def login(self):
self.transport.write('login')
resp = yield self.transport.read(5, timeout=1) # this doesn't exist
if resp != 'user:':
raise SomeException()
self.transport.write('admin')
resp = transport.read(9, timeout=1)
if resp != 'password:':
raise SomeException()
self.transport.write('hunter2')
# ... etc