本文整理汇总了Python中twisted.web.iweb.IPolicyForHTTPS方法的典型用法代码示例。如果您正苦于以下问题:Python iweb.IPolicyForHTTPS方法的具体用法?Python iweb.IPolicyForHTTPS怎么用?Python iweb.IPolicyForHTTPS使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.iweb
的用法示例。
在下文中一共展示了iweb.IPolicyForHTTPS方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_deprecatedDuckPolicy
# 需要导入模块: from twisted.web import iweb [as 别名]
# 或者: from twisted.web.iweb import IPolicyForHTTPS [as 别名]
def test_deprecatedDuckPolicy(self):
"""
Passing something that duck-types I{like} a L{web client context
factory <twisted.web.client.WebClientContextFactory>} - something that
does not provide L{IPolicyForHTTPS} - to L{Agent} emits a
L{DeprecationWarning} even if you don't actually C{import
WebClientContextFactory} to do it.
"""
def warnMe():
client.Agent(MemoryReactorClock(),
"does-not-provide-IPolicyForHTTPS")
warnMe()
warnings = self.flushWarnings([warnMe])
self.assertEqual(len(warnings), 1)
[warning] = warnings
self.assertEqual(warning['category'], DeprecationWarning)
self.assertEqual(
warning['message'],
"'does-not-provide-IPolicyForHTTPS' was passed as the HTTPS "
"policy for an Agent, but it does not provide IPolicyForHTTPS. "
"Since Twisted 14.0, you must pass a provider of IPolicyForHTTPS."
)
示例2: integrationTest
# 需要导入模块: from twisted.web import iweb [as 别名]
# 或者: from twisted.web.iweb import IPolicyForHTTPS [as 别名]
def integrationTest(self, hostName, expectedAddress, addressType):
"""
Wrap L{AgentTestsMixin.integrationTest} with TLS.
"""
authority, server = certificatesForAuthorityAndServer(hostName
.decode('ascii'))
def tlsify(serverFactory):
return TLSMemoryBIOFactory(server.options(), False, serverFactory)
def tlsagent(reactor):
from twisted.web.iweb import IPolicyForHTTPS
from zope.interface import implementer
@implementer(IPolicyForHTTPS)
class Policy(object):
def creatorForNetloc(self, hostname, port):
return optionsForClientTLS(hostname.decode("ascii"),
trustRoot=authority)
return client.Agent(reactor, contextFactory=Policy())
(super(AgentHTTPSTests, self)
.integrationTest(hostName, expectedAddress, addressType,
serverWrapper=tlsify,
createAgent=tlsagent,
scheme=b'https'))
示例3: test_deprecatedDuckPolicy
# 需要导入模块: from twisted.web import iweb [as 别名]
# 或者: from twisted.web.iweb import IPolicyForHTTPS [as 别名]
def test_deprecatedDuckPolicy(self):
"""
Passing something that duck-types I{like} a L{web client context
factory <twisted.web.client.WebClientContextFactory>} - something that
does not provide L{IPolicyForHTTPS} - to L{Agent} emits a
L{DeprecationWarning} even if you don't actually C{import
WebClientContextFactory} to do it.
"""
def warnMe():
client.Agent(deterministicResolvingReactor(MemoryReactorClock()),
"does-not-provide-IPolicyForHTTPS")
warnMe()
warnings = self.flushWarnings([warnMe])
self.assertEqual(len(warnings), 1)
[warning] = warnings
self.assertEqual(warning['category'], DeprecationWarning)
self.assertEqual(
warning['message'],
"'does-not-provide-IPolicyForHTTPS' was passed as the HTTPS "
"policy for an Agent, but it does not provide IPolicyForHTTPS. "
"Since Twisted 14.0, you must pass a provider of IPolicyForHTTPS."
)
示例4: integrationTest
# 需要导入模块: from twisted.web import iweb [as 别名]
# 或者: from twisted.web.iweb import IPolicyForHTTPS [as 别名]
def integrationTest(self, hostName, expectedAddress, addressType):
"""
Wrap L{AgentTestsMixin.integrationTest} with TLS.
"""
certHostName = hostName.strip(b'[]')
authority, server = certificatesForAuthorityAndServer(certHostName
.decode('ascii'))
def tlsify(serverFactory):
return TLSMemoryBIOFactory(server.options(), False, serverFactory)
def tlsagent(reactor):
from twisted.web.iweb import IPolicyForHTTPS
from zope.interface import implementer
@implementer(IPolicyForHTTPS)
class Policy(object):
def creatorForNetloc(self, hostname, port):
return optionsForClientTLS(hostname.decode("ascii"),
trustRoot=authority)
return client.Agent(reactor, contextFactory=Policy())
(super(AgentHTTPSTests, self)
.integrationTest(hostName, expectedAddress, addressType,
serverWrapper=tlsify,
createAgent=tlsagent,
scheme=b'https'))
示例5: client_SSLCF
# 需要导入模块: from twisted.web import iweb [as 别名]
# 或者: from twisted.web.iweb import IPolicyForHTTPS [as 别名]
def client_SSLCF(self, certfile):
"""Return an IPolicyForHTTPS for verifiying tests' server cert.
Optionally configures a client cert.
"""
from twisted.internet.ssl import (
Certificate, PrivateCertificate, optionsForClientTLS)
from twisted.web.iweb import IPolicyForHTTPS
with open(self.servercert) as fp:
servercert = Certificate.loadPEM(fp.read())
if certfile:
with open(self.unauth_client) as fp:
unauth_client = PrivateCertificate.loadPEM(fp.read())
else:
unauth_client = None
@implementer(IPolicyForHTTPS)
class UnauthClientPolicyForHTTPS(object):
def creatorForNetloc(self, hostname, port):
return optionsForClientTLS(
hostname.decode('ascii'),
trustRoot=servercert,
clientCertificate=unauth_client)
return UnauthClientPolicyForHTTPS()
示例6: creatorForNetloc
# 需要导入模块: from twisted.web import iweb [as 别名]
# 或者: from twisted.web.iweb import IPolicyForHTTPS [as 别名]
def creatorForNetloc(self, hostname, port):
"""Implements the IPolicyForHTTPS interace so that this can be passed
directly to agents.
"""
return self.get_options(hostname)