當前位置: 首頁>>代碼示例>>Python>>正文


Python ssl.ClientContextFactory方法代碼示例

本文整理匯總了Python中twisted.internet.ssl.ClientContextFactory方法的典型用法代碼示例。如果您正苦於以下問題:Python ssl.ClientContextFactory方法的具體用法?Python ssl.ClientContextFactory怎麽用?Python ssl.ClientContextFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.internet.ssl的用法示例。


在下文中一共展示了ssl.ClientContextFactory方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _getContextFactory

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import ClientContextFactory [as 別名]
def _getContextFactory(self):
        """
        Get a context factory with which to negotiate TLS.

        @rtype: L{None} or
            L{ClientContextFactory <twisted.internet.ssl.ClientContextFactory>}
        @return: A context factory or L{None} if TLS is not supported on the
            client.
        """
        try:
            from twisted.internet import ssl
        except ImportError:
            return None
        else:
            context = ssl.ClientContextFactory()
            context.method = ssl.SSL.TLSv1_METHOD
            return context 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:19,代碼來源:pop3client.py

示例2: test_openSSLBuffering

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import ClientContextFactory [as 別名]
def test_openSSLBuffering(self):
        serverProto = self.serverProto = SingleLineServerProtocol()
        clientProto = self.clientProto = RecordingClientProtocol()

        server = protocol.ServerFactory()
        client = self.client = protocol.ClientFactory()

        server.protocol = lambda: serverProto
        client.protocol = lambda: clientProto

        sCTX = ssl.DefaultOpenSSLContextFactory(certPath, certPath)
        cCTX = ssl.ClientContextFactory()

        port = reactor.listenSSL(0, server, sCTX, interface='127.0.0.1')
        self.addCleanup(port.stopListening)

        clientConnector = reactor.connectSSL('127.0.0.1', port.getHost().port,
                                             client, cCTX)
        self.addCleanup(clientConnector.disconnect)

        return clientProto.deferred.addCallback(
            self.assertEqual, b"+OK <some crap>\r\n") 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:24,代碼來源:test_ssl.py

示例3: _sendmail

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import ClientContextFactory [as 別名]
def _sendmail(self, to_addrs, msg):
        # Import twisted.mail here because it is not available in python3
        from twisted.mail.smtp import ESMTPSenderFactory
        msg = BytesIO(msg)
        d = defer.Deferred()
        factory = ESMTPSenderFactory(self.smtpuser, self.smtppass, self.mailfrom, \
            to_addrs, msg, d, heloFallback=True, requireAuthentication=False, \
            requireTransportSecurity=self.smtptls)
        factory.noisy = False

        if self.smtpssl:
            reactor.connectSSL(self.smtphost, self.smtpport, factory, ssl.ClientContextFactory())
        else:
            reactor.connectTCP(self.smtphost, self.smtpport, factory)

        return d 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:18,代碼來源:mail.py

示例4: test_getHandle

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import ClientContextFactory [as 別名]
def test_getHandle(self):
        """
        L{TLSMemoryBIOProtocol.getHandle} returns the L{OpenSSL.SSL.Connection}
        instance it uses to actually implement TLS.

        This may seem odd.  In fact, it is.  The L{OpenSSL.SSL.Connection} is
        not actually the "system handle" here, nor even an object the reactor
        knows about directly.  However, L{twisted.internet.ssl.Certificate}'s
        C{peerFromTransport} and C{hostFromTransport} methods depend on being
        able to get an L{OpenSSL.SSL.Connection} object in order to work
        properly.  Implementing L{ISystemHandle.getHandle} like this is the
        easiest way for those APIs to be made to work.  If they are changed,
        then it may make sense to get rid of this implementation of
        L{ISystemHandle} and return the underlying socket instead.
        """
        factory = ClientFactory()
        contextFactory = ClientContextFactory()
        wrapperFactory = TLSMemoryBIOFactory(contextFactory, True, factory)
        proto = TLSMemoryBIOProtocol(wrapperFactory, Protocol())
        transport = StringTransport()
        proto.makeConnection(transport)
        self.assertIsInstance(proto.getHandle(), ConnectionType) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:24,代碼來源:test_tls.py

示例5: test_makeConnection

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import ClientContextFactory [as 別名]
def test_makeConnection(self):
        """
        When L{TLSMemoryBIOProtocol} is connected to a transport, it connects
        the protocol it wraps to a transport.
        """
        clientProtocol = Protocol()
        clientFactory = ClientFactory()
        clientFactory.protocol = lambda: clientProtocol

        contextFactory = ClientContextFactory()
        wrapperFactory = TLSMemoryBIOFactory(
            contextFactory, True, clientFactory)
        sslProtocol = wrapperFactory.buildProtocol(None)

        transport = StringTransport()
        sslProtocol.makeConnection(transport)

        self.assertNotIdentical(clientProtocol.transport, None)
        self.assertNotIdentical(clientProtocol.transport, transport) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:21,代碼來源:test_tls.py

