[PATCH 2 of 5 V2] sslutil: use a dict for hanging hg state off the wrapped socket

Gregory Szorc gregory.szorc at gmail.com
Sun May 15 19:18:39 EDT 2016


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1463336707 25200
#      Sun May 15 11:25:07 2016 -0700
# Node ID 0a4ddbaae306c1e8a28abc37c54fe29f94042996
# Parent  56ceced54f4efb6da734e24af29b34d0aabc3d6c
sslutil: use a dict for hanging hg state off the wrapped socket

I plan on introducing more state on the socket instance. Instead
of using multiple variables, let's just use one to minimize risk
of name collision.

diff --git a/mercurial/sslutil.py b/mercurial/sslutil.py
--- a/mercurial/sslutil.py
+++ b/mercurial/sslutil.py
@@ -166,17 +166,19 @@ def wrapsocket(sock, keyfile, certfile, 
 
     sslsocket = sslcontext.wrap_socket(sock, server_hostname=serverhostname)
     # check if wrap_socket failed silently because socket had been
     # closed
     # - see http://bugs.python.org/issue13721
     if not sslsocket.cipher():
         raise error.Abort(_('ssl connection failed'))
 
-    sslsocket._hgcaloaded = caloaded
+    sslsocket._hgstate = {
+        'caloaded': caloaded,
+    }
 
     return sslsocket
 
 def _verifycert(cert, hostname):
     '''Verify that cert (in socket.getpeercert() format) matches hostname.
     CRLs is not handled.
 
     Returns error message if any problems are found and None on success.
@@ -336,17 +338,17 @@ class validator(object):
         # the same as below for BC.
         if self.ui.insecureconnections:
             self.ui.warn(_('warning: %s certificate with fingerprint %s not '
                            'verified (check hostfingerprints or web.cacerts '
                            'config setting)\n') %
                          (host, nicefingerprint))
             return
 
-        if not sock._hgcaloaded:
+        if not sock._hgstate['caloaded']:
             if strict:
                 raise error.Abort(_('%s certificate with fingerprint %s not '
                                     'verified') % (host, nicefingerprint),
                                   hint=_('check hostfingerprints or '
                                          'web.cacerts config setting'))
             else:
                 self.ui.warn(_('warning: %s certificate with fingerprint %s '
                                'not verified (check hostfingerprints or '


More information about the Mercurial-devel mailing list