• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python reactor.connectSSL函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中twisted.internet.reactor.connectSSL函数的典型用法代码示例。如果您正苦于以下问题:Python connectSSL函数的具体用法?Python connectSSL怎么用?Python connectSSL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了connectSSL函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _request

    def _request (self, method, url, *a, **kw) :
        if not url or (not url.startswith("http://") and not url.startswith("https://")) :
            if not self._base_url :
                return defer.maybeDeferred(lambda x : Response(url, ), )

            url = urllib.basejoin(self._base_url, (url and url or ""), )

        _scheme, _host, _port, _path = client_http._parse(url, )

        kw["method"] = method
        _factory = self._client_factory(url, *a, **kw)

        if _scheme == "https" :
            from twisted.internet import ssl
            #_contextFactory = kw.get("contextFactory")
            #if _contextFactory is None :
            #    _contextFactory = ssl.ClientContextFactory()
            _contextFactory = ssl.ClientContextFactory()

            reactor.connectSSL(_host, _port, _factory, _contextFactory, )
        else:
            reactor.connectTCP(_host, _port, _factory)

        return _factory.deferred.addCallback(
            self._cb_request, _factory, url,
        ).addCallback(
            self._cb_request_debug,
        )
开发者ID:creativify,项目名称:information-overload,代码行数:28,代码来源:client.py


示例2: handleStatus_301

 def handleStatus_301(self):
     l = self.headers.get('location')
     if not l:
         self.handleStatusDefault()
         return
     url = l[0]
     if self.followRedirect:
         scheme, host, port, path = \
             _parse(url, defaultPort=self.transport.getPeer().port)
         self.factory.setURL(url)
 
         if self.factory.scheme == 'https':
             from twisted.internet import ssl
             contextFactory = ssl.ClientContextFactory()
             reactor.connectSSL(self.factory.host, self.factory.port, 
                                self.factory, contextFactory)
         else:
             reactor.connectTCP(self.factory.host, self.factory.port, 
                                self.factory)
     else:
         self.handleStatusDefault()
         self.factory.noPage(
             failure.Failure(
                 error.PageRedirect(
                     self.status, self.message, location = url)))
     self.quietLoss = 1
     self.transport.loseConnection()
开发者ID:GNOME,项目名称:postr,代码行数:27,代码来源:proxyclient.py


示例3: write

 def write(self, notifications):
   "Connect to the APNS service and send notifications"
   if not self.factory:
     log.msg('APNSService write (connecting)')
     server, port = ((APNS_SERVER_SANDBOX_HOSTNAME 
                     if self.environment == 'sandbox'
                     else APNS_SERVER_HOSTNAME), APNS_SERVER_PORT)
     self.factory = self.clientProtocolFactory()
     context = self.getContextFactory()
     reactor.connectSSL(server, port, self.factory, context)
   
   client = self.factory.clientProtocol
   if client:
     return client.sendMessage(notifications)
   else:      
     d = self.factory.deferred
     timeout = reactor.callLater(self.timeout, 
       lambda: d.called or d.errback(
         Exception('Notification timed out after %i seconds' % self.timeout)))
     def cancel_timeout(r):
       try: timeout.cancel()
       except: pass
       return r
     
     d.addCallback(lambda p: p.sendMessage(notifications))
     d.addErrback(log_errback('apns-service-write'))
     d.addBoth(cancel_timeout)
     return d
开发者ID:B-Rich,项目名称:pyapns,代码行数:28,代码来源:server.py


示例4: connect

    def connect(self):
        """connect to the jabber server"""
        self.dprint('Starting to connect')
        self.dprint('Building context factory for jid %s' % self.jidString(self.userId))
        jidStr = self.jidString(self.userId)
        self._fact = factory = client.basicClientFactory(jid.JID(jidStr), self.userPassword)
        factory.addBootstrap('//event/stream/authd', self.authenticate)
        factory.addBootstrap(client.BasicAuthenticator.INVALID_USER_EVENT, self.invalidUser)
        factory.addBootstrap(client.BasicAuthenticator.AUTH_FAILED_EVENT, self.fatalError)
        factory.addBootstrap(client.BasicAuthenticator.REGISTER_FAILED_EVENT, self.fatalError)

        self.dprint('connecting to server %s using id %s...' % (self.server, self.userId))
        if self.wants_ssl:
            class contextFactory:
                isClient = 1
                method = ssl.SSL.SSLv3_METHOD

                def getContext(self):
                    context = ssl.SSL.Context(self.method)
                    return context

            self.dprint('Connecting with ssl...')
            ctxFactory = contextFactory()
            reactor.connectSSL(self.host, self.port, factory, ctxFactory)
        else:
            reactor.connectTCP(self.host, self.port, factory)
        return reactor
