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

Python base.BaseQuery类代码示例

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

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



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

示例1: test_ssl_hostname_verification

    def test_ssl_hostname_verification(self):
        """
        If the endpoint passed to L{BaseQuery} has C{ssl_hostname_verification}
        sets to C{True}, a L{VerifyingContextFactory} is passed to
        C{connectSSL}.
        """
        agent_creations = []

        @implementer(IAgent)
        class FakeAgent(object):
            def __init__(self, reactor, contextFactory,
                         connectTimeout=None, bindAddress=None, pool=None):
                agent_creations.append((reactor, contextFactory,
                                        connectTimeout, bindAddress, pool))

            def request(self, method, uri, headers=None, bodyProducer=None):
                return Deferred()

        verifyClass(IAgent, FakeAgent)

        certs = [makeCertificate(O="Test Certificate", CN="something")[1]]
        self.patch(base, "Agent", FakeAgent)
        self.patch(ssl, "_ca_certs", certs)
        endpoint = AWSServiceEndpoint(ssl_hostname_verification=True)
        query = BaseQuery("an action", "creds", endpoint, reactor="ignored")
        query.get_page("https://example.com/file")

        self.assertEqual(len(agent_creations), 1)
        [(_, contextFactory, _, _, _)] = agent_creations
        self.assertIsInstance(contextFactory, ssl.VerifyingContextFactory)
开发者ID:oubiwann,项目名称:txaws,代码行数:30,代码来源:test_base.py


示例2: test_ssl_hostname_verification

    def test_ssl_hostname_verification(self):
        """
        If the endpoint passed to L{BaseQuery} has C{ssl_hostname_verification}
        sets to C{True}, a L{VerifyingContextFactory} is passed to
        C{connectSSL}.
        """

        class FakeReactor(object):

            def __init__(self):
                self.connects = []

            def connectSSL(self, host, port, client, factory):
                self.connects.append((host, port, client, factory))

        certs = makeCertificate(O="Test Certificate", CN="something")[1]
        self.patch(ssl, "_ca_certs", certs)
        fake_reactor = FakeReactor()
        endpoint = AWSServiceEndpoint(ssl_hostname_verification=True)
        query = BaseQuery("an action", "creds", endpoint, fake_reactor)
        query.get_page("https://example.com/file")
        [(host, port, client, factory)] = fake_reactor.connects
        self.assertEqual("example.com", host)
        self.assertEqual(443, port)
        self.assertTrue(isinstance(factory, ssl.VerifyingContextFactory))
        self.assertEqual("example.com", factory.host)
        self.assertNotEqual([], factory.caCerts)
开发者ID:lud4ik,项目名称:txAWS,代码行数:27,代码来源:test_base.py


示例3: test_errors

 def test_errors(self):
     query = BaseQuery(
         "an action", "creds", AWSServiceEndpoint("http://endpoint"),
     )
     d = query.get_page(self._get_url("not_there"))
     self.assertFailure(d, TwistedWebError)
     return d
开发者ID:oubiwann,项目名称:txaws,代码行数:7,代码来源:test_base.py


示例4: test_get_page

 def test_get_page(self):
     query = BaseQuery(
         "an action", "creds", AWSServiceEndpoint("http://endpoint"),
     )
     d = query.get_page(self._get_url("file"))
     d.addCallback(self.assertEquals, "0123456789")
     return d
开发者ID:oubiwann,项目名称:txaws,代码行数:7,代码来源:test_base.py


示例5: test_get_request_headers_with_client

    def test_get_request_headers_with_client(self):
        def check_results(results):
            self.assertEquals(results.keys(), [])
            self.assertEquals(results.values(), [])

        query = BaseQuery("an action", "creds", "http://endpoint")
        d = query.get_page(self._get_url("file"))
        d.addCallback(query.get_request_headers)
        return d.addCallback(check_results)
开发者ID:GP89,项目名称:txaws,代码行数:9,代码来源:test_client.py


示例6: test_custom_body_producer

    def test_custom_body_producer(self):

        def check_producer_was_used(ignore):
            self.assertEqual(producer.written, 'test data')

        producer = StringBodyProducer('test data')
        query = BaseQuery("an action", "creds", "http://endpoint",
            body_producer=producer)
        d = query.get_page(self._get_url("thing_to_put"), method='PUT')
        return d.addCallback(check_producer_was_used)
开发者ID:antisvin,项目名称:txAWS,代码行数:10,代码来源:test_base.py


示例7: test_get_response_headers_with_client

    def test_get_response_headers_with_client(self):
        def check_results(results):
            self.assertEquals(
                sorted(results.keys()),
                ["accept-ranges", "content-length", "content-type", "date", "last-modified", "server"],
            )
            self.assertEquals(len(results.values()), 6)

        query = BaseQuery("an action", "creds", "http://endpoint")
        d = query.get_page(self._get_url("file"))
        d.addCallback(query.get_response_headers)
        return d.addCallback(check_results)
开发者ID:GP89,项目名称:txaws,代码行数:12,代码来源:test_client.py


示例8: test_ssl_subject_alt_name

    def test_ssl_subject_alt_name(self):
        """
        L{VerifyingContextFactory} supports checking C{subjectAltName} in the
        certificate if it's available.
        """
        context_factory = DefaultOpenSSLContextFactory(PRIVSANKEY, PUBSANKEY)
        self.port = reactor.listenSSL(0, self.site, context_factory, interface="127.0.0.1")
        self.portno = self.port.getHost().port

        endpoint = AWSServiceEndpoint(ssl_hostname_verification=True)
        query = BaseQuery("an action", "creds", endpoint)
        d = query.get_page("https://127.0.0.1:%d/file" % (self.portno,))
        return d.addCallback(self.assertEquals, "0123456789")
