diff options
author | Benjamin Peterson <benjamin@python.org> | 2014-11-24 02:38:13 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2014-11-24 02:38:13 (GMT) |
commit | 6c22e65773c94ff810bd7adbb43c2b52e269598a (patch) | |
tree | 30307d736adb065bbe175560f7d6f8528d552673 /Lib | |
parent | 83711e9bdf47d020d44997b74e1d24995130b992 (diff) | |
parent | 43052a14c1412893ae76253f1323a41769d09b07 (diff) | |
download | cpython-6c22e65773c94ff810bd7adbb43c2b52e269598a.zip cpython-6c22e65773c94ff810bd7adbb43c2b52e269598a.tar.gz cpython-6c22e65773c94ff810bd7adbb43c2b52e269598a.tar.bz2 |
merge 3.4 (#22788)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/logging/handlers.py | 9 | ||||
-rw-r--r-- | Lib/test/test_logging.py | 19 |
2 files changed, 12 insertions, 16 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 43cbb55..c67ac99 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -1089,7 +1089,8 @@ class HTTPHandler(logging.Handler): A class which sends records to a Web server, using either GET or POST semantics. """ - def __init__(self, host, url, method="GET", secure=False, credentials=None): + def __init__(self, host, url, method="GET", secure=False, credentials=None, + context=None): """ Initialize the instance with the host, the request URL, and the method ("GET" or "POST") @@ -1098,11 +1099,15 @@ class HTTPHandler(logging.Handler): method = method.upper() if method not in ["GET", "POST"]: raise ValueError("method must be GET or POST") + if not secure and context is not None: + raise ValueError("context parameter only makes sense " + "with secure=True") self.host = host self.url = url self.method = method self.secure = secure self.credentials = credentials + self.context = context def mapLogRecord(self, record): """ @@ -1122,7 +1127,7 @@ class HTTPHandler(logging.Handler): import http.client, urllib.parse host = self.host if self.secure: - h = http.client.HTTPSConnection(host) + h = http.client.HTTPSConnection(host, context=self.context) else: h = http.client.HTTPConnection(host) url = self.url diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index c875e55..99b32c9 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -1663,21 +1663,11 @@ class HTTPHandlerTest(BaseTest): localhost_cert = os.path.join(here, "keycert.pem") sslctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) sslctx.load_cert_chain(localhost_cert) - # Unfortunately, HTTPHandler doesn't allow us to change the - # SSLContext used by HTTPSConnection, so we have to - # monkeypatch. This can be cleaned up if issue 22788 is - # fixed. - old = ssl._create_default_https_context - def restore_handler(): - ssl._create_default_https_context = old - self.addCleanup(restore_handler) - def hack_create_ctx(): - ctx = old() - ctx.load_verify_locations(localhost_cert) - return ctx - ssl._create_default_https_context = hack_create_ctx + + context = ssl.create_default_context(cafile=localhost_cert) else: sslctx = None + context = None self.server = server = TestHTTPServer(addr, self.handle_request, 0.01, sslctx=sslctx) server.start() @@ -1685,7 +1675,8 @@ class HTTPHandlerTest(BaseTest): host = 'localhost:%d' % server.server_port secure_client = secure and sslctx self.h_hdlr = logging.handlers.HTTPHandler(host, '/frob', - secure=secure_client) + secure=secure_client, + context=context) self.log_data = None root_logger.addHandler(self.h_hdlr) |