本文整理汇总了Python中twisted.internet.protocol.Factory.buildProtocol方法的典型用法代码示例。如果您正苦于以下问题:Python Factory.buildProtocol方法的具体用法?Python Factory.buildProtocol怎么用?Python Factory.buildProtocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.protocol.Factory
的用法示例。
在下文中一共展示了Factory.buildProtocol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def buildProtocol(self, addr):
if self.accept_list != None and addr.host not in self.accept_list:
return None
p = Factory.buildProtocol(self, addr)
p.command_cb = self.command_cb
p.raddr = addr
return p
示例2: buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def buildProtocol(self, addr):
"""
Builds the protocol
"""
p = Factory.buildProtocol(self, addr)
p.hub = self.hub
return p
示例3: test_connectionCancelledBeforeSecure
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def test_connectionCancelledBeforeSecure(self):
"""
If the connection is cancelled before the SSH transport layer has
finished key exchange (ie, gotten to the point where we may attempt to
authenticate), the L{Deferred} returned by
L{SSHCommandClientEndpoint.connect} fires with a L{Failure} wrapping
L{CancelledError} and the connection is aborted.
"""
endpoint = SSHCommandClientEndpoint.newConnection(
self.reactor, b"/bin/ls -l", b"dummy user",
self.hostname, self.port, knownHosts=self.knownHosts,
ui=FixedResponseUI(False))
factory = Factory()
factory.protocol = Protocol
d = endpoint.connect(factory)
transport = AbortableFakeTransport(None, isServer=False)
factory = self.reactor.tcpClients[0][2]
client = factory.buildProtocol(None)
client.makeConnection(transport)
d.cancel()
self.failureResultOf(d).trap(CancelledError)
self.assertTrue(transport.aborted)
# Make sure the connection closing doesn't result in unexpected
# behavior when due to cancellation:
client.connectionLost(Failure(ConnectionDone()))
示例4: buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def buildProtocol(self, addr):
p = Factory.buildProtocol(self, addr)
p.player = {}
p.player_uuid = self.player_uuid
p.username = self.username
return p
示例5: buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def buildProtocol(self, addr):
if self.dead:
return None
ip = addr.host
connections = self.peerConnections.get(ip, 0)
maxConnections = self.servconfig["client_peer_exempt"][ip] if ip in self.servconfig["client_peer_exempt"] else self.servconfig["client_peer_connections"]
if maxConnections and connections >= maxConnections:
log.msg("A client at IP address {} has exceeded the session limit".format(ip))
return None
self.peerConnections[ip] = connections + 1
return Factory.buildProtocol(self, addr)
示例6: start
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def start(self):
"""
Start the socks5 server by listening on the specified TCP ports.
"""
def build_protocol(_):
socks5connection = Socks5Connection(self)
self.sessions.append(socks5connection)
return socks5connection
factory = Factory()
factory.buildProtocol = build_protocol
self.twisted_port = reactor.listenTCP(self.port, factory)
示例7: test_defaultBuildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def test_defaultBuildProtocol(self):
"""
L{Factory.buildProtocol} by default constructs a protocol by calling
its C{protocol} attribute, and attaches the factory to the result.
"""
class SomeProtocol(Protocol):
pass
f = Factory()
f.protocol = SomeProtocol
protocol = f.buildProtocol(None)
self.assertIsInstance(protocol, SomeProtocol)
self.assertIdentical(protocol.factory, f)
示例8: buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def buildProtocol(self, addr):
proto = Factory.buildProtocol(self, addr)
for prev_proto in self.already_proto:
assert isinstance(prev_proto.locator, CoordinatorLocatorDecorator), 'Каждый локатор должен быть ' \
'декорирован для задания своего ' \
'списка incoming_connections'
assert prev_proto.locator.decorated_locator is self.coordinator_locator, 'координирующий ' \
'локатор должен быть один'
prev_proto.locator.add_incoming_connection(proto)
proto.locator.add_incoming_connection(prev_proto)
# add for the next protos
self.already_proto.append(proto)
return proto
示例9: buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def buildProtocol(self, addr):
if self.dead:
return None
ip = addr.host
# self.unique_ips.add(ip)
# self.stats_data["total_connections"] = len(self.unique_ips)
# if self.app_ip_log:
# with open(self.app_ip_log,"w") as f:
# f.write(json.dumps(list(self.unique_ips), separators=(',',':')))
conn = self.peerConnections.get(ip, 0)
max = self.client_peer_exempt[ip] if ip in self.client_peer_exempt else self.client_peer_connections
if max and conn >= max:
return None
# self.stats_data["connections"] += 1
self.peerConnections[ip] = conn + 1
return Factory.buildProtocol(self, addr)
示例10: test_connectionClosedBeforeSecure
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def test_connectionClosedBeforeSecure(self):
"""
If the connection closes at any point before the SSH transport layer
has finished key exchange (ie, gotten to the point where we may attempt
to authenticate), the L{Deferred} returned by
L{SSHCommandClientEndpoint.connect} fires with a L{Failure} wrapping
the reason for the lost connection.
"""
endpoint = SSHCommandClientEndpoint.newConnection(
self.reactor, b"/bin/ls -l", b"dummy user",
self.hostname, self.port, knownHosts=self.knownHosts,
ui=FixedResponseUI(False))
factory = Factory()
factory.protocol = Protocol
d = endpoint.connect(factory)
transport = StringTransport()
factory = self.reactor.tcpClients[0][2]
client = factory.buildProtocol(None)
client.makeConnection(transport)
client.connectionLost(Failure(ConnectionDone()))
self.failureResultOf(d).trap(ConnectionDone)
示例11: buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def buildProtocol(self, addr):
if addr.host not in self.only_ip and "0.0.0.0" not in self.only_ip:
return
return Factory.buildProtocol(self, addr)
示例12: buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def buildProtocol(self, addr):
self.resetDelay() # Reset the delay
self.p = Factory.buildProtocol(self, addr)
return self.p
示例13: buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def buildProtocol(self, addr):
prot = Factory.buildProtocol(self, addr)
self.protocols.append(prot)
return prot
示例14: buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def buildProtocol(self, addr):
p = Factory.buildProtocol(self, addr)
p.control_session = self.control_session
return p
示例15: buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def buildProtocol(self, addr):
log.msg("Client connected from:", (addr,))
protocol = Factory.buildProtocol(self, addr)
protocol.register(self.map)
protocol.addr = addr
return protocol