appier 1.31.4__py2.py3-none-any.whl → 1.32.0__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- appier/__init__.py +333 -52
- appier/amqp.py +29 -30
- appier/api.py +214 -212
- appier/asgi.py +54 -55
- appier/async_neo.py +46 -35
- appier/async_old.py +55 -42
- appier/asynchronous.py +7 -13
- appier/base.py +1762 -1429
- appier/bus.py +51 -52
- appier/cache.py +99 -84
- appier/common.py +9 -11
- appier/component.py +17 -19
- appier/compress.py +25 -28
- appier/config.py +96 -73
- appier/controller.py +9 -15
- appier/crypt.py +25 -21
- appier/data.py +73 -57
- appier/defines.py +191 -226
- appier/exceptions.py +103 -63
- appier/execution.py +94 -88
- appier/export.py +90 -88
- appier/extra.py +6 -13
- appier/extra_neo.py +8 -11
- appier/extra_old.py +18 -16
- appier/geo.py +57 -47
- appier/git.py +101 -90
- appier/graph.py +23 -24
- appier/http.py +520 -398
- appier/legacy.py +373 -180
- appier/log.py +90 -97
- appier/meta.py +42 -42
- appier/mock.py +32 -34
- appier/model.py +793 -681
- appier/model_a.py +208 -183
- appier/mongo.py +183 -107
- appier/observer.py +39 -31
- appier/part.py +23 -24
- appier/preferences.py +44 -47
- appier/queuing.py +78 -96
- appier/redisdb.py +40 -35
- appier/request.py +227 -175
- appier/scheduler.py +13 -18
- appier/serialize.py +37 -31
- appier/session.py +161 -147
- appier/settings.py +2 -11
- appier/smtp.py +53 -49
- appier/storage.py +39 -33
- appier/structures.py +50 -45
- appier/test/__init__.py +2 -11
- appier/test/base.py +111 -108
- appier/test/cache.py +28 -35
- appier/test/config.py +10 -19
- appier/test/crypt.py +3 -12
- appier/test/data.py +3 -12
- appier/test/exceptions.py +8 -17
- appier/test/export.py +16 -33
- appier/test/graph.py +27 -60
- appier/test/http.py +42 -54
- appier/test/legacy.py +20 -30
- appier/test/log.py +14 -35
- appier/test/mock.py +27 -123
- appier/test/model.py +79 -91
- appier/test/part.py +5 -14
- appier/test/preferences.py +5 -13
- appier/test/queuing.py +29 -37
- appier/test/request.py +61 -73
- appier/test/serialize.py +12 -23
- appier/test/session.py +10 -19
- appier/test/smtp.py +8 -14
- appier/test/structures.py +20 -24
- appier/test/typesf.py +14 -28
- appier/test/util.py +480 -438
- appier/typesf.py +251 -171
- appier/util.py +578 -407
- appier/validation.py +280 -143
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/METADATA +6 -1
- appier-1.32.0.dist-info/RECORD +86 -0
- appier-1.31.4.dist-info/RECORD +0 -86
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/LICENSE +0 -0
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/WHEEL +0 -0
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/top_level.txt +0 -0
appier/api.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
|
|
4
4
|
# Hive Appier Framework
|
|
5
|
-
# Copyright (c) 2008-
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
6
|
#
|
|
7
7
|
# This file is part of Hive Appier Framework.
|
|
8
8
|
#
|
|
@@ -22,16 +22,7 @@
|
|
|
22
22
|
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
23
|
""" The author(s) of the module """
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
""" The version of the module """
|
|
27
|
-
|
|
28
|
-
__revision__ = "$LastChangedRevision$"
|
|
29
|
-
""" The revision number of the module """
|
|
30
|
-
|
|
31
|
-
__date__ = "$LastChangedDate$"
|
|
32
|
-
""" The last change date of the module """
|
|
33
|
-
|
|
34
|
-
__copyright__ = "Copyright (c) 2008-2022 Hive Solutions Lda."
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
35
26
|
""" The copyright for the module """
|
|
36
27
|
|
|
37
28
|
__license__ = "Apache License, Version 2.0"
|
|
@@ -51,6 +42,7 @@ from . import observer
|
|
|
51
42
|
from . import exceptions
|
|
52
43
|
from . import structures
|
|
53
44
|
|
|
45
|
+
|
|
54
46
|
class API(observer.Observable):
|
|
55
47
|
"""
|
|
56
48
|
Abstract and top level API class that should be used
|
|
@@ -63,71 +55,68 @@ class API(observer.Observable):
|
|
|
63
55
|
|
|
64
56
|
SINGLETON = None
|
|
65
57
|
|
|
66
|
-
def __init__(self, owner
|
|
58
|
+
def __init__(self, owner=None, *args, **kwargs):
|
|
67
59
|
observer.Observable.__init__(self, *args, **kwargs)
|
|
68
60
|
self.owner = owner or base.APP
|
|
69
|
-
if not hasattr(self, "auth_callback"):
|
|
61
|
+
if not hasattr(self, "auth_callback"):
|
|
62
|
+
self.auth_callback = None
|
|
70
63
|
|
|
71
64
|
@classmethod
|
|
72
65
|
def singleton(cls, *args, **kwargs):
|
|
73
66
|
callback = kwargs.pop("scallback", None)
|
|
74
|
-
if cls.SINGLETON:
|
|
67
|
+
if cls.SINGLETON:
|
|
68
|
+
return cls.SINGLETON
|
|
75
69
|
cls.SINGLETON = cls(*args, **kwargs)
|
|
76
|
-
if callback:
|
|
70
|
+
if callback:
|
|
71
|
+
callback(cls.SINGLETON)
|
|
77
72
|
return cls.SINGLETON
|
|
78
73
|
|
|
79
74
|
def get(
|
|
80
75
|
self,
|
|
81
76
|
url,
|
|
82
|
-
headers
|
|
83
|
-
params
|
|
84
|
-
handle
|
|
85
|
-
silent
|
|
86
|
-
redirect
|
|
87
|
-
timeout
|
|
88
|
-
callback
|
|
89
|
-
extra
|
|
77
|
+
headers=None,
|
|
78
|
+
params=None,
|
|
79
|
+
handle=None,
|
|
80
|
+
silent=None,
|
|
81
|
+
redirect=None,
|
|
82
|
+
timeout=None,
|
|
83
|
+
callback=True,
|
|
84
|
+
extra=None,
|
|
90
85
|
**kwargs
|
|
91
86
|
):
|
|
92
87
|
headers = headers or dict()
|
|
93
88
|
extra = extra or dict()
|
|
94
89
|
params = structures.OrderedDict(params or kwargs)
|
|
95
90
|
auth_callback = self.auth_callback if callback else None
|
|
96
|
-
self.build(
|
|
97
|
-
"GET",
|
|
98
|
-
url,
|
|
99
|
-
headers = headers,
|
|
100
|
-
params = params,
|
|
101
|
-
kwargs = kwargs
|
|
102
|
-
)
|
|
91
|
+
self.build("GET", url, headers=headers, params=params, kwargs=kwargs)
|
|
103
92
|
return self.request(
|
|
104
93
|
http.get,
|
|
105
94
|
url,
|
|
106
|
-
params
|
|
107
|
-
headers
|
|
108
|
-
handle
|
|
109
|
-
silent
|
|
110
|
-
redirect
|
|
111
|
-
timeout
|
|
112
|
-
auth_callback
|
|
95
|
+
params=params,
|
|
96
|
+
headers=headers,
|
|
97
|
+
handle=handle,
|
|
98
|
+
silent=silent,
|
|
99
|
+
redirect=redirect,
|
|
100
|
+
timeout=timeout,
|
|
101
|
+
auth_callback=auth_callback,
|
|
113
102
|
**extra
|
|
114
103
|
)
|
|
115
104
|
|
|
116
105
|
def post(
|
|
117
106
|
self,
|
|
118
107
|
url,
|
|
119
|
-
data
|
|
120
|
-
data_j
|
|
121
|
-
data_m
|
|
122
|
-
headers
|
|
123
|
-
params
|
|
124
|
-
mime
|
|
125
|
-
handle
|
|
126
|
-
silent
|
|
127
|
-
redirect
|
|
128
|
-
timeout
|
|
129
|
-
callback
|
|
130
|
-
extra
|
|
108
|
+
data=None,
|
|
109
|
+
data_j=None,
|
|
110
|
+
data_m=None,
|
|
111
|
+
headers=None,
|
|
112
|
+
params=None,
|
|
113
|
+
mime=None,
|
|
114
|
+
handle=None,
|
|
115
|
+
silent=None,
|
|
116
|
+
redirect=None,
|
|
117
|
+
timeout=None,
|
|
118
|
+
callback=True,
|
|
119
|
+
extra=None,
|
|
131
120
|
**kwargs
|
|
132
121
|
):
|
|
133
122
|
headers = headers or dict()
|
|
@@ -137,46 +126,46 @@ class API(observer.Observable):
|
|
|
137
126
|
self.build(
|
|
138
127
|
"POST",
|
|
139
128
|
url,
|
|
140
|
-
data
|
|
141
|
-
data_j
|
|
142
|
-
data_m
|
|
143
|
-
headers
|
|
144
|
-
params
|
|
145
|
-
mime
|
|
146
|
-
kwargs
|
|
129
|
+
data=data,
|
|
130
|
+
data_j=data_j,
|
|
131
|
+
data_m=data_m,
|
|
132
|
+
headers=headers,
|
|
133
|
+
params=params,
|
|
134
|
+
mime=mime,
|
|
135
|
+
kwargs=kwargs,
|
|
147
136
|
)
|
|
148
137
|
return self.request(
|
|
149
138
|
http.post,
|
|
150
139
|
url,
|
|
151
|
-
params
|
|
152
|
-
data
|
|
153
|
-
data_j
|
|
154
|
-
data_m
|
|
155
|
-
headers
|
|
156
|
-
mime
|
|
157
|
-
handle
|
|
158
|
-
silent
|
|
159
|
-
redirect
|
|
160
|
-
timeout
|
|
161
|
-
auth_callback
|
|
140
|
+
params=params,
|
|
141
|
+
data=data,
|
|
142
|
+
data_j=data_j,
|
|
143
|
+
data_m=data_m,
|
|
144
|
+
headers=headers,
|
|
145
|
+
mime=mime,
|
|
146
|
+
handle=handle,
|
|
147
|
+
silent=silent,
|
|
148
|
+
redirect=redirect,
|
|
149
|
+
timeout=timeout,
|
|
150
|
+
auth_callback=auth_callback,
|
|
162
151
|
**extra
|
|
163
152
|
)
|
|
164
153
|
|
|
165
154
|
def put(
|
|
166
155
|
self,
|
|
167
156
|
url,
|
|
168
|
-
data
|
|
169
|
-
data_j
|
|
170
|
-
data_m
|
|
171
|
-
headers
|
|
172
|
-
params
|
|
173
|
-
mime
|
|
174
|
-
handle
|
|
175
|
-
silent
|
|
176
|
-
redirect
|
|
177
|
-
timeout
|
|
178
|
-
callback
|
|
179
|
-
extra
|
|
157
|
+
data=None,
|
|
158
|
+
data_j=None,
|
|
159
|
+
data_m=None,
|
|
160
|
+
headers=None,
|
|
161
|
+
params=None,
|
|
162
|
+
mime=None,
|
|
163
|
+
handle=None,
|
|
164
|
+
silent=None,
|
|
165
|
+
redirect=None,
|
|
166
|
+
timeout=None,
|
|
167
|
+
callback=True,
|
|
168
|
+
extra=None,
|
|
180
169
|
**kwargs
|
|
181
170
|
):
|
|
182
171
|
headers = headers or dict()
|
|
@@ -186,83 +175,77 @@ class API(observer.Observable):
|
|
|
186
175
|
self.build(
|
|
187
176
|
"PUT",
|
|
188
177
|
url,
|
|
189
|
-
data
|
|
190
|
-
data_j
|
|
191
|
-
data_m
|
|
192
|
-
headers
|
|
193
|
-
params
|
|
194
|
-
mime
|
|
195
|
-
kwargs
|
|
178
|
+
data=data,
|
|
179
|
+
data_j=data_j,
|
|
180
|
+
data_m=data_m,
|
|
181
|
+
headers=headers,
|
|
182
|
+
params=params,
|
|
183
|
+
mime=mime,
|
|
184
|
+
kwargs=kwargs,
|
|
196
185
|
)
|
|
197
186
|
return self.request(
|
|
198
187
|
http.put,
|
|
199
188
|
url,
|
|
200
|
-
params
|
|
201
|
-
data
|
|
202
|
-
data_j
|
|
203
|
-
data_m
|
|
204
|
-
headers
|
|
205
|
-
mime
|
|
206
|
-
handle
|
|
207
|
-
silent
|
|
208
|
-
redirect
|
|
209
|
-
timeout
|
|
210
|
-
auth_callback
|
|
189
|
+
params=params,
|
|
190
|
+
data=data,
|
|
191
|
+
data_j=data_j,
|
|
192
|
+
data_m=data_m,
|
|
193
|
+
headers=headers,
|
|
194
|
+
mime=mime,
|
|
195
|
+
handle=handle,
|
|
196
|
+
silent=silent,
|
|
197
|
+
redirect=redirect,
|
|
198
|
+
timeout=timeout,
|
|
199
|
+
auth_callback=auth_callback,
|
|
211
200
|
**extra
|
|
212
201
|
)
|
|
213
202
|
|
|
214
203
|
def delete(
|
|
215
204
|
self,
|
|
216
205
|
url,
|
|
217
|
-
headers
|
|
218
|
-
params
|
|
219
|
-
handle
|
|
220
|
-
silent
|
|
221
|
-
redirect
|
|
222
|
-
timeout
|
|
223
|
-
callback
|
|
224
|
-
extra
|
|
206
|
+
headers=None,
|
|
207
|
+
params=None,
|
|
208
|
+
handle=None,
|
|
209
|
+
silent=None,
|
|
210
|
+
redirect=None,
|
|
211
|
+
timeout=None,
|
|
212
|
+
callback=True,
|
|
213
|
+
extra=None,
|
|
225
214
|
**kwargs
|
|
226
215
|
):
|
|
227
216
|
headers = headers or dict()
|
|
228
217
|
extra = extra or dict()
|
|
229
218
|
params = structures.OrderedDict(params or kwargs)
|
|
230
219
|
auth_callback = self.auth_callback if callback else None
|
|
231
|
-
self.build(
|
|
232
|
-
"DELETE",
|
|
233
|
-
url,
|
|
234
|
-
headers = headers,
|
|
235
|
-
params = params,
|
|
236
|
-
kwargs = kwargs
|
|
237
|
-
)
|
|
220
|
+
self.build("DELETE", url, headers=headers, params=params, kwargs=kwargs)
|
|
238
221
|
return self.request(
|
|
239
222
|
http.delete,
|
|
240
223
|
url,
|
|
241
|
-
params
|
|
242
|
-
headers
|
|
243
|
-
handle
|
|
244
|
-
silent
|
|
245
|
-
redirect
|
|
246
|
-
timeout
|
|
247
|
-
auth_callback
|
|
224
|
+
params=params,
|
|
225
|
+
headers=headers,
|
|
226
|
+
handle=handle,
|
|
227
|
+
silent=silent,
|
|
228
|
+
redirect=redirect,
|
|
229
|
+
timeout=timeout,
|
|
230
|
+
auth_callback=auth_callback,
|
|
248
231
|
**extra
|
|
249
232
|
)
|
|
250
233
|
|
|
251
234
|
def patch(
|
|
252
235
|
self,
|
|
253
236
|
url,
|
|
254
|
-
data
|
|
255
|
-
data_j
|
|
256
|
-
data_m
|
|
257
|
-
headers
|
|
258
|
-
params
|
|
259
|
-
mime
|
|
260
|
-
handle
|
|
261
|
-
silent
|
|
262
|
-
redirect
|
|
263
|
-
timeout
|
|
264
|
-
callback
|
|
265
|
-
extra
|
|
237
|
+
data=None,
|
|
238
|
+
data_j=None,
|
|
239
|
+
data_m=None,
|
|
240
|
+
headers=None,
|
|
241
|
+
params=None,
|
|
242
|
+
mime=None,
|
|
243
|
+
handle=None,
|
|
244
|
+
silent=None,
|
|
245
|
+
redirect=None,
|
|
246
|
+
timeout=None,
|
|
247
|
+
callback=True,
|
|
248
|
+
extra=None,
|
|
266
249
|
**kwargs
|
|
267
250
|
):
|
|
268
251
|
headers = headers or dict()
|
|
@@ -272,48 +255,50 @@ class API(observer.Observable):
|
|
|
272
255
|
self.build(
|
|
273
256
|
"PATCH",
|
|
274
257
|
url,
|
|
275
|
-
data
|
|
276
|
-
data_j
|
|
277
|
-
data_m
|
|
278
|
-
headers
|
|
279
|
-
params
|
|
280
|
-
mime
|
|
281
|
-
kwargs
|
|
258
|
+
data=data,
|
|
259
|
+
data_j=data_j,
|
|
260
|
+
data_m=data_m,
|
|
261
|
+
headers=headers,
|
|
262
|
+
params=params,
|
|
263
|
+
mime=mime,
|
|
264
|
+
kwargs=kwargs,
|
|
282
265
|
)
|
|
283
266
|
return self.request(
|
|
284
267
|
http.patch,
|
|
285
268
|
url,
|
|
286
|
-
params
|
|
287
|
-
data
|
|
288
|
-
data_j
|
|
289
|
-
data_m
|
|
290
|
-
headers
|
|
291
|
-
mime
|
|
292
|
-
handle
|
|
293
|
-
silent
|
|
294
|
-
redirect
|
|
295
|
-
timeout
|
|
296
|
-
auth_callback
|
|
269
|
+
params=params,
|
|
270
|
+
data=data,
|
|
271
|
+
data_j=data_j,
|
|
272
|
+
data_m=data_m,
|
|
273
|
+
headers=headers,
|
|
274
|
+
mime=mime,
|
|
275
|
+
handle=handle,
|
|
276
|
+
silent=silent,
|
|
277
|
+
redirect=redirect,
|
|
278
|
+
timeout=timeout,
|
|
279
|
+
auth_callback=auth_callback,
|
|
297
280
|
**extra
|
|
298
281
|
)
|
|
299
282
|
|
|
300
283
|
def request(self, method, *args, **kwargs):
|
|
301
|
-
try:
|
|
284
|
+
try:
|
|
285
|
+
result = method(*args, **kwargs)
|
|
302
286
|
except exceptions.HTTPError as exception:
|
|
303
287
|
self.handle_error(exception)
|
|
304
|
-
else:
|
|
288
|
+
else:
|
|
289
|
+
return result
|
|
305
290
|
|
|
306
291
|
def build(
|
|
307
292
|
self,
|
|
308
293
|
method,
|
|
309
294
|
url,
|
|
310
|
-
data
|
|
311
|
-
data_j
|
|
312
|
-
data_m
|
|
313
|
-
headers
|
|
314
|
-
params
|
|
315
|
-
mime
|
|
316
|
-
kwargs
|
|
295
|
+
data=None,
|
|
296
|
+
data_j=None,
|
|
297
|
+
data_m=None,
|
|
298
|
+
headers=None,
|
|
299
|
+
params=None,
|
|
300
|
+
mime=None,
|
|
301
|
+
kwargs=None,
|
|
317
302
|
):
|
|
318
303
|
pass
|
|
319
304
|
|
|
@@ -322,8 +307,11 @@ class API(observer.Observable):
|
|
|
322
307
|
|
|
323
308
|
@property
|
|
324
309
|
def logger(self):
|
|
325
|
-
if self.owner:
|
|
326
|
-
|
|
310
|
+
if self.owner:
|
|
311
|
+
return self.owner.logger
|
|
312
|
+
else:
|
|
313
|
+
return logging.getLogger()
|
|
314
|
+
|
|
327
315
|
|
|
328
316
|
class OAuthAPI(API):
|
|
329
317
|
"""
|
|
@@ -355,10 +343,11 @@ class OAuthAPI(API):
|
|
|
355
343
|
self.mode = OAuthAPI.OAUTH_MODE
|
|
356
344
|
|
|
357
345
|
def handle_error(self, error):
|
|
358
|
-
if not error.code in http.AUTH_ERRORS:
|
|
346
|
+
if not error.code in http.AUTH_ERRORS:
|
|
347
|
+
raise error
|
|
359
348
|
raise exceptions.OAuthAccessError(
|
|
360
|
-
message
|
|
361
|
-
original
|
|
349
|
+
message="Problems using access token found must re-authorize",
|
|
350
|
+
original=error,
|
|
362
351
|
)
|
|
363
352
|
|
|
364
353
|
def is_direct(self):
|
|
@@ -370,8 +359,8 @@ class OAuthAPI(API):
|
|
|
370
359
|
def _get_mode(self):
|
|
371
360
|
return OAuthAPI.OAUTH_MODE
|
|
372
361
|
|
|
373
|
-
class OAuth1API(OAuthAPI):
|
|
374
362
|
|
|
363
|
+
class OAuth1API(OAuthAPI):
|
|
375
364
|
def __init__(self, *args, **kwargs):
|
|
376
365
|
OAuthAPI.__init__(self, *args, **kwargs)
|
|
377
366
|
self.oauth_token = None
|
|
@@ -381,33 +370,36 @@ class OAuth1API(OAuthAPI):
|
|
|
381
370
|
self,
|
|
382
371
|
method,
|
|
383
372
|
url,
|
|
384
|
-
data
|
|
385
|
-
data_j
|
|
386
|
-
data_m
|
|
387
|
-
headers
|
|
388
|
-
params
|
|
389
|
-
mime
|
|
390
|
-
kwargs
|
|
373
|
+
data=None,
|
|
374
|
+
data_j=None,
|
|
375
|
+
data_m=None,
|
|
376
|
+
headers=None,
|
|
377
|
+
params=None,
|
|
378
|
+
mime=None,
|
|
379
|
+
kwargs=None,
|
|
391
380
|
):
|
|
392
|
-
if not self.is_oauth():
|
|
381
|
+
if not self.is_oauth():
|
|
382
|
+
return
|
|
393
383
|
auth = kwargs.pop("auth", self.auth_default)
|
|
394
|
-
if auth:
|
|
384
|
+
if auth:
|
|
385
|
+
self.auth_header(method, url, headers, kwargs)
|
|
395
386
|
|
|
396
|
-
def auth_header(self, method, url, headers, kwargs, sign_method
|
|
397
|
-
if not sign_method == "HMAC-SHA1":
|
|
387
|
+
def auth_header(self, method, url, headers, kwargs, sign_method="HMAC-SHA1"):
|
|
388
|
+
if not sign_method == "HMAC-SHA1":
|
|
389
|
+
raise exceptions.NotImplementedError()
|
|
398
390
|
|
|
399
|
-
if not self.client_key:
|
|
400
|
-
message
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
391
|
+
if not self.client_key:
|
|
392
|
+
raise exceptions.SecurityError(message="No client key defined, mandatory")
|
|
393
|
+
if not self.client_secret:
|
|
394
|
+
raise exceptions.SecurityError(
|
|
395
|
+
message="No client secret defined, mandatory"
|
|
396
|
+
)
|
|
405
397
|
|
|
406
398
|
oauth_callback = kwargs.pop("oauth_callback", None)
|
|
407
399
|
|
|
408
400
|
params = []
|
|
409
401
|
|
|
410
|
-
encoded = http._quote(kwargs, safe
|
|
402
|
+
encoded = http._quote(kwargs, safe="~")
|
|
411
403
|
items = encoded.items()
|
|
412
404
|
params.extend(items)
|
|
413
405
|
|
|
@@ -416,41 +408,49 @@ class OAuth1API(OAuthAPI):
|
|
|
416
408
|
oauth_timestamp = str(int(time.time()))
|
|
417
409
|
|
|
418
410
|
authorization = dict(
|
|
419
|
-
oauth_nonce
|
|
420
|
-
oauth_signature_method
|
|
421
|
-
oauth_timestamp
|
|
422
|
-
oauth_consumer_key
|
|
423
|
-
oauth_version
|
|
411
|
+
oauth_nonce=oauth_nonce,
|
|
412
|
+
oauth_signature_method=sign_method,
|
|
413
|
+
oauth_timestamp=oauth_timestamp,
|
|
414
|
+
oauth_consumer_key=self.client_key,
|
|
415
|
+
oauth_version="1.0",
|
|
424
416
|
)
|
|
425
|
-
if self.oauth_token:
|
|
426
|
-
|
|
417
|
+
if self.oauth_token:
|
|
418
|
+
authorization["oauth_token"] = self.oauth_token
|
|
419
|
+
if oauth_callback:
|
|
420
|
+
authorization["oauth_callback"] = oauth_callback
|
|
427
421
|
|
|
428
|
-
encoded = http._quote(authorization, safe
|
|
422
|
+
encoded = http._quote(authorization, safe="~")
|
|
429
423
|
items = encoded.items()
|
|
430
424
|
params.extend(items)
|
|
431
425
|
params.sort()
|
|
432
426
|
|
|
433
427
|
signature_base = "&".join(["%s=%s" % (key, value) for key, value in params])
|
|
434
|
-
signature_extra = "&".join(
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
428
|
+
signature_extra = "&".join(
|
|
429
|
+
[
|
|
430
|
+
legacy.quote(method, safe="~"),
|
|
431
|
+
legacy.quote(url, safe="~"),
|
|
432
|
+
legacy.quote(signature_base, safe="~"),
|
|
433
|
+
]
|
|
434
|
+
)
|
|
439
435
|
|
|
440
|
-
if self.oauth_token_secret:
|
|
441
|
-
|
|
436
|
+
if self.oauth_token_secret:
|
|
437
|
+
key = "%s&%s" % (self.client_secret, self.oauth_token_secret)
|
|
438
|
+
else:
|
|
439
|
+
key = "%s&" % self.client_secret
|
|
442
440
|
|
|
443
|
-
if legacy.is_unicode(key):
|
|
444
|
-
|
|
441
|
+
if legacy.is_unicode(key):
|
|
442
|
+
key = key.encode("utf-8")
|
|
443
|
+
if legacy.is_unicode(signature_extra):
|
|
444
|
+
signature_extra = signature_extra.encode("utf-8")
|
|
445
445
|
|
|
446
446
|
oauth_signature = hmac.new(key, signature_extra, hashlib.sha1).digest()
|
|
447
447
|
oauth_signature = base64.b64encode(oauth_signature)
|
|
448
448
|
oauth_signature = legacy.str(oauth_signature)
|
|
449
449
|
|
|
450
450
|
authorization["oauth_signature"] = oauth_signature
|
|
451
|
-
authorization = http._quote(authorization, safe
|
|
451
|
+
authorization = http._quote(authorization, safe="~")
|
|
452
452
|
authorization = authorization.items()
|
|
453
|
-
authorization = [
|
|
453
|
+
authorization = ['%s="%s"' % (key, value) for key, value in authorization]
|
|
454
454
|
|
|
455
455
|
authorization_s = ", ".join(authorization)
|
|
456
456
|
authorization_s = "OAuth %s" % authorization_s
|
|
@@ -461,8 +461,8 @@ class OAuth1API(OAuthAPI):
|
|
|
461
461
|
def auth_default(self):
|
|
462
462
|
return True
|
|
463
463
|
|
|
464
|
-
class OAuth2API(OAuthAPI):
|
|
465
464
|
|
|
465
|
+
class OAuth2API(OAuthAPI):
|
|
466
466
|
def __init__(self, *args, **kwargs):
|
|
467
467
|
OAuthAPI.__init__(self, *args, **kwargs)
|
|
468
468
|
self.access_token = None
|
|
@@ -471,15 +471,16 @@ class OAuth2API(OAuthAPI):
|
|
|
471
471
|
self,
|
|
472
472
|
method,
|
|
473
473
|
url,
|
|
474
|
-
data
|
|
475
|
-
data_j
|
|
476
|
-
data_m
|
|
477
|
-
headers
|
|
478
|
-
params
|
|
479
|
-
mime
|
|
480
|
-
kwargs
|
|
474
|
+
data=None,
|
|
475
|
+
data_j=None,
|
|
476
|
+
data_m=None,
|
|
477
|
+
headers=None,
|
|
478
|
+
params=None,
|
|
479
|
+
mime=None,
|
|
480
|
+
kwargs=None,
|
|
481
481
|
):
|
|
482
|
-
if not self.is_oauth():
|
|
482
|
+
if not self.is_oauth():
|
|
483
|
+
return
|
|
483
484
|
token = kwargs.pop("token", self.token_default)
|
|
484
485
|
if token and "param" in self.oauth_types:
|
|
485
486
|
kwargs[self.oauth_param] = self.get_access_token()
|
|
@@ -487,9 +488,10 @@ class OAuth2API(OAuthAPI):
|
|
|
487
488
|
headers["Authorization"] = "Bearer %s" % self.get_access_token()
|
|
488
489
|
|
|
489
490
|
def get_access_token(self):
|
|
490
|
-
if self.access_token:
|
|
491
|
+
if self.access_token:
|
|
492
|
+
return self.access_token
|
|
491
493
|
raise exceptions.OAuthAccessError(
|
|
492
|
-
message
|
|
494
|
+
message="No access token found must re-authorize"
|
|
493
495
|
)
|
|
494
496
|
|
|
495
497
|
@property
|