comparison libervia/desktop_kivy/core/patches.py @ 493:b3cedbee561d

refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 18:26:16 +0200
parents cagou/core/patches.py@3c9ba4a694ef
children
comparison
equal deleted inserted replaced
492:5114bbb5daa3 493:b3cedbee561d
1 #!/usr/bin/env python3
2
3 #Libervia Desktop-Kivy
4 # Copyright (C) 2016-2021 Jérôme Poisson (goffi@goffi.org)
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
15
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 import urllib.request, urllib.error, urllib.parse
20 import ssl
21
22
23 def disable_tls_validation():
24 # allow to disable certificate validation
25 ctx_no_verify = ssl.create_default_context()
26 ctx_no_verify.check_hostname = False
27 ctx_no_verify.verify_mode = ssl.CERT_NONE
28
29 class HTTPSHandler(urllib.request.HTTPSHandler):
30 no_certificate_check = False
31
32 def __init__(self, *args, **kwargs):
33 urllib.request._HTTPSHandler_ori.__init__(self, *args, **kwargs)
34 if self.no_certificate_check:
35 self._context = ctx_no_verify
36
37 urllib.request._HTTPSHandler_ori = urllib.request.HTTPSHandler
38 urllib.request.HTTPSHandler = HTTPSHandler
39 urllib.request.HTTPSHandler.no_certificate_check = True