开发者ID:Psicrone,项目名称:xmppBot,代码行数:27,代码来源:Adapter.py


示例5: _makeGetterFactory

def _makeGetterFactory(url, factoryFactory, contextFactory=None, *args, **kwargs):
    """
    Create and connect an HTTP page getting factory.

    Any additional positional or keyword arguments are used when calling
    C{factoryFactory}.

    @param factoryFactory: Factory factory that is called with C{url}, C{args}
        and C{kwargs} to produce the getter

    @param contextFactory: Context factory to use when creating a secure
        connection, defaulting to C{None}

    @return: The factory created by C{factoryFactory}
    """
    scheme, host, port, path = _parse(url)
    factory = factoryFactory(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
开发者ID:rolando-contribute,项目名称:cyclone,代码行数:26,代码来源:client.py


示例6: get_page

    def get_page(self, contextFactory=None, description=None, *args, **kwargs):
        if description is None:
            description = self.url

        log.debug("Requesting %s", description)

        scheme, _, _, _ = twisted_web_client_parse(self.url)
        factory = txwebclient.HTTPClientFactory(self.url, *args, **kwargs)
        if scheme == 'https':
            from twisted.internet import ssl
            if contextFactory is None:
                contextFactory = ssl.ClientContextFactory()
            if self.use_proxy:
                ip = yield self.resolve(self.proxy_host)
                reactor.connectSSL(ip, self.proxy_port,
                                   factory, contextFactory)
            else:
                ip = yield self.resolve(self.host)
                reactor.connectSSL(ip, self.port,
                                   factory, contextFactory)
        else:
            if self.use_proxy:
                ip = yield self.resolve(self.proxy_host)
                reactor.connectTCP(ip, self.proxy_port, factory)
            else:
                ip = yield self.resolve(self.host)
                reactor.connectTCP(ip, self.port, factory)

        result = yield factory.deferred
        defer.returnValue(result)
开发者ID:zenoss,项目名称:ZenPacks.zenoss.AWS,代码行数:30,代码来源:utils.py


示例7: __init__

	def __init__(self, url, contextFactory=None, retries=0):

		url = stripNoPrint(url)
		if retries > 0:
			print "Retrying: ", url
		else:
			print "Get: ", url
		self.retries = retries
		self.url = url
		self.charset = None
		scheme, host, port, path = _parse(url)
		HTTPClientFactory.__init__(self, url,
			method='GET', postdata=None, headers=None,
			agent='Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US;' + 
				' rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10')
		if scheme == 'https':
			from twisted.internet import ssl
			if contextFactory is None:
				contextFactory = ssl.ClientContextFactory()
			reactor.connectSSL(host, port, self, contextFactory)
		else:
			reactor.connectTCP(host, port, self)
		
		self.deferred.addCallbacks(self.getCharset, self.Err)
		self.deferred.addCallbacks(self.getTitle, self.Err)
开发者ID:kunwon1,项目名称:Subtitle,代码行数:25,代码来源:TitleGetter2.py


示例8: __init__

 def __init__(self, version):
  self.version = version
  self.stopped = False
  self.tc = 0
  self.th = {}
  self.sjid = u'%[email protected]%s/%s' % (config.USER, config.SERVER, config.RESOURCE)
  self.jid = jid.JID(self.sjid)
  self.onauthd = None
  self.a = XMPPAuthenticator(self.jid, config.PASSWD)
  self.c = ClientFactory(self.a, self)
  self.c.maxRetries = 0
  self.c.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self.authd)
  self.c.addBootstrap(xmlstream.INIT_FAILED_EVENT, self.initfailed)
  self.c.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, self.onConnected)
  self.c.addBootstrap(xmlstream.STREAM_END_EVENT, self.onDisconnected)
  self.x = None
  self.log = log.logger()
  self.msghandlers = []
  port = config.PORT
  if config.CONNECT_SERVER: server = config.CONNECT_SERVER
  else: server = config.SERVER
  if config.USE_SSL:
   from twisted.internet import ssl
   reactor.connectSSL(server, port, self.c, ssl.ClientContextFactory())
  else: reactor.connectTCP(server, port, self.c)
