本文整理汇总了Python中twisted.internet.protocol.ClientCreator.connectSSL方法的典型用法代码示例。如果您正苦于以下问题:Python ClientCreator.connectSSL方法的具体用法?Python ClientCreator.connectSSL怎么用?Python ClientCreator.connectSSL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.protocol.ClientCreator
的用法示例。
在下文中一共展示了ClientCreator.connectSSL方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import connectSSL [as 别名]
def run():
# Create the client
FTPClient.debug = 1
creator = ClientCreator(reactor, FTPClient, "admin", '1', passive=1)
creator.connectSSL("localhost", 2121,
ssl.ClientContextFactory()).addCallback(connectionMade).addErrback(connectionFailed)
reactor.run(installSignalHandlers=0)
示例2: dataReceived
# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import connectSSL [as 别名]
def dataReceived(self, data):
# NB: this only receives whole frames; so we will just decode
# data as-is.
# NB: its cometsession.py:TCPConnectionResource that makes sure
# we receive whole frames here.
self.logger.debug('dataReceived: data=%r' % data)
self.logger.debug('self.outgoingConn is', self.outgoingConn)
if self.outgoingConn:
# NB: outgoingConn is-a ProxyOutgoingProtocol
self.logger.debug("write (out): %r" % data)
return self.outgoingConn.transport.write(data)
if self.state == "handshake":
try:
data = data.strip()
urlparse.uses_netloc.append("ssl")
url = urlparse.urlparse(data)
if not url.netloc:
ssl = False
else:
ssl = url.scheme == "ssl"
host, port = url.netloc.split(':')
port = int(port)
self.completedHandshake = True
except:
self.logger.error("failed to connect on handshake", tb=True)
self.transport.write("0" + str(ERRORS['InvalidHandshake']))
self.transport.loseConnection()
return
peer = self.transport.getPeer()
self.fromHost = peer.host
self.fromPort = peer.port
self.toHost = host
self.toPort = port
allowed = False
for source in config.map['[access]'].get((host, port), []):
if source == self.transport.hostHeader or source == '*':
allowed = True
break
if not allowed:
self.logger.warn('Unauthorized connect from %r:%d to %r:%d' % (self.fromHost, self.fromPort, self.toHost, self.toPort))
self.transport.write("0" + str(ERRORS['Unauthorized']))
self.transport.loseConnection()
return
self.logger.access('new connection from %s:%s to %s:%d' % (self.fromHost, self.fromPort, self.toHost, self.toPort))
self.state = 'connecting'
client = ClientCreator(reactor, ProxyOutgoingProtocol, self)
if ssl:
from twisted.internet import ssl
client.connectSSL(host, port, ssl.ClientContextFactory()).addErrback(self.errorConnection)
else:
client.connectTCP(host, port).addErrback(self.errorConnection)
# TODO: connect timeout or onConnectFailed handling...
else:
self.transport.write("0" + str(ERRORS['InvalidHandshake']))
self.state = 'closed'
self.transport.loseConnection()
示例3: writeMetric
# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import connectSSL [as 别名]
def writeMetric(metric_path, value, timestamp, host, port, username, password,
vhost, exchange, spec=None, channel_number=1, ssl=False):
if not spec:
spec = txamqp.spec.load(os.path.normpath(
os.path.join(os.path.dirname(__file__), 'amqp0-8.xml')))
delegate = TwistedDelegate()
connector = ClientCreator(reactor, AMQClient, delegate=delegate,
vhost=vhost, spec=spec)
if ssl:
from twisted.internet.ssl import ClientContextFactory
conn = yield connector.connectSSL(host, port, ClientContextFactory())
else:
conn = yield connector.connectTCP(host, port)
yield conn.authenticate(username, password)
channel = yield conn.channel(channel_number)
yield channel.channel_open()
yield channel.exchange_declare(exchange=exchange, type="topic",
durable=True, auto_delete=False)
message = Content( "%f %d" % (value, timestamp) )
message["delivery mode"] = 2
channel.basic_publish(exchange=exchange, content=message, routing_key=metric_path)
yield channel.channel_close()
示例4: _connect
# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import connectSSL [as 别名]
def _connect(self, scheme, host, port):
"""
Connect to the given host and port, using a transport selected based on
scheme.
@param scheme: A string like C{'http'} or C{'https'} (the only two
supported values) to use to determine how to establish the
connection.
@param host: A C{str} giving the hostname which will be connected to in
order to issue a request.
@param port: An C{int} giving the port number the connection will be on.
@return: A L{Deferred} which fires with a connected instance of
C{self._protocol}.
"""
cc = ClientCreator(self._reactor, self._protocol)
if scheme == "http":
d = cc.connectTCP(host, port)
elif scheme == "https":
d = cc.connectSSL(host, port, self._wrapContextFactory(host, port))
else:
d = defer.fail(SchemeNotSupported("Unsupported scheme: %r" % (scheme,)))
return d
示例5: connect
# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import connectSSL [as 别名]
def connect(self, user, targetserver):
if targetserver not in self.ircd.servconfig["serverlinks"]:
if user:
user.sendMessage(irc.ERR_NOSUCHSERVER, targetserver, ":No link block exists")
return
def sendServerHandshake(protocol, password):
protocol.callRemote(
IntroduceServer,
name=self.ircd.name,
password=password,
description=self.ircd.servconfig["server_description"],
version=protocol_version,
commonmodules=self.ircd.common_modules,
)
protocol.sentDataBurst = False
servinfo = self.ircd.servconfig["serverlinks"][targetserver]
if "ip" not in servinfo or "port" not in servinfo:
return
if "bindaddress" in servinfo and "bindport" in servinfo:
bind = (servinfo["bindaddress"], servinfo["bindport"])
else:
bind = None
creator = ClientCreator(reactor, ServerProtocol, self.ircd)
if "ssl" in servinfo and servinfo["ssl"]:
d = creator.connectSSL(servinfo["ip"], servinfo["port"], self.ircd.ssl_cert, bindAddress=bind)
else:
d = creator.connectTCP(servinfo["ip"], servinfo["port"], bindAddress=bind)
d.addCallback(sendServerHandshake, servinfo["outgoing_password"])
示例6: connect_to_rez
# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import connectSSL [as 别名]
def connect_to_rez(rez_info):
dyno_id = rez_info.get('dyno_id')
cc = ClientCreator(reactor, ProcLiteProtocol)
(cc.connectSSL(rez_info.get('host'),
self.settings['dynohost_rendezvous_port'],
ssl.ClientContextFactory()).
addCallback(buildProtoCallback(dyno_id)))
示例7: connect
# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import connectSSL [as 别名]
def connect(self, host, port):
self._stack_conn = _Connection()
self._stack_conn.attach(self)
c = ClientCreator(reactor, lambda: self._stack_conn)
if self.ssl_options is not None:
yield c.connectSSL(host, port, SSLContextFactory(self.ssl_options))
else:
yield c.connectTCP(host, port)
示例8: createConnection
# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import connectSSL [as 别名]
def createConnection(self, addr, keyId):
if addr is None:
return False
host, port = addr
cc = ClientCreator(reactor, TintProtocol, self)
d = cc.connectSSL(host, port, self.contextFactory)
return d.addCallback(self.saveConnection, keyId)
示例9: connect
# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import connectSSL [as 别名]
def connect(self, host, port, scheme='http'):
self.host = host
self.port = port
c = ClientCreator(reactor, _HttpClient)
if scheme == 'http':
self._proto = yield c.connectTCP(self.host, self.port)
elif scheme == 'https':
self._proto = yield c.connectSSL(self.host, self.port,
ssl.ClientContextFactory())
else:
raise HttpException('unsupported url scheme %s' % scheme)
yield self._proto.connect_cb
示例10: createConnection
# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import connectSSL [as 别名]
def createConnection(self, addrs, keyId):
if len(addrs) == 0:
raise HostUnreachableError("Cannot connect to %s" % keyId)
host, port = addrs.pop()
self.log.debug("Attempting to create connection to %s:%i" % (host, port))
cc = ClientCreator(reactor, TintProtocol, self)
d = cc.connectSSL(host, port, self.contextFactory, timeout=5)
d.addCallback(self.saveConnection, keyId)
if len(addrs) > 0:
d.addErrback(lambda _: self.createConnection(addrs, keyId))
return d
示例11: writeMetric
# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import connectSSL [as 别名]
def writeMetric(metricList, host, port, username, password,
vhost, exchange, queue, spec=None, channel_number=1, ssl=False):
global conn
if not spec:
spec = txamqp.spec.load(os.path.normpath(
os.path.join(os.path.dirname(__file__), 'amqp0-8.xml')))
delegate = TwistedDelegate()
connector = ClientCreator(reactor, AMQClient, delegate=delegate,
vhost=vhost, spec=spec)
if ssl:
from twisted.internet.ssl import ClientContextFactory
conn = yield connector.connectSSL(host, port, ClientContextFactory())
else:
conn = yield connector.connectTCP(host, port, timeout=130)
yield conn.authenticate(username, password)
channel = yield conn.channel(channel_number)
yield channel.channel_open()
yield channel.exchange_declare(exchange=exchange, type="topic", durable=True, auto_delete=False)
#reply = yield channel.queue_declare(queue = queue, durable = True)
#my_queue = reply.queue
#Pickup settings.BIND_PATTERNS somewhere else
#for bind_pattern in settings.BIND_PATTERNS:
# yield channel.queue_bind(exchange=exchange, queue=my_queue, routing_key=bind_pattern)
for (metric, datapoints) in metricList:
body = ""
for point in datapoints:
temp = "%f %d\n"%(point[1], point[0])
body = body + temp
message = Content(body)
message["delivery mode"] = 2
channel.basic_publish(exchange=exchange, content=message, routing_key=metric)
yield channel.channel_close()
yield conn.close("Publish Done. Closing Connection.")
示例12: server_autoconnect
# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import connectSSL [as 别名]
def server_autoconnect(self):
def sendServerHandshake(protocol, password):
protocol.callRemote(IntroduceServer, name=self.name, password=password, description=self.servconfig["server_description"], version=protocol_version, commonmodules=self.common_modules)
protocol.sentDataBurst = False
for server in self.servconfig["serverlink_autoconnect"]:
if server not in self.servers and server in self.servconfig["serverlinks"]:
log.msg("Initiating autoconnect to server {}".format(server))
servinfo = self.servconfig["serverlinks"][server]
if "ip" not in servinfo or "port" not in servinfo:
continue
if "bindaddress" in servinfo and "bindport" in servinfo:
bind = (servinfo["bindaddress"], servinfo["bindport"])
else:
bind = None
creator = ClientCreator(reactor, ServerProtocol, self)
if "ssl" in servinfo and servinfo["ssl"]:
d = creator.connectSSL(servinfo["ip"], servinfo["port"], self.ssl_cert, bindAddress=bind)
else:
d = creator.connectTCP(servinfo["ip"], servinfo["port"], bindAddress=bind)
d.addCallback(sendServerHandshake, servinfo["outgoing_password"])
示例13: createClientChannel
# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import connectSSL [as 别名]
def createClientChannel(self, request):
"""
Creates the actual channel for the request.
@param request: The request
@type request: L{ClientRequest}
"""
c = ClientCreator(reactor, self.clientChannel, self)
if request.uri.scheme == 'http':
d = c.connectTCP(host=request.uri.netloc, port=request.uri.port)
else:
d = c.connectSSL(host=request.uri.netloc, port=request.uri.port,
contextFactory=ssl.ClientContextFactory())
pending = PendingChannel()
pending.host = request.uri.getHost()
if request.closeAfter:
pending.readPersistent = False
self.pendingChannels.add(pending)
d.addCallback(self.__request, request, pending)
d.addErrback(self.__handleConnErrback, request, pending)
示例14: do_tcp_check
# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import connectSSL [as 别名]
def do_tcp_check(host, port, tls=False, tls_verify=True,
timeout=None):
"""Generic connection check function."""
if not isIPAddress(host):
try:
ip = yield reactor.resolve(host, timeout=(1, timeout))
except DNSLookupError:
raise ValueError("dns resolution failed")
else:
ip = host
creator = ClientCreator(reactor, TCPCheckProtocol)
try:
if tls:
context = VerifyingContextFactory(tls_verify, CA_CERTS)
yield creator.connectSSL(ip, port, context,
timeout=timeout)
else:
yield creator.connectTCP(ip, port, timeout=timeout)
except TimeoutError:
if ip == host:
raise ValueError("timed out")
else:
raise ValueError("timed out connecting to {}".format(ip))
示例15: getFeedback
# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import connectSSL [as 别名]
def getFeedback(self, deferred):
logger.info("Connecting to Feedback Server, App: %s:%s" % (self.app_mode, self.app_id))
cc = ClientCreator(self.reactor, FeedbackProtocol, deferred)
# SRI: not sure what the client_context_factory is for.. is it ok to reuse like this?
cc.connectSSL(self.feedback_host, self.feedback_port, self.client_context_factory)