Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
no longer use SSLContext
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed May 5, 2022
1 parent eb1a786 commit 93e7f60
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/sage/arith/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,7 @@ def xkcd(n=""):
import contextlib
import json
from sage.misc.html import html
from ssl import SSLContext
from ssl import create_default_context as default_context

from urllib.request import urlopen
from urllib.error import HTTPError, URLError
Expand All @@ -2046,7 +2046,7 @@ def xkcd(n=""):
url = "https://xkcd.com/{}/info.0.json".format(n)

try:
with contextlib.closing(urlopen(url, context=SSLContext())) as f:
with contextlib.closing(urlopen(url, context=default_context())) as f:
data = f.read()
except HTTPError as error:
if error.getcode() == 400: # this error occurs when asking for a non valid comic number
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/designs/covering_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# ****************************************************************************

from urllib.request import urlopen
from ssl import SSLContext
from ssl import create_default_context as default_context

from sage.misc.sage_eval import sage_eval
from sage.structure.sage_object import SageObject
Expand Down Expand Up @@ -529,7 +529,7 @@ def best_known_covering_design_www(v, k, t, verbose=False):
if verbose:
print("Looking up the bounds at %s" % url)

f = urlopen(url, context=SSLContext())
f = urlopen(url, context=default_context())
try:
s = bytes_to_str(f.read())
finally:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/databases/oeis.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
# ****************************************************************************
from urllib.request import urlopen
from urllib.parse import urlencode
from ssl import SSLContext
from ssl import create_default_context as default_context

from sage.structure.sage_object import SageObject
from sage.structure.unique_representation import UniqueRepresentation
Expand Down Expand Up @@ -200,7 +200,7 @@ def _fetch(url):
"""
try:
verbose("Fetching URL %s ..." % url, caller_name='OEIS')
f = urlopen(url, context=SSLContext())
f = urlopen(url, context=default_context())
result = f.read()
f.close()
return bytes_to_str(result)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/databases/sloane.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def install(self, oeis_url="https://oeis.org/stripped.gz",
raise IOError("Sloane encyclopedia is already installed")

tm = verbose("Downloading stripped version of Sloane encyclopedia")
ssl._create_default_https_context = ssl.SSLContext
ssl._create_default_https_context = ssl.create_default_context
try:
fname, _ = urlretrieve(oeis_url)
except IOError as msg:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/features/internet.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def _is_present(self):
"""
import urllib.error
from urllib.request import Request, urlopen
from ssl import SSLContext
from ssl import create_default_context as default_context

req = Request("https://www.sagemath.org", headers={"User-Agent": "sage-doctest"})
try:
urlopen(req, timeout=1, context=SSLContext())
urlopen(req, timeout=1, context=default_context())
return FeatureTestResult(self, True)
except urllib.error.URLError:
return FeatureTestResult(self, False)
Expand Down
6 changes: 3 additions & 3 deletions src/sage/graphs/isgci.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,7 @@ class is defined by the exclusion of subgraphs, one can write a generic
import os
import zipfile
from urllib.request import urlopen
from ssl import SSLContext

from ssl import create_default_context as default_context

#*****************************************************************************
# Copyright (C) 2011 Nathann Cohen <[email protected]>
Expand Down Expand Up @@ -828,7 +827,8 @@ def _download_db(self):
sage: graph_classes._download_db() # Not tested -- requires internet
"""
from sage.misc.misc import SAGE_TMP
u = urlopen('https://www.graphclasses.org/data.zip', context=SSLContext())
u = urlopen('https://www.graphclasses.org/data.zip',
context=default_context())
localFile = open(os.path.join(SAGE_TMP, 'isgci.zip'), 'w')
localFile.write(u.read())
localFile.close()
Expand Down
5 changes: 3 additions & 2 deletions src/sage/interfaces/mathematica.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,11 +1140,12 @@ def request_wolfram_alpha(input, verbose=False):
from urllib.request import Request, build_opener, HTTPCookieProcessor, HTTPSHandler
import json
from http.cookiejar import CookieJar
from ssl import SSLContext
from ssl import create_default_context as default_context

# we need cookies for this...
cj = CookieJar()
opener = build_opener(HTTPCookieProcessor(cj), HTTPSHandler(context=SSLContext()))
opener = build_opener(HTTPCookieProcessor(cj),
HTTPSHandler(context=default_context()))
# build initial query for code
req = Request("https://www.wolframalpha.com/input/api/v1/code")
resp = opener.open(req)
Expand Down
5 changes: 3 additions & 2 deletions src/sage/misc/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import http.client as httplib
from urllib.parse import urlencode
from ssl import SSLContext
from ssl import create_default_context as default_context

pushover_defaults = {"token": "Eql67F14ohOZJ0AtEBJJU7FiLAk8wK"}

Expand Down Expand Up @@ -77,7 +77,8 @@ def pushover(message, **kwds):
request.update(pushover_defaults)
request.update(kwds)

conn = httplib.HTTPSConnection("api.pushover.net:443", context=SSLContext())
conn = httplib.HTTPSConnection("api.pushover.net:443",
context=default_context())
conn.request("POST", "/1/messages.json",
urlencode(request),
{"Content-type": "application/x-www-form-urlencoded"})
Expand Down
4 changes: 2 additions & 2 deletions src/sage/misc/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from pathlib import Path
from urllib.request import urlopen
from urllib.error import URLError
from ssl import SSLContext
from ssl import create_default_context as default_context

DEFAULT_PYPI = 'https://pypi.org/pypi'

Expand Down Expand Up @@ -110,7 +110,7 @@ def pip_remote_version(pkg, pypi_url=DEFAULT_PYPI, ignore_URLError=False):
url = '{pypi_url}/{pkg}/json'.format(pypi_url=pypi_url, pkg=pkg)

try:
f = urlopen(url, context=SSLContext())
f = urlopen(url, context=default_context())
text = f.read()
f.close()
except URLError:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/misc/remote_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import os
from urllib.request import Request, urlopen
from ssl import SSLContext
from ssl import create_default_context as default_context


def get_remote_file(filename, verbose=True):
Expand Down Expand Up @@ -43,7 +43,7 @@ def get_remote_file(filename, verbose=True):
if verbose:
print("Loading started")

content = urlopen(req, timeout=1, context=SSLContext())
content = urlopen(req, timeout=1, context=default_context())
with open(temp_name, 'wb') as f:
f.write(content.read())

Expand Down

0 comments on commit 93e7f60

Please sign in to comment.