开发者ID:BackupTheBerlios,项目名称:freq-dev-svn,代码行数:25,代码来源:twistedwrapper.py


示例9: connectSSL

 def connectSSL(self, server, port, vhost):
     """Connect to the server using an SSL socket."""
     drivers.log.info("Attempting an SSL connection.")
     if SSL:
         reactor.connectSSL(server, port, self, ssl.ClientContextFactory(), bindAddress=(vhost, 0))
     else:
         drivers.log.error("PyOpenSSL is not available. Not connecting.")
开发者ID:SebLemery,项目名称:supybot,代码行数:7,代码来源:Twisted.py


示例10: do_connect

    def do_connect():
        """Connect and authenticate."""
        result_deferred = Deferred()
        context_factory = None
        if use_tls:
            from twisted.internet import ssl as twisted_ssl
            context_factory = twisted_ssl.ClientContextFactory()

        body = MIMEText(message)
        body['Subject'] = subject
        factory = ESMTPSenderFactory(
            username,
            password,
            from_address,
            to_address,
            StringIO(body.as_string()),
            result_deferred,
            contextFactory=context_factory,
            requireTransportSecurity=use_tls,
            requireAuthentication=True,
            heloFallback=helo_fallback)

        if use_tls:
            reactor.connectSSL(host, port, factory, context_factory)
        else:
            reactor.connectTCP(host, port, factory)
        result = yield result_deferred

        if result[0] == 0:
            raise RuntimeError("failed to send email via smtp")
开发者ID:canonical-ols,项目名称:conn-check,代码行数:30,代码来源:checks.py


示例11: connect_to_server

 def connect_to_server(self):
     """
     Connect to media server
     """
     reactor.connectSSL(sys.argv[1], int(sys.argv[2]),
                        TheaterFactory(self), ssl.ClientContextFactory())
     reactor.run()
开发者ID:MediaKraken,项目名称:MediaKraken_Deployment,代码行数:7,代码来源:main_server_link.py


示例12: testFailedVerify

    def testFailedVerify(self):
        org = "twisted.test.test_ssl"
        self.setupServerAndClient(
            (org, org + ", client"), {},
            (org, org + ", server"), {})

        def verify(*a):
            return False
        self.clientCtxFactory.getContext().set_verify(SSL.VERIFY_PEER, verify)

        serverConnLost = defer.Deferred()
        serverProtocol = protocol.Protocol()
        serverProtocol.connectionLost = serverConnLost.callback
        serverProtocolFactory = protocol.ServerFactory()
        serverProtocolFactory.protocol = lambda: serverProtocol
        self.serverPort = serverPort = reactor.listenSSL(0,
            serverProtocolFactory, self.serverCtxFactory)

        clientConnLost = defer.Deferred()
        clientProtocol = protocol.Protocol()
        clientProtocol.connectionLost = clientConnLost.callback
        clientProtocolFactory = protocol.ClientFactory()
        clientProtocolFactory.protocol = lambda: clientProtocol
        reactor.connectSSL('127.0.0.1',
            serverPort.getHost().port, clientProtocolFactory, self.clientCtxFactory)

        dl = defer.DeferredList([serverConnLost, clientConnLost], consumeErrors=True)
        return dl.addCallback(self._cbLostConns)
开发者ID:Lovelykira,项目名称:frameworks_try,代码行数:28,代码来源:test_ssl.py


示例13: run

    def run(self):
        """ main loop - pretty simple """
        while True:
            try:
                clientFactory = self.parent.request_queue.get(True,1)
                if type(clientFactory) == type("Quit"): return
            except Queue.Empty:
                if self.finished: return
                continue

            self.parent.ppc.getToken()
            if self.parent.ssl:

                with open(self.parent.keyfile) as keyFile:
                    with open(self.parent.crtfile) as certFile:
                        clientCert = ssl.PrivateCertificate.loadPEM(
                        keyFile.read() + certFile.read())

                ctx = clientCert.options()
                #contextFactory = ssl.ClientContextFactory()
                reactor.connectSSL(self.parent.host, self.parent.port, clientFactory, ctx)
            else:
                reactor.connectTCP(self.parent.host, self.parent.port, clientFactory)

            time_taken = time()-clientFactory.Qtime
            stats = self.parent.statistics
            stats.avg_time_taken = (
                stats.total_serviced * stats.avg_time_taken + time_taken) \
                / (stats.total_serviced+1)
            stats.total_serviced += 1