示例6: test_openSSLBuffering

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import ClientContextFactory [as 別名]
def test_openSSLBuffering(self):
        serverProto = self.serverProto = SingleLineServerProtocol()
        clientProto = self.clientProto = RecordingClientProtocol()

        server = protocol.ServerFactory()
        client = self.client = protocol.ClientFactory()

        server.protocol = lambda: serverProto
        client.protocol = lambda: clientProto

        sCTX = ssl.DefaultOpenSSLContextFactory(certPath, certPath)
        cCTX = ssl.ClientContextFactory()

        port = reactor.listenSSL(0, server, sCTX, interface='127.0.0.1')
        self.addCleanup(port.stopListening)

        reactor.connectSSL('127.0.0.1', port.getHost().port, client, cCTX)

        return clientProto.deferred.addCallback(
            self.assertEquals, "+OK <some crap>\r\n") 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:22,代碼來源:test_ssl.py

示例7: callRemote

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import ClientContextFactory [as 別名]
def callRemote(self, method, *args, **kwargs):
        if pipeline_debug: print 'callRemote to %s : %s' % (self.host, method)
        args = (args, kwargs)
        query = Query(self.path, self.host, method, self.user,
                      self.password, *args)
        self.factory.addQuery(query)

        if pipeline_debug: print 'factory started: %s' % self.factory.started
        if not self.factory.started:
            self.factory.started = True
            def connect(host):
                if self.secure:
                    if pipeline_debug: print 'connecting to %s' % str((host, self.port or 443))
                    from twisted.internet import ssl
                    reactor.connectSSL(host, self.port or 443,
                                       self.factory, ssl.ClientContextFactory(),
                                       timeout=60)
                else:
                    if pipeline_debug: print 'connecting to %s' % str((host, self.port or 80))
                    reactor.connectTCP(host, self.port or 80, self.factory,
                                       timeout=60)
            df = reactor.resolve(self.host)
            df.addCallback(connect)
            df.addErrback(query.deferred.errback)
        return query.deferred 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:27,代碼來源:twisted_ebrpc.py

示例8: downloadPageFactory

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import ClientContextFactory [as 別名]
def downloadPageFactory(url, file, progressCallback=None,
                        agent="BitTorrent client",
                        bindAddress=None,
                        contextFactory=None):
    """Download a web page to a file.

    @param file: path to file on filesystem, or file-like object.
    """
    scheme, host, port, path = client._parse(url)
    factory = ProgressHTTPDownloader(url, file,
                                     progressCallback=progressCallback,
                                     agent=agent,
                                     supportPartial=0)
    if scheme == 'https':
        from twisted.internet import ssl
        if contextFactory is None:
            contextFactory = ssl.ClientContextFactory()
        reactor.connectSSL(host, port, factory, contextFactory,
                           bindAddress=bindAddress)
    else:
        reactor.connectTCP(host, port, factory,
                           bindAddress=bindAddress)
    return factory 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:25,代碼來源:HTTPDownloader.py

示例9: getPage

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import ClientContextFactory [as 別名]
def getPage(url, contextFactory=None, *args, **kwargs):
    """Download a web page as a string.

    Download a page. Return a deferred, which will callback with a
    page (as a string) or errback with a description of the error.

    See HTTPClientFactory to see what extra args can be passed.
    """
    scheme, host, port, path = _parse(url)
    factory = HTTPClientFactory(url, *args, **kwargs)
    if scheme == 'https':
        from twisted.internet import ssl
        if contextFactory is None:
            contextFactory = ssl.ClientContextFactory()
        reactor.connectSSL(host, port, factory, contextFactory)
    else:
        reactor.connectTCP(host, port, factory)
    return factory.deferred 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:20,代碼來源:client.py

示例10: downloadPage

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import ClientContextFactory [as 別名]
def downloadPage(url, file, contextFactory=None, *args, **kwargs):
    """Download a web page to a file.

    @param file: path to file on filesystem, or file-like object.
    
    See HTTPDownloader to see what extra args can be passed.
    """
    scheme, host, port, path = _parse(url)
    factory = HTTPDownloader(url, file, *args, **kwargs)
    if scheme == 'https':
        from twisted.internet import ssl
        if contextFactory is None:
            contextFactory = ssl.ClientContextFactory()
        reactor.connectSSL(host, port, factory, contextFactory)
    else:
        reactor.connectTCP(host, port, factory)
    return factory.deferred 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:19,代碼來源:client.py

