Skip to content

Commit b376a8d

Browse files
author
Release Manager
committed
Trac #33771: SSLContext needs an argument
with python 3.10, one sees a deprecation {{{ sage: oeis([5,21,84,330]) .../sage/local/var/lib/sage/venv-python3.10/lib/python3.10/site- packages/sage/databases/oeis.py:203: DeprecationWarning: ssl.SSLContext() without protocol argument is deprecated. f = urlopen(url, context=SSLContext()) .../sage/local/var/lib/sage/venv-python3.10/lib/python3.10/site- packages/sage/databases/oeis.py:203: DeprecationWarning: ssl.PROTOCOL_TLS is deprecated f = urlopen(url, context=SSLContext()) 0: A002054: Binomial coefficient C(2n+1, n-1). 1: A289797: p-INVERT of the triangular numbers (A000217), where p(S) = 1 - S - S^2. 2: A284911: Number of partitions of n^2 that are the sum of n not necessarily distinct partitions of n into distinct parts. }}} URL: https://trac.sagemath.org/33771 Reported by: chapoton Ticket author(s): Frédéric Chapoton Reviewer(s): Thierry Monteil
2 parents df168c8 + 93e7f60 commit b376a8d

File tree

10 files changed

+22
-20
lines changed

10 files changed

+22
-20
lines changed

src/sage/arith/misc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2033,7 +2033,7 @@ def xkcd(n=""):
20332033
import contextlib
20342034
import json
20352035
from sage.misc.html import html
2036-
from ssl import SSLContext
2036+
from ssl import create_default_context as default_context
20372037

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

20482048
try:
2049-
with contextlib.closing(urlopen(url, context=SSLContext())) as f:
2049+
with contextlib.closing(urlopen(url, context=default_context())) as f:
20502050
data = f.read()
20512051
except HTTPError as error:
20522052
if error.getcode() == 400: # this error occurs when asking for a non valid comic number

src/sage/combinat/designs/covering_design.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
# ****************************************************************************
4747

4848
from urllib.request import urlopen
49-
from ssl import SSLContext
49+
from ssl import create_default_context as default_context
5050

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

532-
f = urlopen(url, context=SSLContext())
532+
f = urlopen(url, context=default_context())
533533
try:
534534
s = bytes_to_str(f.read())
535535
finally:

src/sage/databases/oeis.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
# ****************************************************************************
161161
from urllib.request import urlopen
162162
from urllib.parse import urlencode
163-
from ssl import SSLContext
163+
from ssl import create_default_context as default_context
164164

165165
from sage.structure.sage_object import SageObject
166166
from sage.structure.unique_representation import UniqueRepresentation
@@ -200,7 +200,7 @@ def _fetch(url):
200200
"""
201201
try:
202202
verbose("Fetching URL %s ..." % url, caller_name='OEIS')
203-
f = urlopen(url, context=SSLContext())
203+
f = urlopen(url, context=default_context())
204204
result = f.read()
205205
f.close()
206206
return bytes_to_str(result)

src/sage/databases/sloane.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def install(self, oeis_url="https://oeis.org/stripped.gz",
202202
raise IOError("Sloane encyclopedia is already installed")
203203

204204
tm = verbose("Downloading stripped version of Sloane encyclopedia")
205-
ssl._create_default_https_context = ssl.SSLContext
205+
ssl._create_default_https_context = ssl.create_default_context
206206
try:
207207
fname, _ = urlretrieve(oeis_url)
208208
except IOError as msg:

src/sage/features/internet.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def _is_present(self):
4040
"""
4141
import urllib.error
4242
from urllib.request import Request, urlopen
43-
from ssl import SSLContext
43+
from ssl import create_default_context as default_context
4444

4545
req = Request("https://www.sagemath.org", headers={"User-Agent": "sage-doctest"})
4646
try:
47-
urlopen(req, timeout=1, context=SSLContext())
47+
urlopen(req, timeout=1, context=default_context())
4848
return FeatureTestResult(self, True)
4949
except urllib.error.URLError:
5050
return FeatureTestResult(self, False)

src/sage/graphs/isgci.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,7 @@ class is defined by the exclusion of subgraphs, one can write a generic
400400
import os
401401
import zipfile
402402
from urllib.request import urlopen
403-
from ssl import SSLContext
404-
403+
from ssl import create_default_context as default_context
405404

406405
#*****************************************************************************
407406
# Copyright (C) 2011 Nathann Cohen <[email protected]>
@@ -828,7 +827,8 @@ def _download_db(self):
828827
sage: graph_classes._download_db() # Not tested -- requires internet
829828
"""
830829
from sage.misc.misc import SAGE_TMP
831-
u = urlopen('https://www.graphclasses.org/data.zip', context=SSLContext())
830+
u = urlopen('https://www.graphclasses.org/data.zip',
831+
context=default_context())
832832
localFile = open(os.path.join(SAGE_TMP, 'isgci.zip'), 'w')
833833
localFile.write(u.read())
834834
localFile.close()

src/sage/interfaces/mathematica.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1140,11 +1140,12 @@ def request_wolfram_alpha(input, verbose=False):
11401140
from urllib.request import Request, build_opener, HTTPCookieProcessor, HTTPSHandler
11411141
import json
11421142
from http.cookiejar import CookieJar
1143-
from ssl import SSLContext
1143+
from ssl import create_default_context as default_context
11441144

11451145
# we need cookies for this...
11461146
cj = CookieJar()
1147-
opener = build_opener(HTTPCookieProcessor(cj), HTTPSHandler(context=SSLContext()))
1147+
opener = build_opener(HTTPCookieProcessor(cj),
1148+
HTTPSHandler(context=default_context()))
11481149
# build initial query for code
11491150
req = Request("https://www.wolframalpha.com/input/api/v1/code")
11501151
resp = opener.open(req)

src/sage/misc/messaging.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import http.client as httplib
1616
from urllib.parse import urlencode
17-
from ssl import SSLContext
17+
from ssl import create_default_context as default_context
1818

1919
pushover_defaults = {"token": "Eql67F14ohOZJ0AtEBJJU7FiLAk8wK"}
2020

@@ -77,7 +77,8 @@ def pushover(message, **kwds):
7777
request.update(pushover_defaults)
7878
request.update(kwds)
7979

80-
conn = httplib.HTTPSConnection("api.pushover.net:443", context=SSLContext())
80+
conn = httplib.HTTPSConnection("api.pushover.net:443",
81+
context=default_context())
8182
conn.request("POST", "/1/messages.json",
8283
urlencode(request),
8384
{"Content-type": "application/x-www-form-urlencoded"})

src/sage/misc/package.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
from pathlib import Path
5252
from urllib.request import urlopen
5353
from urllib.error import URLError
54-
from ssl import SSLContext
54+
from ssl import create_default_context as default_context
5555

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

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

112112
try:
113-
f = urlopen(url, context=SSLContext())
113+
f = urlopen(url, context=default_context())
114114
text = f.read()
115115
f.close()
116116
except URLError:

src/sage/misc/remote_file.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import os
55
from urllib.request import Request, urlopen
6-
from ssl import SSLContext
6+
from ssl import create_default_context as default_context
77

88

99
def get_remote_file(filename, verbose=True):
@@ -43,7 +43,7 @@ def get_remote_file(filename, verbose=True):
4343
if verbose:
4444
print("Loading started")
4545

46-
content = urlopen(req, timeout=1, context=SSLContext())
46+
content = urlopen(req, timeout=1, context=default_context())
4747
with open(temp_name, 'wb') as f:
4848
f.write(content.read())
4949

0 commit comments

Comments
 (0)