开发者ID:GP89,项目名称:txaws,代码行数:13,代码来源:test_client.py


示例9: test_ssl_verification_negative

    def test_ssl_verification_negative(self):
        """
        The L{VerifyingContextFactory} fails with a SSL error the certificates
        can't be checked.
        """
        context_factory = DefaultOpenSSLContextFactory(BADPRIVKEY, BADPUBKEY)
        self.port = reactor.listenSSL(0, self.site, context_factory, interface="127.0.0.1")
        self.portno = self.port.getHost().port

        endpoint = AWSServiceEndpoint(ssl_hostname_verification=True)
        query = BaseQuery("an action", "creds", endpoint)
        d = query.get_page(self._get_url("file"))
        return self.assertFailure(d, SSLError)
开发者ID:GP89,项目名称:txaws,代码行数:13,代码来源:test_client.py


示例10: test_ssl_verification_positive

    def test_ssl_verification_positive(self):
        """
        The L{VerifyingContextFactory} properly allows to connect to the
        endpoint if the certificates match.
        """
        context_factory = DefaultOpenSSLContextFactory(PRIVKEY, PUBKEY)
        self.port = reactor.listenSSL(0, self.site, context_factory, interface="127.0.0.1")
        self.portno = self.port.getHost().port

        endpoint = AWSServiceEndpoint(ssl_hostname_verification=True)
        query = BaseQuery("an action", "creds", endpoint)
        d = query.get_page(self._get_url("file"))
        return d.addCallback(self.assertEquals, "0123456789")
开发者ID:GP89,项目名称:txaws,代码行数:13,代码来源:test_client.py


示例11: test_ssl_verification_bypassed

    def test_ssl_verification_bypassed(self):
        """
        L{BaseQuery} doesn't use L{VerifyingContextFactory}
        if C{ssl_hostname_verification} is C{False}, thus allowing to connect
        to non-secure endpoints.
        """
        context_factory = DefaultOpenSSLContextFactory(BADPRIVKEY, BADPUBKEY)
        self.port = reactor.listenSSL(0, self.site, context_factory, interface="127.0.0.1")
        self.portno = self.port.getHost().port

        endpoint = AWSServiceEndpoint(ssl_hostname_verification=False)
        query = BaseQuery("an action", "creds", endpoint)
        d = query.get_page(self._get_url("file"))
        return d.addCallback(self.assertEquals, "0123456789")
开发者ID:GP89,项目名称:txaws,代码行数:14,代码来源:test_client.py


示例12: test_custom_receiver_factory

    def test_custom_receiver_factory(self):

        class TestReceiverProtocol(StreamingBodyReceiver):
            used = False

            def __init__(self):
                StreamingBodyReceiver.__init__(self)
                TestReceiverProtocol.used = True

        def check_used(ignore):
            self.assert_(TestReceiverProtocol.used)

        query = BaseQuery("an action", "creds", "http://endpoint",
            receiver_factory=TestReceiverProtocol)
        d = query.get_page(self._get_url("file"))
        d.addCallback(self.assertEquals, "0123456789")
        d.addCallback(check_used)
        return d
开发者ID:antisvin,项目名称:txAWS,代码行数:18,代码来源:test_base.py


示例13: test_get_response_headers_with_client

    def test_get_response_headers_with_client(self):

        def check_results(results):
            #self.assertEquals(sorted(results.keys()), [
            #    "accept-ranges", "content-length", "content-type", "date",
            #    "last-modified", "server"])
            # XXX I think newclient exludes content-length from headers?
            # Also the header names are capitalized ... do we need to worry
            # about backwards compat?
            self.assertEquals(sorted(results.keys()), [
                "Accept-Ranges", "Content-Type", "Date",
                "Last-Modified", "Server"])
            self.assertEquals(len(results.values()), 5)

        query = BaseQuery("an action", "creds", "http://endpoint")
        d = query.get_page(self._get_url("file"))
        d.addCallback(query.get_response_headers)
        return d.addCallback(check_results)
开发者ID:antisvin,项目名称:txAWS,代码行数:18,代码来源:test_base.py


示例14: test_ssl_verification_negative

    def test_ssl_verification_negative(self):
        """
        The L{VerifyingContextFactory} fails with a SSL error the certificates
        can't be checked.
        """
        context_factory = WebDefaultOpenSSLContextFactory(BADPRIVKEY, BADPUBKEY)
        self.port = reactor.listenSSL(
            0, self.site, context_factory, interface="127.0.0.1")
        self.portno = self.port.getHost().port

        endpoint = AWSServiceEndpoint(ssl_hostname_verification=True)
        query = BaseQuery("an action", "creds", endpoint)
        d = query.get_page(self._get_url("file"))
        def fail(ignore):
            self.fail('Expected SSLError')
        def check_exception(why):
            # XXX kind of a mess here ... need to unwrap the
            # exception and check
            root_exc = why.value[0][0].value
            self.assert_(isinstance(root_exc, SSLError))
        return d.addCallbacks(fail, check_exception)
开发者ID:mithrandi,项目名称:txaws,代码行数:21,代码来源:test_ssl.py


示例15: test_get_response_headers_no_client

    def test_get_response_headers_no_client(self):

        query = BaseQuery("an action", "creds", "http://endpoint")
        results = query.get_response_headers()
        self.assertEquals(results, None)
开发者ID:GP89,项目名称:txaws,代码行数:5,代码来源:test_client.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python client.Query类代码示例发布时间:2022-05-27
下一篇:
Python protocol.AMQClient类代码示例发布时间: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