示例11: startTLS

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import ClientContextFactory [as 別名]
def startTLS(self):
        def proceed(obj):
            print "proceed"
            ctx = ssl.ClientContextFactory()
            ctx.method = SSL.TLSv1_METHOD   # We only do TLS, no SSL
            self.transport.startTLS(ctx)
            self.reset()
            self.tlsEstablished = 1
            self.sendHeader()

        def failure(obj):
            self.factory.stopTrying()
            self.dispatch(obj, TLS_FAILED_EVENT)

        self.addOnetimeObserver("/proceed", proceed)
        self.addOnetimeObserver("/failure", failure)
        self.send("<starttls xmlns='%s'/>" % NS_XMPP_TLS) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:19,代碼來源:xmlstream.py

示例12: setUp

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import ClientContextFactory [as 別名]
def setUp(self):
        test_tcp.PortCleanerUpper.setUp(self)
        self.serverConns = []
        f = protocol.ServerFactory()
        f.protocol = protocol.Protocol
        self.listener = reactor.listenSSL(
            0, f, ssl.DefaultOpenSSLContextFactory(certPath, certPath), interface="127.0.0.1",
        )
        self.ports.append(self.listener)
        f = protocol.ClientFactory()
        f.protocol = test_tcp.ConnectionLosingProtocol

        f.protocol.master = self

        L = []
        def connector():
            p = self.listener.getHost().port
            ctx = ssl.ClientContextFactory()
            return reactor.connectSSL('127.0.0.1', p, f, ctx)
        self.connector = connector

        self.totalConnections = 0 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:24,代碼來源:test_ssl.py

示例13: testOpenSSLBuffering

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import ClientContextFactory [as 別名]
def testOpenSSLBuffering(self):
        serverProto = self.serverProto = SingleLineServerProtocol()
        clientProto = self.clientProto = RecordingClientProtocol()

        server = protocol.ServerFactory()
        client = self.client = protocol.ClientFactory()

        server.protocol = lambda: serverProto
        client.protocol = lambda: clientProto
        client.buffer = []

        sCTX = ssl.DefaultOpenSSLContextFactory(certPath, certPath)
        cCTX = ssl.ClientContextFactory()

        port = self.port = reactor.listenSSL(0, server, sCTX, interface='127.0.0.1')
        reactor.connectSSL('127.0.0.1', port.getHost().port, client, cCTX)

        i = 0
        while i < 5000 and not client.buffer:
            i += 1
            reactor.iterate()

        self.assertEquals(client.buffer, ["+OK <some crap>\r\n"]) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:25,代碼來源:test_ssl.py

示例14: start

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import ClientContextFactory [as 別名]
def start(klass, address, pdid, realm='paradrop', start_reactor=False,
              debug=False, extra=None, reconnect=True):
        '''
        Creates a new instance of this session and attaches it to the router
        at the given address and realm.

        reconnect: The session will attempt to reconnect on connection failure
            and continue trying indefinitely.
        '''
        # Enable log messages of autobahn for debugging
        #import txaio
        #txaio.start_logging()

        dee = Deferred()

        component_config = ComponentConfig(realm=u''+realm, extra=u''+pdid)
        session_factory = BaseSessionFactory(config=component_config, deferred=dee)
        session_factory.session = klass

        transport_factory = BaseClientFactory(session_factory, url=address)
        if not reconnect:
            transport_factory.maxRetries = 0
        transport_factory.setProtocolOptions(autoPingInterval=8., autoPingTimeout=4.,)
        context_factory = ClientContextFactory()
        websocket.connectWS(transport_factory, context_factory)

        if start_reactor:
            reactor.run()

        return dee

        # This the the recommended way to start the WAMP component,
        # but it is friendly to customize the component
        #runner = ApplicationRunner(url=u''+address, realm=u''+realm)
        #return runner.run(klass, start_reactor=start_reactor, auto_reconnect=reconnect) 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:37,代碼來源:cxbr.py

示例15: __init__

# 需要導入模塊: from twisted.internet import ssl [as 別名]
# 或者: from twisted.internet.ssl import ClientContextFactory [as 別名]
def __init__(self, oauth2_token, baseURL=None, reactor=None):
        self._baseURL = baseURL or 'https://api.github.com/'
        self.oauth2_token = oauth2_token
        self.rateLimitWarningIssued = False
        self.contextFactory = ssl.ClientContextFactory()
        if reactor is None:
            from twisted.internet import reactor
        self.reactor = reactor 
開發者ID:llvm,項目名稱:llvm-zorg,代碼行數:10,代碼來源:api.py


注:本文中的twisted.internet.ssl.ClientContextFactory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。