本文整理汇总了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;未经允许,请勿转载。 |
请发表评论