本文整理汇总了Python中twisted.internet.protocol.Protocol类的典型用法代码示例。如果您正苦于以下问题:Python Protocol类的具体用法?Python Protocol怎么用?Python Protocol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Protocol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeConnection
def makeConnection(self, transport):
if isinstance(self.factory, OutgoingConnectionFactory):
self.factory.rawserver._remove_pending_connection(self.factory.addr)
self.can_timeout = 1
self.setTimeout(self.factory.rawserver.config['socket_timeout'])
self.attachTransport(transport, self.factory.connection, *self.factory.connection_args)
Protocol.makeConnection(self, transport)
示例2: makeConnection
def makeConnection(self, transport):
directlyProvides(self, providedBy(transport))
Protocol.makeConnection(self, transport)
self.transport.write("o")
self.factory.registerProtocol(self)
self.wrappedProtocol.makeConnection(self)
self.heartbeat_timer = reactor.callLater(self.parent._options['heartbeat'], self.heartbeat)
示例3: __init__
def __init__(self):
try:
Protocol.__init__(self)
except AttributeError:
pass
self.buffer = ""
self.drd = Deferred()
示例4: makeConnection
def makeConnection(self, transport):
"""
Connect this wrapper to the given transport and initialize the
necessary L{OpenSSL.SSL.Connection} with a memory BIO.
"""
tlsContext = self.factory._contextFactory.getContext()
self._tlsConnection = Connection(tlsContext, None)
if self.factory._isClient:
self._tlsConnection.set_connect_state()
else:
self._tlsConnection.set_accept_state()
self._appSendBuffer = []
# Intentionally skip ProtocolWrapper.makeConnection - it might call
# wrappedProtocol.makeConnection, which we want to make conditional.
Protocol.makeConnection(self, transport)
self.factory.registerProtocol(self)
if self._connectWrapped:
# Now that the TLS layer is initialized, notify the application of
# the connection.
ProtocolWrapper.makeConnection(self, transport)
# Now that we ourselves have a transport (initialized by the
# ProtocolWrapper.makeConnection call above), kick off the TLS
# handshake.
try:
self._tlsConnection.do_handshake()
except WantReadError:
# This is the expected case - there's no data in the connection's
# input buffer yet, so it won't be able to complete the whole
# handshake now. If this is the speak-first side of the
# connection, then some bytes will be in the send buffer now; flush
# them.
self._flushSendBIO()
示例5: __init__
def __init__(self):
Protocol.__init__(self)
self.packetBuffer = ''
self.packetSize = 0
self.errorMsg = ''
self.errorId = 0
self.msgMap = {}
示例6: connectionMade
def connectionMade(self):
"""
overload Protocol.connectionMade to verify that we have a connection
"""
log.msg("ResponseProducerProtocol connectionMade",
logLevel=logging.DEBUG)
Protocol.connectionMade(self)
示例7: connectionLost
def connectionLost(self, reason):
Protocol.connectionLost(self, reason)
self.started = False
self.factory.number_of_connections -= 1
self.player = None
print "lost"
print "Current number of connections:", self.factory.number_of_connections
示例8: makeConnection
def makeConnection(self, transport):
"""
Connect this wrapper to the given transport and initialize the
necessary L{OpenSSL.SSL.Connection} with a memory BIO.
"""
self._tlsConnection = self.factory._createConnection(self)
self._appSendBuffer = []
# Add interfaces provided by the transport we are wrapping:
for interface in providedBy(transport):
directlyProvides(self, interface)
# Intentionally skip ProtocolWrapper.makeConnection - it might call
# wrappedProtocol.makeConnection, which we want to make conditional.
Protocol.makeConnection(self, transport)
self.factory.registerProtocol(self)
if self._connectWrapped:
# Now that the TLS layer is initialized, notify the application of
# the connection.
ProtocolWrapper.makeConnection(self, transport)
# Now that we ourselves have a transport (initialized by the
# ProtocolWrapper.makeConnection call above), kick off the TLS
# handshake.
self._checkHandshakeStatus()
示例9: build_protocol
def build_protocol():
"""
:return: ``Protocol`` hooked up to transport.
"""
p = Protocol()
p.makeConnection(StringTransport())
return p
示例10: makeConnection
def makeConnection(self, transport):
directlyProvides(self, providedBy(transport))
Protocol.makeConnection(self, transport)
if not self.method in self.allowedMethods:
self.sendHeaders({'status': '405 Method Not Supported','allow': ', '.join(self.allowedMethods)})
self.transport.write("\r\n")
self.transport.loseConnection()
return
elif self.method == 'OPTIONS':
self.sendHeaders()
self.transport.write("")
self.transport.loseConnection()
return
if not self.writeOnly:
if self.session in self.factory.sessions:
self.wrappedProtocol = self.factory.sessions[self.session]
else:
self.wrappedProtocol = RelayProtocol(self.factory, self.factory.wrappedFactory.buildProtocol(self.transport.addr), self.session, self)
if self.wrappedProtocol.attached:
self.wrappedProtocol = None
self.failConnect()
else:
if not self.prepConnection():
self.disconnecting = False
self.wrappedProtocol.makeConnection(self)
else:
if self.session in self.factory.sessions:
self.wrappedProtocol = self.factory.sessions[self.session]
else:
self.sendHeaders({'status': '404 Not Found'})
self.transport.write("\r\n")
self.transport.loseConnection()
示例11: connectionMade
def connectionMade(self):
Protocol.connectionMade(self)
self.transport.setTcpNoDelay(True)
self.buffer = ''
self.nbytes = 0
# XXX send version message
self._handler = self._handle_version, 12
示例12: makeConnection
def makeConnection(self, transport):
directlyProvides(self, providedBy(transport))
Protocol.makeConnection(self, transport)
if self.wrappedProtocol:
self.prepConnection()
self.wrappedProtocol.makeConnection(self)
else:
self.failConnect()
示例13: makeConnection
def makeConnection(self, transport):
"""
overload Protocol.makeConnection in order to get a reference to the
transport
"""
log.msg("ResponseProducerProtocol makeConnection",
logLevel=logging.DEBUG)
Protocol.makeConnection(self, transport)
示例14: connectionMade
def connectionMade(self):
AbstractWind.connectionMade(self)
Protocol.connectionMade(self)
_ = self.transport.getPeer()
_ = (_.host, _.port)
self.peer, self.port = _
示例15: reconnector
def reconnector(self, onion):
protocol = Protocol()
protocol.onion = onion
protocol.connectionLost = lambda failure: self.handleLostConnection(failure, onion)
tor_endpoint = clientFromString(self.reactor, "tor:%s.onion:8060" % onion)
self.onion_pending_map[onion] = connectProtocol(tor_endpoint, protocol)
self.onion_pending_map[onion].addCallback(lambda protocol: self.connection_ready(onion, protocol))
self.onion_pending_map[onion].addErrback(lambda failure: self.connectFail(failure, onion))