-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathserver.py
65 lines (52 loc) · 1.99 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from __future__ import absolute_import, print_function, unicode_literals
from wolframclient.utils import six
try:
import certifi
DEFAULT_CA_PATH = certifi.where()
except ImportError:
certifi = None
DEFAULT_CA_PATH = None
__all__ = ["WolframServer", "DEFAULT_CA_PATH"]
class WolframServer:
"""Represents the cloud server.
Contains the authentication endpoints information, the API endpoint aka. the
cloud base (`$CloudBase` in the Wolfram Language), and eventually the xauth
consumer key and secret.
"""
def __init__(
self,
cloudbase,
request_token_endpoint,
access_token_endpoint,
xauth_consumer_key=None,
xauth_consumer_secret=None,
certificate=None,
):
self.cloudbase = cloudbase
self.request_token_endpoint = request_token_endpoint
self.access_token_endpoint = access_token_endpoint
self.xauth_consumer_key = xauth_consumer_key
self.xauth_consumer_secret = xauth_consumer_secret
if certificate is None or isinstance(certificate, six.string_types):
self.certificate = certificate
else:
raise ValueError("Invalid certificate. Must be a string type or None.")
def is_xauth(self):
return self.xauth_consumer_key is not None and self.xauth_consumer_secret is not None
def __repr__(self):
return "<{}: cloudbase={}, request_token={}, access_token={}, certificate={}, xauth support={}>".format(
self.__class__.__name__,
self.cloudbase,
self.request_token_endpoint,
self.access_token_endpoint,
self.certificate,
self.is_xauth(),
)
# A built-in instance representing the Wolfram Public Cloud.
WOLFRAM_PUBLIC_CLOUD_SERVER = WolframServer(
"https://www.wolframcloud.com",
"https://account.wolfram.com/auth/request-token",
"https://account.wolfram.com/auth/access-token",
xauth_consumer_key=None,
xauth_consumer_secret=None,
)