From e554ef9c6d885da1c6f79e2a85d4f298c52bc28c Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Tue, 12 Feb 2019 14:24:20 +0000 Subject: [PATCH 1/5] added context as an argument for downloading --- openmc/_utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openmc/_utils.py b/openmc/_utils.py index d16f556231..4a2f548f6a 100644 --- a/openmc/_utils.py +++ b/openmc/_utils.py @@ -7,7 +7,7 @@ from urllib.request import urlopen _BLOCK_SIZE = 16384 -def download(url, checksum=None): +def download(url, checksum=None, context=None): """Download file from a URL Parameters @@ -16,6 +16,8 @@ def download(url, checksum=None): URL from which to download checksum : str or None MD5 checksum to check against + context : ssl.SSLContext instance or None + For example ssl._create_unverified_context() Returns ------- @@ -23,7 +25,7 @@ def download(url, checksum=None): Name of file written locally """ - req = urlopen(url) + req = urlopen(url, context=context) # Get file size from header file_size = req.length From 59501916ccfc2d979b55b1043aee23e354a469d0 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Tue, 12 Feb 2019 15:02:51 +0000 Subject: [PATCH 2/5] added **kwargs to allow flexible downloading --- openmc/_utils.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/openmc/_utils.py b/openmc/_utils.py index 4a2f548f6a..ee3f0d4932 100644 --- a/openmc/_utils.py +++ b/openmc/_utils.py @@ -7,7 +7,7 @@ from urllib.request import urlopen _BLOCK_SIZE = 16384 -def download(url, checksum=None, context=None): +def download(url, checksum=None, **kwargs): """Download file from a URL Parameters @@ -16,8 +16,11 @@ def download(url, checksum=None, context=None): URL from which to download checksum : str or None MD5 checksum to check against - context : ssl.SSLContext instance or None - For example ssl._create_unverified_context() + **kwargs : dict + Optional arguements passed to urlopen() + context: ssl.SSLContext object + Describes the various SSL options, + e.g. context=ssl._create_unverified_context() Returns ------- @@ -25,8 +28,8 @@ def download(url, checksum=None, context=None): Name of file written locally """ - req = urlopen(url, context=context) - + req = urlopen(url, **kwargs) + print(kwargs) # Get file size from header file_size = req.length From d2d30ae97db073de4fa37de783bb86aaf096dce8 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Tue, 12 Feb 2019 15:04:40 +0000 Subject: [PATCH 3/5] removed print statment not needed --- openmc/_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openmc/_utils.py b/openmc/_utils.py index ee3f0d4932..1f5632a8da 100644 --- a/openmc/_utils.py +++ b/openmc/_utils.py @@ -29,7 +29,6 @@ def download(url, checksum=None, **kwargs): """ req = urlopen(url, **kwargs) - print(kwargs) # Get file size from header file_size = req.length From 866e75a8413da9f284df400db1e0dc2b791429e9 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 13 Feb 2019 11:52:10 +0000 Subject: [PATCH 4/5] removed contex related comments --- openmc/_utils.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/openmc/_utils.py b/openmc/_utils.py index 1f5632a8da..e5fc4be991 100644 --- a/openmc/_utils.py +++ b/openmc/_utils.py @@ -17,10 +17,7 @@ def download(url, checksum=None, **kwargs): checksum : str or None MD5 checksum to check against **kwargs : dict - Optional arguements passed to urlopen() - context: ssl.SSLContext object - Describes the various SSL options, - e.g. context=ssl._create_unverified_context() + Keyword arguments passed to :func:urllib.request.urlopen Returns ------- From 02205aa336e2b8f869c1ec50efaee8a867ca8a8f Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 13 Feb 2019 11:53:50 +0000 Subject: [PATCH 5/5] reworded keword comments --- openmc/_utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openmc/_utils.py b/openmc/_utils.py index e5fc4be991..15781282c2 100644 --- a/openmc/_utils.py +++ b/openmc/_utils.py @@ -16,8 +16,7 @@ def download(url, checksum=None, **kwargs): URL from which to download checksum : str or None MD5 checksum to check against - **kwargs : dict - Keyword arguments passed to :func:urllib.request.urlopen + Keyword arguments passed to :func:urllib.request.urlopen Returns -------