wolframclient.utils package¶
Submodules¶
wolframclient.utils.api module¶
wolframclient.utils.asyncio module¶
wolframclient.utils.datastructures module¶
-
class
wolframclient.utils.datastructures.
Association
[source]¶ Bases:
collections.OrderedDict
A
OrderedDict
that serializes to an Association
-
class
wolframclient.utils.datastructures.
Settings
[source]¶ Bases:
dict
Dictionary subclass enabling attribute lookup/assignment of keys/values.
For example:
>>> m = Settings({'foo': 'bar'}) >>> m.foo 'bar' >>> m.foo = 'not bar' >>> m['foo'] 'not bar'
Settings
objects also provide.first()
which acts like.get()
but accepts multiple keys as arguments, and returns the value of the first hit, e.g.:>>> m = Settings({'foo': 'bar', 'biz': 'baz'}) >>> m.first('wrong', 'incorrect', 'foo', 'biz') 'bar'
wolframclient.utils.debug module¶
wolframclient.utils.decorators module¶
-
class
wolframclient.utils.decorators.
cached_property
(func, name=None)[source]¶ Bases:
object
Decorator that converts a method with a single self argument into a property cached on the instance.
Optional
name
argument allows you to make cached properties of other methods. (e.g. url = cached_property(get_absolute_url, name=’url’) )
-
wolframclient.utils.decorators.
to_dict
(fn)¶
-
wolframclient.utils.decorators.
to_tuple
(fn)¶
wolframclient.utils.dispatch module¶
-
class
wolframclient.utils.dispatch.
Dispatch
[source]¶ Bases:
object
A method dispatcher class allowing for multiple implementations of a function. Each implementation is associated to a specific input type.
Implementations are registered with the annotation
dispatch()
.The Dispatch class is callable, it behaves as a function that uses the implementation corresponding to the input parameter.
When a type is a subtype, the type and its parents are checked in the order given by
__mro__
(method resolution order).Example: method
resolve()
applied to an instance ofcollections.OrderedDict
, check for the first implementation to match withcollections.OrderedDict
, then withdict
, and ultimately toobject
.Once the mapping is determined, it is cached for later use.
-
as_method
()[source]¶ Return the dispatch as a class method.
Create a new dispatcher:
dispatch = Dispatcher()
Use the dispatcher as a class method:
class MyClass(object): myMethod = dispatch.as_method()
Call the class method:
o = MyClass() o.myMethod(arg, *args, **kwargs)
-
dispatch
(*args, **opts)[source]¶ Annotate a function and map it to a given set of type(s).
Declare an implementation to use on
bytearray
input:@dispatcher.dispatch(bytearray) def my_func(...)
The default implementation is associated with
object
. Set a default:@dispatcher.dispatch(object) def my_default_func(...)
A tuple can be used as input to associate more than one type with a function. Declare a function used for both
bytes
andbytearray
:@dispatcher.dispatch((bytes, bytearray)) def my_func(...)
Implementation must be unique. By default, registering the same combination of types will raise an error. Set replace_existing to
True
to update the current mapping. Or, set keep_existing toTrue
to ignore duplicate registration and keep the existing mapping.
-
register
(function, types=<class 'object'>, keep_existing=False, replace_existing=False)[source]¶ Equivalent to annotation
dispatch()
but as a function.
-
update
(dispatch, **opts)[source]¶ Update current mapping with the one from dispatch.
dispatch can be a Dispatch instance or a
dict
. **opts are passed toregister()
-
wolframclient.utils.encoding module¶
-
wolframclient.utils.encoding.
concatenate_bytes
()¶ Concatenate any number of bytes objects.
The bytes whose method is called is inserted in between each pair.
The result is returned as a new bytes object.
Example: b’.’.join([b’ab’, b’pq’, b’rs’]) -> b’ab.pq.rs’.
-
wolframclient.utils.encoding.
force_bytes
(s, encoding='utf-8', errors='strict')[source]¶ If strings_only is True, don’t convert (some) non-string-like objects.
wolframclient.utils.externalevaluate module¶
-
wolframclient.utils.externalevaluate.
EvaluationEnvironment
(code, session_data={}, constants=None, **extra)[source]¶
-
class
wolframclient.utils.externalevaluate.
SideEffectSender
(level=0)[source]¶ Bases:
logging.Handler
-
class
wolframclient.utils.externalevaluate.
StdoutProxy
(stream)[source]¶ Bases:
object
-
keep_listening
¶ Provide a convenient way to build objects representing arbitrary Wolfram Language expressions through the use of attributes.
This class is conveniently instantiated at startup as
wl
,Global
andSystem
. It should be instantiated only to represent many symbols belonging to the same specific context.Example:
>>> dev = WLSymbolFactory('Developer') >>> dev.PackedArrayQ Developer`PackedArrayQ
Alternative:
>>> wl.Developer.PackedArrayQ Developer`PackedArrayQ
-
-
wolframclient.utils.externalevaluate.
evaluate_message
(input=None, return_type=None, args=None, **opts)[source]¶
-
wolframclient.utils.externalevaluate.
handle_message
(socket, evaluate_message=<function evaluate_message>, consumer=None)[source]¶
wolframclient.utils.functional module¶
wolframclient.utils.importutils module¶
-
class
wolframclient.utils.importutils.
API
(importer=<function safe_import_string>, **mapping)[source]¶ Bases:
object