Skip to content

Commit 2c9366c

Browse files
author
Dorian Birraux
committed
Merge branch 'master' into feature/better-read-write-performances
# Conflicts: # wolframclient/utils/externalevaluate.py
2 parents 0cf5ab4 + 709d785 commit 2c9366c

16 files changed

Lines changed: 84 additions & 39 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ wolframclient/tests/local_config.json
99
.coverage
1010
.vscode
1111
*.code-workspace
12-
/test-reports
12+
/test-reports
13+
.DS_Store

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"Programming Language :: Python :: 3.5",
2727
"Programming Language :: Python :: 3.6",
2828
"Programming Language :: Python :: 3.7",
29-
"Topic :: Software Development :: Libraries :: Wolfram Language Library"
29+
"Topic :: Software Development :: Libraries"
3030
]
3131

3232

@@ -66,6 +66,7 @@ def load_tests():
6666
'oauthlib',
6767
'zmq',
6868
],
69+
classifiers = CLASSIFIERS,
6970
project_urls={
7071
'Source code': 'https://github.com/WolframResearch/WolframClientForPython',
7172
'Documentation': 'https://wolfr.am/wolframclientdoc',

wolframclient/evaluation/cloud/asynccloudsession.py

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

3+
import json
34
import logging
45

56
from wolframclient.evaluation.base import WolframAsyncEvaluator
@@ -260,7 +261,7 @@ async def perform(self, **kwargs):
260261
# formatting for http requests, based on aiohttp objects.
261262

262263

263-
def _encode_inputs_as_wxf(inputs, multipart, **kwargs):
264+
def _encode_inputs_as_wxf(form_data, inputs, **kwargs):
264265
for name, value in inputs.items():
265266
form_data.add_field(name + "__wxf", export(value, target_format="wxf", **kwargs))
266267

wolframclient/evaluation/cloud/oauth.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,18 @@ def __init__(
192192

193193
def authenticate(self):
194194
if logger.isEnabledFor(logging.DEBUG):
195-
logger.debug("xauth authentication of user %s", user)
195+
logger.debug("xauth authentication of user %s", self.xauth_credentials.user)
196196
if not self.server.is_xauth():
197197
raise AuthenticationException(
198198
"XAuth is not configured. Missing consumer key and/or secret."
199199
)
200200
# todo use xauth server key/secret
201201
client = self.client_class(self.consumer_key, self.consumer_secret)
202-
params = {}
203-
params["x_auth_username"] = self.xauth_credentials.user
204-
params["x_auth_password"] = self.xauth_credentials.password
205-
params["x_auth_mode"] = "client_auth"
202+
params = {
203+
"x_auth_username": self.xauth_credentials.user,
204+
"x_auth_password": self.xauth_credentials.password,
205+
"x_auth_mode": "client_auth"
206+
}
206207

207208
# avoid dumping password in log files.
208209
logging.disable(logging.DEBUG)

wolframclient/evaluation/kernel/initkernel.m

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,16 @@ no matter the total size (tested with 80MB) *)
150150
socketEventHandler[data_] := Block[
151151
{expr},
152152
ClientLibrary`debug["Evaluating a new expression."];
153-
expr = EvaluationData[BinarySerialize[BinaryDeserialize[data]]];
153+
expr = EvaluationData[BinaryDeserialize[data]];
154154
(* Produce inline InputForm string messages. *)
155155
AssociateTo[
156-
expr,
157-
"MessagesText" -> Map[
158-
fmtmsg,
159-
expr["MessagesExpressions"]
160-
]
156+
expr, {
157+
"Result" -> BinarySerialize[expr["Result"]],
158+
"MessagesText" -> Map[
159+
fmtmsg,
160+
expr["MessagesExpressions"]
161+
]
162+
}
161163
];
162164
ClientLibrary`debug["Done evaluating."];
163165
SocketWriteByteArrayFunc[
@@ -167,7 +169,6 @@ no matter the total size (tested with 80MB) *)
167169
ClientLibrary`debug["Done responding."];
168170
];
169171

170-
171172
SendAck[] := WriteString[$OutputSocket, "OK"]
172173

173174
$MaxIdlePause=.001;

wolframclient/evaluation/pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(
7373
):
7474
super().__init__(loop)
7575
if poolsize <= 0:
76-
raise ValueError("Invalid pool size value %i. Expecting a positive integer." % i)
76+
raise ValueError("Invalid pool size value %i. Expecting a positive integer." % poolsize)
7777
self._queue = asyncio.Queue(load_factor * poolsize, loop=self._loop)
7878
self.async_language_session_class = async_language_session_class
7979
self._evaluators = set()

wolframclient/exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, response, msg=None):
1414
else:
1515
try:
1616
self.msg = response.text()
17-
except UnicodeDecodeErrors:
17+
except UnicodeDecodeError:
1818
self.msg = "Failed to decode request body."
1919

2020
def __str__(self):

wolframclient/language/traceback.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ def _get_lines_from_file(filename, lineno, context_lines, loader=None, module_na
236236
break
237237
source = [force_text(sline, encoding, "replace") for sline in source]
238238

239+
lineno = min(lineno, len(source) - 1)
239240
lower_bound = max(0, lineno - context_lines)
240241
upper_bound = lineno + context_lines
241242

wolframclient/serializers/base.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,22 @@ def serialize_tzinfo(
134134
def _serialize_external_object(self, o):
135135

136136
yield "System", "Python"
137-
yield "Type", "PythonFunction"
137+
138+
if callable(o):
139+
yield "Type", "PythonFunction"
140+
try:
141+
# force tuple to avoid calling this method again on `map`.
142+
yield "Arguments", tuple(map(force_text, first(inspect.getfullargspec(o))))
143+
except TypeError:
144+
# this function can fail with TypeError unsupported callable
145+
pass
146+
else:
147+
yield "Type", "PythonObject"
138148

139149
if hasattr(o, "__name__"):
140-
yield "Name", force_text(o.__name__)
150+
yield "Command", force_text(o.__name__)
141151
else:
142-
yield "Name", force_text(o.__class__.__name__)
152+
yield "Command", force_text(o.__class__.__name__)
143153

144154
is_module = inspect.ismodule(o)
145155

@@ -155,12 +165,7 @@ def _serialize_external_object(self, o):
155165
yield "IsMethod", inspect.ismethod(o),
156166
yield "IsCallable", callable(o),
157167

158-
if callable(o):
159-
try:
160-
yield "Arguments", map(force_text, first(inspect.getargspec(o)))
161-
except TypeError:
162-
# this function can fail with TypeError unsupported callable
163-
pass
168+
164169

165170
def serialize_external_object(self, obj):
166171
return self.serialize_function(

wolframclient/serializers/encoder.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,13 @@ def update_dispatch(self):
100100

101101
@wolfram_encoder.dispatch(object)
102102
def encode(serializer, o):
103-
if is_iterable(o):
104-
return serializer.serialize_iterable(map(serializer.encode, o), length=safe_len(o))
103+
105104
if serializer.allow_external_objects:
106105
return serializer.serialize_external_object(o)
107106

107+
if is_iterable(o):
108+
return serializer.serialize_iterable(map(serializer.encode, o), length=safe_len(o))
109+
108110
raise NotImplementedError("Cannot serialize object of class %s" % o.__class__)
109111

110112

0 commit comments

Comments
 (0)