comparison cagou/core/patches.py @ 312:772c170b47a9

Python3 port: /!\ Cagou now runs with Python 3.6+ Port has been done in the same way as for backend (check backend commit b2d067339de3 message for details).
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:14:22 +0200
parents b0461363bc65
children 4d660b252487
comparison
equal deleted inserted replaced
311:a0d978d3ce84 312:772c170b47a9
15 # GNU Affero General Public License for more details. 15 # GNU Affero General Public License for more details.
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 import urllib2 20 import urllib.request, urllib.error, urllib.parse
21 import ssl 21 import ssl
22 22
23 23
24 def apply(): 24 def apply():
25 # allow to disable certificate validation 25 # allow to disable certificate validation
26 ctx_no_verify = ssl.create_default_context() 26 ctx_no_verify = ssl.create_default_context()
27 ctx_no_verify.check_hostname = False 27 ctx_no_verify.check_hostname = False
28 ctx_no_verify.verify_mode = ssl.CERT_NONE 28 ctx_no_verify.verify_mode = ssl.CERT_NONE
29 29
30 class HTTPSHandler(urllib2.HTTPSHandler): 30 class HTTPSHandler(urllib.request.HTTPSHandler):
31 no_certificate_check = False 31 no_certificate_check = False
32 32
33 def __init__(self, *args, **kwargs): 33 def __init__(self, *args, **kwargs):
34 urllib2._HTTPSHandler_ori.__init__(self, *args, **kwargs) 34 urllib.request._HTTPSHandler_ori.__init__(self, *args, **kwargs)
35 if self.no_certificate_check: 35 if self.no_certificate_check:
36 self._context = ctx_no_verify 36 self._context = ctx_no_verify
37 37
38 urllib2._HTTPSHandler_ori = urllib2.HTTPSHandler 38 urllib.request._HTTPSHandler_ori = urllib.request.HTTPSHandler
39 urllib2.HTTPSHandler = HTTPSHandler 39 urllib.request.HTTPSHandler = HTTPSHandler
40 urllib2.HTTPSHandler.no_certificate_check = True 40 urllib.request.HTTPSHandler.no_certificate_check = True