本文整理汇总了Python中twisted.internet.protocol.Protocol.makeConnection方法的典型用法代码示例。如果您正苦于以下问题:Python Protocol.makeConnection方法的具体用法?Python Protocol.makeConnection怎么用?Python Protocol.makeConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.protocol.Protocol
的用法示例。
在下文中一共展示了Protocol.makeConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeConnection
# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import makeConnection [as 别名]
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()
示例2: makeConnection
# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import makeConnection [as 别名]
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: build_protocol
# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import makeConnection [as 别名]
def build_protocol():
"""
:return: ``Protocol`` hooked up to transport.
"""
p = Protocol()
p.makeConnection(StringTransport())
return p
示例4: makeConnection
# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import makeConnection [as 别名]
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()
示例5: makeConnection
# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import makeConnection [as 别名]
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)
示例6: makeConnection
# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import makeConnection [as 别名]
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()
示例7: makeConnection
# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import makeConnection [as 别名]
def makeConnection(self, transport):
directlyProvides(self, providedBy(transport))
Protocol.makeConnection(self, transport)
if self.wrappedProtocol:
self.prepConnection()
self.wrappedProtocol.makeConnection(self)
else:
self.failConnect()
示例8: makeConnection
# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import makeConnection [as 别名]
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)
示例9: makeConnection
# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import makeConnection [as 别名]
def makeConnection(self, transport):
"""
When a connection is made, register this wrapper with its factory,
save the real transport, and connect the wrapped protocol to this
L{ProtocolWrapper} to intercept any transport calls it makes.
"""
directlyProvides(self, providedBy(transport))
Protocol.makeConnection(self, transport)
self.factory.registerProtocol(self)
self.wrappedProtocol.makeConnection(self)
示例10: makeConnection
# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import makeConnection [as 别名]
def makeConnection(self, transport):
"""
Connects the factory to us and us to the underlying transport.
L{CompressingProtocol.makeConnection}() can't be used because it calls
makeConnection on the wrapped protocol, which causes a second full
initialization, while the stream just needs a reset (done by
L{CompressInitiatingInitializer}).
"""
directlyProvides(self, providedBy(transport))
Protocol.makeConnection(self, transport)
self.factory.registerProtocol(self)
self.wrappedProtocol.transport = self
transport.protocol = self
示例11: makeConnection
# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import makeConnection [as 别名]
def makeConnection(self, transport):
self.attachTransport(transport, self.wrapper)
self.can_timeout = True
self.setTimeout(self.factory.rawserver.config.get('socket_timeout', 30))
return Protocol.makeConnection(self, transport)
示例12: makeConnection
# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import makeConnection [as 别名]
def makeConnection(self, transport):
directlyProvides(self, providedBy(transport))
Protocol.makeConnection(self, transport)
self.factory.registerProtocol(self)
# We implement only Anonymous access
self.transport.write(struct.pack("!BB", 5, len(b"\x00")) + b"\x00")
self.transport.write(struct.pack("!BBBBB", 5, 1, 0, 3, len(self._host)) + self._host + struct.pack("!H", self._port))
self.wrappedProtocol.makeConnection(self)
try:
self._connectedDeferred.callback(self.wrappedProtocol)
except Exception:
pass
self.state = 1
示例13: makeConnection
# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import makeConnection [as 别名]
def makeConnection(self, transport):
"""
When a connection is made, register this wrapper with its factory,
save the real transport, and connect the wrapped protocol to this
L{ProtocolWrapper} to intercept any transport calls it makes.
"""
directlyProvides(self, providedBy(transport))
Protocol.makeConnection(self, transport)
self.factory.registerProtocol(self)
# We implement only Anonymous access
self.transport.write(struct.pack("!BB", 5, len("\x00")) + "\x00")
if self._optimistic:
self.transport.write(struct.pack("!BBBBB", 5, 1, 0, 3, len(self._host)) + self._host + struct.pack("!H", self._port))
self.wrappedProtocol.makeConnection(self)
try:
self._connectedDeferred.callback(self.wrappedProtocol)
except Exception:
pass
self.state += 1
示例14: makeConnection
# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import makeConnection [as 别名]
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.
# The connection might already be aborted (eg. by a callback during
# connection setup), so don't even bother trying to handshake in that
# case.
if not self._aborted:
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()
示例15: makeConnection
# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import makeConnection [as 别名]
def makeConnection(self, transport):
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)