GeezerVison is showing github.com — Merge pull request #23 from jkseppan/fix_htpps_imread · matplotlib/matplotlib@cefa068
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -761,11 +761,18 @@ def is_url(filename): |
761 | 761 | return URL_REGEX.match(filename) is not None |
762 | 762 |
|
763 | 763 |
|
| 764 | +@functools.lru_cache() |
| 765 | +def _get_ssl_context(): |
| 766 | + import certifi |
| 767 | + import ssl |
| 768 | + return ssl.create_default_context(cafile=certifi.where()) |
| 769 | + |
| 770 | + |
764 | 771 | @contextlib.contextmanager |
765 | 772 | def _open_file_or_url(fname): |
766 | 773 | if not isinstance(fname, Path) and is_url(fname): |
767 | 774 | import urllib.request |
768 | | - with urllib.request.urlopen(fname) as f: |
| 775 | + with urllib.request.urlopen(fname, context=_get_ssl_context()) as f: |
769 | 776 | yield (line.decode('utf-8') for line in f) |
770 | 777 | else: |
771 | 778 | fname = os.path.expanduser(fname) |
|
Collapse file
Copy file name to clipboardExpand all lines: lib/matplotlib/image.py +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1475,7 +1475,8 @@ def imread(fname, format=None): |
1475 | 1475 | if len(parsed.scheme) > 1: # Pillow doesn't handle URLs directly. |
1476 | 1476 | # hide imports to speed initial import on systems with slow linkers |
1477 | 1477 | from urllib import request |
1478 | | - with request.urlopen(fname) as response: |
| 1478 | + with request.urlopen(fname, |
| 1479 | + context=mpl._get_ssl_context()) as response: |
1479 | 1480 | import io |
1480 | 1481 | try: |
1481 | 1482 | response.seek(0) |
|
Collapse file
Copy file name to clipboardExpand all lines: setup.py +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -278,6 +278,7 @@ def build_extensions(self): |
278 | 278 | "numpy>=1.15", |
279 | 279 | ], |
280 | 280 | install_requires=[ |
| 281 | + "certifi>=2020.06.20", |
281 | 282 | "cycler>=0.10", |
282 | 283 | "kiwisolver>=1.0.1", |
283 | 284 | "numpy>=1.16", |
|