当前位置: 首页>>代码示例>>Python>>正文


Python ClientCreator.connectSSL方法代码示例

本文整理汇总了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)
开发者ID:dalinhuang,项目名称:gybprojects,代码行数:9,代码来源:ftp_client.py

示例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()
开发者ID:mattbennett,项目名称:orbited,代码行数:60,代码来源:proxy.py

示例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()
开发者ID:3ofcoins,项目名称:graphite_stack,代码行数:31,代码来源:amqp_publisher.py

示例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
开发者ID:rolando-contribute,项目名称:cyclone,代码行数:27,代码来源:client.py

示例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"])
开发者ID:smillaedler,项目名称:txircd,代码行数:32,代码来源:cmd_connect.py

示例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)))
开发者ID:boffbowsh,项目名称:gitmouth,代码行数:9,代码来源:session.py

示例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)
开发者ID:bernii,项目名称:monocle,代码行数:10,代码来源:__init__.py

示例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)
开发者ID:krahimian,项目名称:tint,代码行数:10,代码来源:tintp.py

示例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
开发者ID:bernii,项目名称:monocle,代码行数:14,代码来源:http.py

示例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
开发者ID:tintfoundation,项目名称:tint,代码行数:14,代码来源:tintp.py

示例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.")
开发者ID:niteshjain,项目名称:CarbonAMQP_Producer,代码行数:45,代码来源:amqp_publisher.py

示例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"])
开发者ID:smillaedler,项目名称:txircd,代码行数:22,代码来源:ircd.py

示例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)
开发者ID:tdavis,项目名称:tangled,代码行数:22,代码来源:http.py

示例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))
开发者ID:canonical-ols,项目名称:conn-check,代码行数:25,代码来源:checks.py

示例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)
开发者ID:TomACPace,项目名称:apnsd,代码行数:7,代码来源:daemon.py


注:本文中的twisted.internet.protocol.ClientCreator.connectSSL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。