diff --git a/gertty/app.py b/gertty/app.py index 58c6797..99f0122 100644 --- a/gertty/app.py +++ b/gertty/app.py @@ -36,6 +36,7 @@ from gertty import mywid from gertty import palette from gertty import sync from gertty import search +from gertty import requestsexceptions from gertty.view import change_list as view_change_list from gertty.view import project_list as view_project_list from gertty.view import change as view_change @@ -207,6 +208,7 @@ class App(object): self.sync_pipe = self.loop.watch_pipe(self.refresh) self.error_queue = Queue.Queue() self.error_pipe = self.loop.watch_pipe(self._errorPipeInput) + self.logged_warnings = set() warnings.showwarning = self._showWarning @@ -469,7 +471,20 @@ class App(object): def _showWarning(self, message, category, filename, lineno, file=None, line=None): + # Don't display repeat warnings + if str(message) in self.logged_warnings: + return m = warnings.formatwarning(message, category, filename, lineno, line) + self.log.warning(m) + self.logged_warnings.add(str(message)) + # Log this warning, but never display it to the user; it is + # nearly un-actionable. + if category == requestsexceptions.InsecurePlatformWarning: + return + # Disable InsecureRequestWarning when certificate validation is disabled + if not self.config.verify_ssl: + if category == requestsexceptions.InsecureRequestWarning: + return self.error_queue.put(('Warning', m)) os.write(self.error_pipe, 'error\n') diff --git a/gertty/requestsexceptions.py b/gertty/requestsexceptions.py new file mode 100644 index 0000000..aefb002 --- /dev/null +++ b/gertty/requestsexceptions.py @@ -0,0 +1,29 @@ +# Copyright 2015 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +try: + from requests.packages.urllib3.exceptions import InsecurePlatformWarning +except ImportError: + try: + from urllib3.exceptions import InsecurePlatformWarning + except ImportError: + InsecurePlatformWarning = None + +try: + from requests.packages.urllib3.exceptions import InsecureRequestWarning +except ImportError: + try: + from urllib3.exceptions import InsecureRequestWarning + except ImportError: + InsecureRequestWarning = None diff --git a/gertty/sync.py b/gertty/sync.py index cd0882d..b4673fb 100644 --- a/gertty/sync.py +++ b/gertty/sync.py @@ -887,9 +887,6 @@ class Sync(object): self.log = logging.getLogger('gertty.sync') self.queue = MultiQueue([HIGH_PRIORITY, NORMAL_PRIORITY, LOW_PRIORITY]) self.result_queue = Queue.Queue() - # Disable InsecureRequestWarning when certificate validation is disabled - if not self.app.config.verify_ssl: - requests.packages.urllib3.disable_warnings() self.session = requests.Session() if self.app.config.auth_type == 'basic': authclass = requests.auth.HTTPBasicAuth