Skip to content

Commit c149d4c

Browse files
author
Dorian Birraux
committed
Merge pull request #225 in LCL/wolframclientforpython from bugfix/383943-use-certifi-everywhere to master
* commit 'b6cc78c6c0e34dcccaaec0f8c97e09ffa59c243c': add test to ensure sslcontext is initialized correctly Warning should be displayed once and for all multithreading module does not exist remove useless pass increment version Update changelog aiohttp based classes now use certifi update ssl api
2 parents 73024d3 + b6cc78c commit c149d4c

9 files changed

Lines changed: 38 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Version 1.1.3
2+
- Async cloud evaluator based on `aiohttp` now use `certifi` to create a default `SSLContext` if none is provided. Other cloud evaluator are based on the `requests` module which also uses this library.
3+
- Updating dependency list accordingly in `setup.py`. `certifi` was already listed as a `requests` dependency, so this should have no direct impact on user site package.
4+
# Version 1.1.3
25
- Update asynchronous evaluator classes. Remove the `loop` parameter. Most optional loop parameters are deprecated in the Python standart library `asyncio` and in most libraries, mainly because it is misleading and lead to misuses and bugs. The loop parameter is useful when instantiating asynchronous evaluators outside the scope of an event loop. It's implementation was not good enough and was relying on usages deprecated in 3.8.
36
- Removing four asynchronous generators in asynchronous evaluation result classes: `iter_messages`, `iter_messages_name`, `iter_messages_tuple` and `iter_output`. These coroutines are only working on python 3.6+ and are not critical enough to drop support for 3.5. Asynchronous properties: `messages`, `messages_name` and `output` provide the same information.
47

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def load_tests():
6767
'aiohttp',
6868
'oauthlib',
6969
'pyzmq',
70+
'certifi>=2017.4.17' # for consistency with requests module.
7071
],
7172
classifiers = CLASSIFIERS,
7273
project_urls={

wolframclient/about.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
__name__ = "wolframclient"
44
__description__ = "A Python library with various tools to interact with the Wolfram Language and the Wolfram Cloud."
5-
__version__ = "1.1.3"
5+
__version__ = "1.1.4"
66
__author__ = "Wolfram Research"
77
__author_email__ = "support@wolfram.com, dorianb@wolfram.com, riccardod@wolfram.com"

wolframclient/evaluation/cloud/asynccloudsession.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
XAuthAIOHttpAsyncSession as XAuthAsyncSession,
1212
)
1313
from wolframclient.evaluation.cloud.base import WolframAPICallBase
14-
from wolframclient.evaluation.cloud.server import WOLFRAM_PUBLIC_CLOUD_SERVER
14+
from wolframclient.evaluation.cloud.server import WOLFRAM_PUBLIC_CLOUD_SERVER, DEFAULT_CA_PATH
1515
from wolframclient.evaluation.result import (
1616
WolframAPIResponseBuilder,
1717
WolframEvaluationWXFResponseAsync,
@@ -65,10 +65,12 @@ def __init__(
6565
if self.server.certificate is not None:
6666
self._ssl_context = self.ssl_context_class()
6767
self._ssl_context.load_verify_locations(self.server.certificate)
68-
# self._ssl_context = ssl.create_default_context(cafile=self.server.certificate)
68+
elif DEFAULT_CA_PATH:
69+
self._ssl_context = ssl.create_default_context(cafile=DEFAULT_CA_PATH)
6970
else:
7071
self._ssl_context = None
7172

73+
7274
def duplicate(self):
7375
return self.__class__(
7476
credentials=self.credentials,

wolframclient/evaluation/cloud/asyncoauth.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import absolute_import, print_function, unicode_literals
22

33
import logging
4-
54
from wolframclient.evaluation.cloud.base import OAuthAsyncSessionBase, UserIDPassword
5+
from wolframclient.evaluation.cloud.server import DEFAULT_CA_PATH
66
from wolframclient.exception import AuthenticationException
77
from wolframclient.utils import six
88
from wolframclient.utils.api import aiohttp, oauth, ssl
@@ -35,7 +35,8 @@ def __init__(
3535
if self.server.certificate is not None:
3636
self._ssl_context = self.ssl_context_class()
3737
self._ssl_context.load_verify_locations(self.server.certificate)
38-
# self._ssl_context = ssl.create_default_context(cafile=self.server.certificate)
38+
elif DEFAULT_CA_PATH:
39+
self._ssl_context = ssl.create_default_context(cafile=DEFAULT_CA_PATH)
3940
else:
4041
self._ssl_context = None
4142

wolframclient/evaluation/cloud/server.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
from __future__ import absolute_import, print_function, unicode_literals
22

33
from wolframclient.utils import six
4+
try:
5+
import certifi
6+
DEFAULT_CA_PATH = certifi.where()
7+
except ImportError:
8+
certifi = None
9+
DEFAULT_CA_PATH = None
410

5-
__all__ = ["WolframServer"]
11+
12+
__all__ = ["WolframServer", "DEFAULT_CA_PATH"]
613

714

815
class WolframServer(object):

wolframclient/tests/evaluation/test_async_cloud.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ async def test_bad_sak_with(self):
141141
) as cloud_session:
142142
cloud_session.authorized()
143143

144+
def test_sslcontext(self):
145+
from wolframclient.evaluation.cloud.server import DEFAULT_CA_PATH
146+
s = WolframCloudAsyncSession()
147+
if DEFAULT_CA_PATH is None:
148+
self.assertIsNone(s._ssl_context)
149+
else:
150+
self.assertIsNotNone(s._ssl_context)
151+
144152
@run_in_loop
145153
async def test_section_api_call_no_param(self):
146154
url = "api/private/requesterid"

wolframclient/utils/api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@
168168
StringPayload="aiohttp.StringPayload",
169169
)
170170

171-
ssl = API(SSLContext="ssl.SSLContext")
171+
ssl = API(
172+
SSLContext="ssl.SSLContext",
173+
create_default_context="ssl.create_default_context",
174+
)
172175

173176
externalevaluate = API(
174177
execute_from_file="wolframclient.utils.externalevaluate.execute_from_file",

wolframclient/utils/lock.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
import warnings
44

55
try:
6-
import multithreading
6+
import multiprocessing
77

8-
_lock = multithreading.Lock()
8+
_lock = multiprocessing.Lock()
99

1010
def Lock():
1111
return _lock
1212

1313

1414
except (ImportError, OSError):
1515

16-
# JYTHON is raising an ImportError when running "import multithreading"
17-
# GVisor is raising an OSError when running "multithreading.Lock()" because the feature is not implemented
16+
# JYTHON is raising an ImportError when running "import multiprocessing"
17+
# GVisor is raising an OSError when running "multiprocessing.Lock()" because the feature is not implemented
1818

1919
from contextlib import contextmanager
2020

21+
warnings.warn("Lock is not implemented in the current interpreter.", RuntimeWarning)
22+
2123
@contextmanager
2224
def Lock():
23-
warnings.warn("Lock is not implemented in the current interpreter.", RuntimeWarning)
2425
yield

0 commit comments

Comments
 (0)