开发者ID:dvla,项目名称:proxypy,代码行数:30,代码来源:proxy.py


示例14: historical_pull

def historical_pull(start_date, end_date, account, api_key, topic_id, filename, time_zone='edt'):

    
    url = 'wss://pipeline.attensity.com/account/' + account + '/feed?api_key=' + api_key + '&topic_id[]=' + topic_id

    # need to generalize and make accessible as a tool
    if time_zone.lower() == 'edt':        
        time_shift = datetime.timedelta(hours=4)
    else:
        # I think, should double check
        time_shift = datetime.timedelta(hours=5)

    start_t = datetime.datetime(start_date['year'], start_date['month'], start_date['day'], start_date['hour'], start_date['minute']) + time_shift    
    start_timestamp = (start_t - datetime.datetime(1970, 1, 1)).total_seconds()

    end_t = datetime.datetime(end_date['year'], end_date['month'], end_date['day'], end_date['hour'], end_date['minute']) + time_shift
    end_timestamp = (end_t - datetime.datetime(1970, 1, 1)).total_seconds()

    if start_timestamp > end_timestamp:
        print 'Start Time is after End Time.'
        print 'Exiting...'
        sys.exit(1)

    url += '&starttime=' + str(int(start_timestamp)) + '&endtime=' + str(int(end_timestamp)) + '&stream_mode=historical'

    print url

    f = open(filename, 'w')

    factory = ws.AttensityFactory(url, file_handle=f)
    reactor.connectSSL(factory.host, factory.port, factory, ssl.ClientContextFactory())
开发者ID:cpfarrell,项目名称:PastResearch,代码行数:31,代码来源:pipeline_access.py


示例15: getProxyPage

    def getProxyPage(url, contextFactory=None, host=None, port=None,
                     status=None, *args, **kwargs):
        """Download a web page as a string. (modified from twisted.web.client.getPage)

        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.
        """
        if status > 300 and status < 304:
            factory = RedirHTTPClientFactory(url, *args, **kwargs)
        else:
            factory = client.HTTPClientFactory(url, *args, **kwargs)

        host = host or factory.host
        port = port or factory.port

        if factory.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:runt18,项目名称:PyBal,代码行数:25,代码来源:proxyfetch.py


示例16: execute

 def execute(self):
     if self.scheme == "https":
         from twisted.internet import ssl
         reactor.connectSSL(self.host, self.port, self, ssl.ClientContextFactory())
     else:
         reactor.connectTCP(self.host, self.port, self)
     return self.deferred
开发者ID:marscher,项目名称:deluge_qt,代码行数:7,代码来源:tracker_icons.py


示例17: testFactoryInfo

 def testFactoryInfo(self):
     url = self.getURL("file")
     uri = client.URI.fromBytes(url)
     factory = client.HTTPClientFactory(url)
     reactor.connectSSL(nativeString(uri.host), uri.port, factory, ssl.ClientContextFactory())
     # The base class defines _cbFactoryInfo correctly for this
     return factory.deferred.addCallback(self._cbFactoryInfo, factory)
开发者ID:ragercool,项目名称:twisted,代码行数:7,代码来源:test_webclient.py


示例18: httpRequest

