From f1a7a0cee34c6bf999a614afd18ce483a5cecbda Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Wed, 18 Nov 2015 21:22:57 +0200 Subject: [PATCH] Print ssl warning on use, not on module import. --- wraptool.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wraptool.py b/wraptool.py index c37d08803..9d4ca9336 100755 --- a/wraptool.py +++ b/wraptool.py @@ -29,11 +29,12 @@ try: has_ssl = True API_ROOT = 'https://wrapdb.mesonbuild.com/v1/' except ImportError: - print('Warning: ssl not available, traffic not authenticated.', - file=sys.stderr) has_ssl = False API_ROOT = 'http://wrapdb.mesonbuild.com/v1/' + +ssl_warning_printed = False + from glob import glob wrapdb_certificate = '''-----BEGIN CERTIFICATE----- @@ -103,9 +104,14 @@ def build_ssl_context(): return ctx def open_wrapdburl(urlstring): + global ssl_warning_printed if has_ssl: return urllib.request.urlopen(urlstring, context=build_ssl_context()) else: + if not ssl_warning_printed: + print('Warning: ssl not available, traffic not authenticated.', + file=sys.stderr) + ssl_warning_printed = True return urllib.request.urlopen(urlstring) def get_result(urlstring):