ssl: extract function that returns dummycert path on Apple python
authorYuya Nishihara <yuya@tcha.org>
Wed, 04 Mar 2015 22:27:01 +0900
changeset 24288 922e087ba158
parent 24287 f78252429e0a
child 24289 07fafcd4bc74
ssl: extract function that returns dummycert path on Apple python This function will be the condition to switch DISABLEOSXDUMMYCERT in test-https.t.
mercurial/sslutil.py
--- a/mercurial/sslutil.py	Wed Mar 11 21:36:48 2015 -0700
+++ b/mercurial/sslutil.py	Wed Mar 04 22:27:01 2015 +0900
@@ -129,6 +129,13 @@
     return (exe.startswith('/usr/bin/python') or
             exe.startswith('/system/library/frameworks/python.framework/'))
 
+def _defaultcacerts():
+    if _plainapplepython():
+        dummycert = os.path.join(os.path.dirname(__file__), 'dummycert.pem')
+        if os.path.exists(dummycert):
+            return dummycert
+    return None
+
 def sslkwargs(ui, host):
     kws = {}
     hostfingerprint = ui.config('hostfingerprints', host)
@@ -139,9 +146,9 @@
         cacerts = util.expandpath(cacerts)
         if not os.path.exists(cacerts):
             raise util.Abort(_('could not find web.cacerts: %s') % cacerts)
-    elif cacerts is None and _plainapplepython():
-        dummycert = os.path.join(os.path.dirname(__file__), 'dummycert.pem')
-        if os.path.exists(dummycert):
+    elif cacerts is None:
+        dummycert = _defaultcacerts()
+        if dummycert:
             ui.debug('using %s to enable OS X system CA\n' % dummycert)
             ui.setconfig('web', 'cacerts', dummycert, 'dummy')
             cacerts = dummycert