def httpRequest(url, payload, headers, method='POST', timeout=DEFAULT_TIMEOUT, ctx_factory=None):
    # copied from twisted.web.client in order to get access to the
    # factory (which contains response codes, headers, etc)

    if type(url) is not str:
        e = HTTPRequestError('URL must be string, not %s' % type(url))
        return defer.fail(e)

    if not url.startswith('http'):
        e = HTTPRequestError('URL does not start with http (URL %s)' % (url))
        return defer.fail(e)

    log.msg(" -- Sending Payload to %s --\n%s\n -- END. Sending Payload --" % (url, payload), system=LOG_SYSTEM, payload=True)

    scheme, netloc, _ , _, _, _ = twhttp.urlparse(url)
    if not ':' in netloc:
        host = netloc
        port = 80 if scheme == 'http' else 443
    else:
        host, s_port = netloc.split(':',1)
        port = int(s_port)

    factory = twclient.HTTPClientFactory(url, method, postdata=payload, timeout=timeout)
    factory.noisy = False # stop spewing about factory start/stop
    factory.protocol.handleStatus_204 = lambda _ : None # 204 is an ok reply, needed by NCS VPN backend

    # fix missing port in header (bug in twisted.web.client)
    factory.headers['host'] = host + ':' + str(port)
    factory.headers['User-Agent'] = 'OpenNSA/Twisted'

    for header, value in headers.items():
        factory.headers[header] = value

    if scheme == 'https':
        if ctx_factory is None:
            return defer.fail(HTTPRequestError('Cannot perform https request without context factory'))
        reactor.connectSSL(host, port, factory, ctx_factory)
    else:
        reactor.connectTCP(host, port, factory)

    def invocationError(err):
        if isinstance(err.value, ConnectionClosed): # note: this also includes ConnectionDone and ConnectionLost
            pass # these are pretty common when the remote shuts down
        elif isinstance(err.value, WebError):
            data = err.value.response
            log.msg(' -- Received Reply (fault) --\n%s\n -- END. Received Reply (fault) --' % data, system=LOG_SYSTEM, payload=True)
            return err
        elif isinstance(err.value, ConnectionRefusedError):
            log.msg('Connection refused for %s:%i. Request URL: %s' % (host, port, url), system=LOG_SYSTEM)
            return err
        else:
            return err

    def logReply(data):
        log.msg(" -- Received Reply --\n%s\n -- END. Received Reply --" % data, system=LOG_SYSTEM, payload=True)
        return data

    factory.deferred.addCallbacks(logReply, invocationError)

    return factory.deferred
开发者ID:NORDUnet,项目名称:opennsa,代码行数:60,代码来源:httpclient.py


示例19: getPagePrxoy

def getPagePrxoy(url, proxy=None, contextFactory=None,
                       *args, **kwargs):
    '''
    proxy=
    {
    host:192.168.1.111,
    port:6666
    }
    '''
    kwargs["timeout"] = 60
    if proxy is None:
        scheme, host, port, path = client._parse(url)
        factory = client.HTTPClientFactory(url, *args, **kwargs)
        if scheme == b'https':
            from twisted.internet import ssl
            if contextFactory is None:
                contextFactory = ssl.ClientContextFactory()
            reactor.connectSSL(client.nativeString(host), port, factory, contextFactory)
        else:
            reactor.connectTCP(client.nativeString(host), port, factory)
        return factory.deferred
    else:
        factory = client.HTTPClientFactory(url, *args, **kwargs)
        reactor.connectTCP(proxy["host"], proxy["port"], factory)
        return factory.deferred
开发者ID:mobishift2011,项目名称:data007,代码行数:25,代码来源:spider_gt.py


示例20: download

    def download(self, url, fakeoutfile, outputfile, *args, **kwargs):
        try:
            parsed = urlparse.urlparse(url)
            scheme = parsed.scheme
            host = parsed.hostname
            port = parsed.port or (443 if scheme == 'https' else 80)
            path = parsed.path or '/'
            if scheme != 'http' and scheme != 'https':
                raise exceptions.NotImplementedError
        except:
            self.write('%s: Unsupported scheme.\n' % (url,))
            self.exit()
            return None

        if self.quiet == False:
            self.write('--%s--  %s' % (time.strftime('%Y-%m-%d %H:%M:%S\n'), url))
            self.write('Connecting to %s:%d... connected.\n' % (host, port))
            self.write('HTTP request sent, awaiting response... ')

        factory = HTTPProgressDownloader(
            self, fakeoutfile, url, outputfile, *args, **kwargs)
        out_addr = None
        if self.protocol.cfg.has_option('honeypot', 'out_addr'):
            out_addr = (self.protocol.cfg.get('honeypot', 'out_addr'), 0)

        if scheme == 'https':
            contextFactory = ssl.ClientContextFactory()
            contextFactory.method = SSL.SSLv23_METHOD
            reactor.connectSSL(host, port, factory, contextFactory)
        else: #can only be http, since we raised an error above for unknown schemes
            self.connection = reactor.connectTCP(
                host, port, factory, bindAddress=out_addr)

        return factory.deferred
开发者ID:g0tmi1k,项目名称:cowrie,代码行数:34,代码来源:wget.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python reactor.connectTCP函数代码示例发布时间:2022-05-27
下一篇:
Python reactor.callWhenRunning函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap