[pypy-commit] pypy stdlib-2.7.9: add SSLSocket.context property

amauryfa noreply at buildbot.pypy.org
Sat Jan 31 00:45:10 CET 2015


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: stdlib-2.7.9
Changeset: r75591:2a8d2a10cc88
Date: 2015-01-26 09:03 +0100
http://bitbucket.org/pypy/pypy/changeset/2a8d2a10cc88/

Log:	add SSLSocket.context property

diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -9,7 +9,7 @@
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.error import OperationError, oefmt, wrap_oserror
 from pypy.interpreter.gateway import interp2app, unwrap_spec
-from pypy.interpreter.typedef import TypeDef, GetSetProperty
+from pypy.interpreter.typedef import TypeDef, GetSetProperty, interp_attrproperty_w
 from pypy.module._ssl.ssl_data import (
     LIBRARY_CODES_TO_NAMES, ERROR_CODES_TO_NAMES)
 from pypy.module._socket import interp_socket
@@ -211,17 +211,17 @@
 
 class _SSLSocket(W_Root):
     @staticmethod
-    def descr_new(space, sslctx, w_sock, socket_type, hostname, w_ssl_sock):
+    def descr_new(space, w_ctx, w_sock, socket_type, hostname, w_ssl_sock):
         self = _SSLSocket()
 
         self.space = space
-        self.ctx = sslctx
+        self.w_ctx = w_ctx
         self.peer_cert = lltype.nullptr(X509.TO)
         self.shutdown_seen_zero = False
         self.handshake_done = False
 
         sock_fd = space.int_w(space.call_method(w_sock, "fileno"))
-        self.ssl = libssl_SSL_new(sslctx.ctx)  # new ssl struct
+        self.ssl = libssl_SSL_new(w_ctx.ctx)  # new ssl struct
         libssl_SSL_set_fd(self.ssl, sock_fd)  # set the socket for SSL
         # The ACCEPT_MOVING_WRITE_BUFFER flag is necessary because the address
         # of a str object may be changed by the garbage collector.
@@ -606,6 +606,7 @@
     compression = interp2app(_SSLSocket.compression_w),
     version = interp2app(_SSLSocket.version_w),
     tls_unique_cb = interp2app(_SSLSocket.tls_unique_cb_w),
+    context=interp_attrproperty_w("w_ctx", _SSLSocket),
 )
 
 
diff --git a/pypy/module/_ssl/test/test_ssl.py b/pypy/module/_ssl/test/test_ssl.py
--- a/pypy/module/_ssl/test/test_ssl.py
+++ b/pypy/module/_ssl/test/test_ssl.py
@@ -73,7 +73,9 @@
         if sys.version_info < (2, 7, 9):
             ss = _ssl.sslwrap(s, 0)
         else:
-            ss = _ssl._SSLContext(_ssl.PROTOCOL_TLSv1)._wrap_socket(s, 0)
+            ctx = _ssl._SSLContext(_ssl.PROTOCOL_TLSv1)
+            ss = ctx._wrap_socket(s, 0)
+            assert ss.context is ctx
         exc = raises(_socket.error, ss.do_handshake)
         if sys.platform == 'win32':
             assert exc.value.errno == 10057 # WSAENOTCONN


More information about the pypy-commit mailing list