Patchwork [3,of,6] sslutil: use a dict for hanging hg state off the wrapped socket

login
register
mail settings
Submitter Gregory Szorc
Date May 15, 2016, 6:57 p.m.
Message ID <f139b7d229a5d0d99c8d.1463338640@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/15120/
State Superseded
Headers show

Comments

Gregory Szorc - May 15, 2016, 6:57 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1463336707 25200
#      Sun May 15 11:25:07 2016 -0700
# Node ID f139b7d229a5d0d99c8d372e81ffaa053b3c3f77
# Parent  41885a60598f5d03437d8e481d48b45d411614a1
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.

Patch

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 '