dub 0.26.12__py3-none-any.whl → 0.27.0__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.
- dub/_version.py +3 -3
- dub/analytics.py +66 -76
- dub/basesdk.py +4 -4
- dub/commissions.py +132 -152
- dub/customers.py +330 -380
- dub/domains.py +396 -456
- dub/embed_tokens.py +66 -78
- dub/events.py +66 -76
- dub/folders.py +264 -304
- dub/links.py +666 -750
- dub/models/errors/__init__.py +9 -0
- dub/models/errors/badrequest.py +12 -6
- dub/models/errors/conflict.py +12 -6
- dub/models/errors/duberror.py +26 -0
- dub/models/errors/forbidden.py +12 -6
- dub/models/errors/internalservererror.py +12 -6
- dub/models/errors/inviteexpired.py +12 -6
- dub/models/errors/no_response_error.py +13 -0
- dub/models/errors/notfound.py +12 -6
- dub/models/errors/ratelimitexceeded.py +12 -6
- dub/models/errors/responsevalidationerror.py +25 -0
- dub/models/errors/sdkerror.py +30 -14
- dub/models/errors/unauthorized.py +12 -6
- dub/models/errors/unprocessableentity.py +12 -6
- dub/models/operations/createcustomer.py +3 -0
- dub/models/operations/getcustomer.py +3 -0
- dub/models/operations/getcustomers.py +3 -0
- dub/models/operations/updatecustomer.py +3 -0
- dub/partners.py +336 -374
- dub/qr_codes.py +62 -72
- dub/tags.py +268 -300
- dub/track.py +132 -152
- dub/utils/__init__.py +3 -0
- dub/utils/serializers.py +21 -3
- dub/workspaces.py +132 -152
- {dub-0.26.12.dist-info → dub-0.27.0.dist-info}/METADATA +50 -56
- {dub-0.26.12.dist-info → dub-0.27.0.dist-info}/RECORD +39 -36
- {dub-0.26.12.dist-info → dub-0.27.0.dist-info}/LICENSE +0 -0
- {dub-0.26.12.dist-info → dub-0.27.0.dist-info}/WHEEL +0 -0
dub/track.py
CHANGED
|
@@ -103,63 +103,58 @@ class Track(BaseSDK):
|
|
|
103
103
|
|
|
104
104
|
response_data: Any = None
|
|
105
105
|
if utils.match_response(http_res, "200", "application/json"):
|
|
106
|
-
return utils.
|
|
107
|
-
|
|
106
|
+
return utils.unmarshal_json_response(
|
|
107
|
+
Optional[operations.TrackLeadResponseBody], http_res
|
|
108
108
|
)
|
|
109
109
|
if utils.match_response(http_res, "400", "application/json"):
|
|
110
|
-
response_data = utils.
|
|
111
|
-
|
|
110
|
+
response_data = utils.unmarshal_json_response(
|
|
111
|
+
errors.BadRequestData, http_res
|
|
112
|
+
)
|
|
113
|
+
raise errors.BadRequest(response_data, http_res)
|
|
112
114
|
if utils.match_response(http_res, "401", "application/json"):
|
|
113
|
-
response_data = utils.
|
|
114
|
-
|
|
115
|
+
response_data = utils.unmarshal_json_response(
|
|
116
|
+
errors.UnauthorizedData, http_res
|
|
117
|
+
)
|
|
118
|
+
raise errors.Unauthorized(response_data, http_res)
|
|
115
119
|
if utils.match_response(http_res, "403", "application/json"):
|
|
116
|
-
response_data = utils.
|
|
117
|
-
|
|
120
|
+
response_data = utils.unmarshal_json_response(
|
|
121
|
+
errors.ForbiddenData, http_res
|
|
122
|
+
)
|
|
123
|
+
raise errors.Forbidden(response_data, http_res)
|
|
118
124
|
if utils.match_response(http_res, "404", "application/json"):
|
|
119
|
-
response_data = utils.
|
|
120
|
-
raise errors.NotFound(
|
|
125
|
+
response_data = utils.unmarshal_json_response(errors.NotFoundData, http_res)
|
|
126
|
+
raise errors.NotFound(response_data, http_res)
|
|
121
127
|
if utils.match_response(http_res, "409", "application/json"):
|
|
122
|
-
response_data = utils.
|
|
123
|
-
raise errors.Conflict(
|
|
128
|
+
response_data = utils.unmarshal_json_response(errors.ConflictData, http_res)
|
|
129
|
+
raise errors.Conflict(response_data, http_res)
|
|
124
130
|
if utils.match_response(http_res, "410", "application/json"):
|
|
125
|
-
response_data = utils.
|
|
126
|
-
|
|
131
|
+
response_data = utils.unmarshal_json_response(
|
|
132
|
+
errors.InviteExpiredData, http_res
|
|
127
133
|
)
|
|
128
|
-
raise errors.InviteExpired(
|
|
134
|
+
raise errors.InviteExpired(response_data, http_res)
|
|
129
135
|
if utils.match_response(http_res, "422", "application/json"):
|
|
130
|
-
response_data = utils.
|
|
131
|
-
|
|
136
|
+
response_data = utils.unmarshal_json_response(
|
|
137
|
+
errors.UnprocessableEntityData, http_res
|
|
132
138
|
)
|
|
133
|
-
raise errors.UnprocessableEntity(
|
|
139
|
+
raise errors.UnprocessableEntity(response_data, http_res)
|
|
134
140
|
if utils.match_response(http_res, "429", "application/json"):
|
|
135
|
-
response_data = utils.
|
|
136
|
-
|
|
141
|
+
response_data = utils.unmarshal_json_response(
|
|
142
|
+
errors.RateLimitExceededData, http_res
|
|
137
143
|
)
|
|
138
|
-
raise errors.RateLimitExceeded(
|
|
144
|
+
raise errors.RateLimitExceeded(response_data, http_res)
|
|
139
145
|
if utils.match_response(http_res, "500", "application/json"):
|
|
140
|
-
response_data = utils.
|
|
141
|
-
|
|
146
|
+
response_data = utils.unmarshal_json_response(
|
|
147
|
+
errors.InternalServerErrorData, http_res
|
|
142
148
|
)
|
|
143
|
-
raise errors.InternalServerError(
|
|
149
|
+
raise errors.InternalServerError(response_data, http_res)
|
|
144
150
|
if utils.match_response(http_res, "4XX", "*"):
|
|
145
151
|
http_res_text = utils.stream_to_text(http_res)
|
|
146
|
-
raise errors.SDKError(
|
|
147
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
148
|
-
)
|
|
152
|
+
raise errors.SDKError("API error occurred", http_res, http_res_text)
|
|
149
153
|
if utils.match_response(http_res, "5XX", "*"):
|
|
150
154
|
http_res_text = utils.stream_to_text(http_res)
|
|
151
|
-
raise errors.SDKError(
|
|
152
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
153
|
-
)
|
|
155
|
+
raise errors.SDKError("API error occurred", http_res, http_res_text)
|
|
154
156
|
|
|
155
|
-
|
|
156
|
-
http_res_text = utils.stream_to_text(http_res)
|
|
157
|
-
raise errors.SDKError(
|
|
158
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
159
|
-
http_res.status_code,
|
|
160
|
-
http_res_text,
|
|
161
|
-
http_res,
|
|
162
|
-
)
|
|
157
|
+
raise errors.SDKError("Unexpected response received", http_res)
|
|
163
158
|
|
|
164
159
|
async def lead_async(
|
|
165
160
|
self,
|
|
@@ -255,63 +250,58 @@ class Track(BaseSDK):
|
|
|
255
250
|
|
|
256
251
|
response_data: Any = None
|
|
257
252
|
if utils.match_response(http_res, "200", "application/json"):
|
|
258
|
-
return utils.
|
|
259
|
-
|
|
253
|
+
return utils.unmarshal_json_response(
|
|
254
|
+
Optional[operations.TrackLeadResponseBody], http_res
|
|
260
255
|
)
|
|
261
256
|
if utils.match_response(http_res, "400", "application/json"):
|
|
262
|
-
response_data = utils.
|
|
263
|
-
|
|
257
|
+
response_data = utils.unmarshal_json_response(
|
|
258
|
+
errors.BadRequestData, http_res
|
|
259
|
+
)
|
|
260
|
+
raise errors.BadRequest(response_data, http_res)
|
|
264
261
|
if utils.match_response(http_res, "401", "application/json"):
|
|
265
|
-
response_data = utils.
|
|
266
|
-
|
|
262
|
+
response_data = utils.unmarshal_json_response(
|
|
263
|
+
errors.UnauthorizedData, http_res
|
|
264
|
+
)
|
|
265
|
+
raise errors.Unauthorized(response_data, http_res)
|
|
267
266
|
if utils.match_response(http_res, "403", "application/json"):
|
|
268
|
-
response_data = utils.
|
|
269
|
-
|
|
267
|
+
response_data = utils.unmarshal_json_response(
|
|
268
|
+
errors.ForbiddenData, http_res
|
|
269
|
+
)
|
|
270
|
+
raise errors.Forbidden(response_data, http_res)
|
|
270
271
|
if utils.match_response(http_res, "404", "application/json"):
|
|
271
|
-
response_data = utils.
|
|
272
|
-
raise errors.NotFound(
|
|
272
|
+
response_data = utils.unmarshal_json_response(errors.NotFoundData, http_res)
|
|
273
|
+
raise errors.NotFound(response_data, http_res)
|
|
273
274
|
if utils.match_response(http_res, "409", "application/json"):
|
|
274
|
-
response_data = utils.
|
|
275
|
-
raise errors.Conflict(
|
|
275
|
+
response_data = utils.unmarshal_json_response(errors.ConflictData, http_res)
|
|
276
|
+
raise errors.Conflict(response_data, http_res)
|
|
276
277
|
if utils.match_response(http_res, "410", "application/json"):
|
|
277
|
-
response_data = utils.
|
|
278
|
-
|
|
278
|
+
response_data = utils.unmarshal_json_response(
|
|
279
|
+
errors.InviteExpiredData, http_res
|
|
279
280
|
)
|
|
280
|
-
raise errors.InviteExpired(
|
|
281
|
+
raise errors.InviteExpired(response_data, http_res)
|
|
281
282
|
if utils.match_response(http_res, "422", "application/json"):
|
|
282
|
-
response_data = utils.
|
|
283
|
-
|
|
283
|
+
response_data = utils.unmarshal_json_response(
|
|
284
|
+
errors.UnprocessableEntityData, http_res
|
|
284
285
|
)
|
|
285
|
-
raise errors.UnprocessableEntity(
|
|
286
|
+
raise errors.UnprocessableEntity(response_data, http_res)
|
|
286
287
|
if utils.match_response(http_res, "429", "application/json"):
|
|
287
|
-
response_data = utils.
|
|
288
|
-
|
|
288
|
+
response_data = utils.unmarshal_json_response(
|
|
289
|
+
errors.RateLimitExceededData, http_res
|
|
289
290
|
)
|
|
290
|
-
raise errors.RateLimitExceeded(
|
|
291
|
+
raise errors.RateLimitExceeded(response_data, http_res)
|
|
291
292
|
if utils.match_response(http_res, "500", "application/json"):
|
|
292
|
-
response_data = utils.
|
|
293
|
-
|
|
293
|
+
response_data = utils.unmarshal_json_response(
|
|
294
|
+
errors.InternalServerErrorData, http_res
|
|
294
295
|
)
|
|
295
|
-
raise errors.InternalServerError(
|
|
296
|
+
raise errors.InternalServerError(response_data, http_res)
|
|
296
297
|
if utils.match_response(http_res, "4XX", "*"):
|
|
297
298
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
298
|
-
raise errors.SDKError(
|
|
299
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
300
|
-
)
|
|
299
|
+
raise errors.SDKError("API error occurred", http_res, http_res_text)
|
|
301
300
|
if utils.match_response(http_res, "5XX", "*"):
|
|
302
301
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
303
|
-
raise errors.SDKError(
|
|
304
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
305
|
-
)
|
|
302
|
+
raise errors.SDKError("API error occurred", http_res, http_res_text)
|
|
306
303
|
|
|
307
|
-
|
|
308
|
-
http_res_text = await utils.stream_to_text_async(http_res)
|
|
309
|
-
raise errors.SDKError(
|
|
310
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
311
|
-
http_res.status_code,
|
|
312
|
-
http_res_text,
|
|
313
|
-
http_res,
|
|
314
|
-
)
|
|
304
|
+
raise errors.SDKError("Unexpected response received", http_res)
|
|
315
305
|
|
|
316
306
|
def sale(
|
|
317
307
|
self,
|
|
@@ -407,63 +397,58 @@ class Track(BaseSDK):
|
|
|
407
397
|
|
|
408
398
|
response_data: Any = None
|
|
409
399
|
if utils.match_response(http_res, "200", "application/json"):
|
|
410
|
-
return utils.
|
|
411
|
-
|
|
400
|
+
return utils.unmarshal_json_response(
|
|
401
|
+
Optional[operations.TrackSaleResponseBody], http_res
|
|
412
402
|
)
|
|
413
403
|
if utils.match_response(http_res, "400", "application/json"):
|
|
414
|
-
response_data = utils.
|
|
415
|
-
|
|
404
|
+
response_data = utils.unmarshal_json_response(
|
|
405
|
+
errors.BadRequestData, http_res
|
|
406
|
+
)
|
|
407
|
+
raise errors.BadRequest(response_data, http_res)
|
|
416
408
|
if utils.match_response(http_res, "401", "application/json"):
|
|
417
|
-
response_data = utils.
|
|
418
|
-
|
|
409
|
+
response_data = utils.unmarshal_json_response(
|
|
410
|
+
errors.UnauthorizedData, http_res
|
|
411
|
+
)
|
|
412
|
+
raise errors.Unauthorized(response_data, http_res)
|
|
419
413
|
if utils.match_response(http_res, "403", "application/json"):
|
|
420
|
-
response_data = utils.
|
|
421
|
-
|
|
414
|
+
response_data = utils.unmarshal_json_response(
|
|
415
|
+
errors.ForbiddenData, http_res
|
|
416
|
+
)
|
|
417
|
+
raise errors.Forbidden(response_data, http_res)
|
|
422
418
|
if utils.match_response(http_res, "404", "application/json"):
|
|
423
|
-
response_data = utils.
|
|
424
|
-
raise errors.NotFound(
|
|
419
|
+
response_data = utils.unmarshal_json_response(errors.NotFoundData, http_res)
|
|
420
|
+
raise errors.NotFound(response_data, http_res)
|
|
425
421
|
if utils.match_response(http_res, "409", "application/json"):
|
|
426
|
-
response_data = utils.
|
|
427
|
-
raise errors.Conflict(
|
|
422
|
+
response_data = utils.unmarshal_json_response(errors.ConflictData, http_res)
|
|
423
|
+
raise errors.Conflict(response_data, http_res)
|
|
428
424
|
if utils.match_response(http_res, "410", "application/json"):
|
|
429
|
-
response_data = utils.
|
|
430
|
-
|
|
425
|
+
response_data = utils.unmarshal_json_response(
|
|
426
|
+
errors.InviteExpiredData, http_res
|
|
431
427
|
)
|
|
432
|
-
raise errors.InviteExpired(
|
|
428
|
+
raise errors.InviteExpired(response_data, http_res)
|
|
433
429
|
if utils.match_response(http_res, "422", "application/json"):
|
|
434
|
-
response_data = utils.
|
|
435
|
-
|
|
430
|
+
response_data = utils.unmarshal_json_response(
|
|
431
|
+
errors.UnprocessableEntityData, http_res
|
|
436
432
|
)
|
|
437
|
-
raise errors.UnprocessableEntity(
|
|
433
|
+
raise errors.UnprocessableEntity(response_data, http_res)
|
|
438
434
|
if utils.match_response(http_res, "429", "application/json"):
|
|
439
|
-
response_data = utils.
|
|
440
|
-
|
|
435
|
+
response_data = utils.unmarshal_json_response(
|
|
436
|
+
errors.RateLimitExceededData, http_res
|
|
441
437
|
)
|
|
442
|
-
raise errors.RateLimitExceeded(
|
|
438
|
+
raise errors.RateLimitExceeded(response_data, http_res)
|
|
443
439
|
if utils.match_response(http_res, "500", "application/json"):
|
|
444
|
-
response_data = utils.
|
|
445
|
-
|
|
440
|
+
response_data = utils.unmarshal_json_response(
|
|
441
|
+
errors.InternalServerErrorData, http_res
|
|
446
442
|
)
|
|
447
|
-
raise errors.InternalServerError(
|
|
443
|
+
raise errors.InternalServerError(response_data, http_res)
|
|
448
444
|
if utils.match_response(http_res, "4XX", "*"):
|
|
449
445
|
http_res_text = utils.stream_to_text(http_res)
|
|
450
|
-
raise errors.SDKError(
|
|
451
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
452
|
-
)
|
|
446
|
+
raise errors.SDKError("API error occurred", http_res, http_res_text)
|
|
453
447
|
if utils.match_response(http_res, "5XX", "*"):
|
|
454
448
|
http_res_text = utils.stream_to_text(http_res)
|
|
455
|
-
raise errors.SDKError(
|
|
456
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
457
|
-
)
|
|
449
|
+
raise errors.SDKError("API error occurred", http_res, http_res_text)
|
|
458
450
|
|
|
459
|
-
|
|
460
|
-
http_res_text = utils.stream_to_text(http_res)
|
|
461
|
-
raise errors.SDKError(
|
|
462
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
463
|
-
http_res.status_code,
|
|
464
|
-
http_res_text,
|
|
465
|
-
http_res,
|
|
466
|
-
)
|
|
451
|
+
raise errors.SDKError("Unexpected response received", http_res)
|
|
467
452
|
|
|
468
453
|
async def sale_async(
|
|
469
454
|
self,
|
|
@@ -559,60 +544,55 @@ class Track(BaseSDK):
|
|
|
559
544
|
|
|
560
545
|
response_data: Any = None
|
|
561
546
|
if utils.match_response(http_res, "200", "application/json"):
|
|
562
|
-
return utils.
|
|
563
|
-
|
|
547
|
+
return utils.unmarshal_json_response(
|
|
548
|
+
Optional[operations.TrackSaleResponseBody], http_res
|
|
564
549
|
)
|
|
565
550
|
if utils.match_response(http_res, "400", "application/json"):
|
|
566
|
-
response_data = utils.
|
|
567
|
-
|
|
551
|
+
response_data = utils.unmarshal_json_response(
|
|
552
|
+
errors.BadRequestData, http_res
|
|
553
|
+
)
|
|
554
|
+
raise errors.BadRequest(response_data, http_res)
|
|
568
555
|
if utils.match_response(http_res, "401", "application/json"):
|
|
569
|
-
response_data = utils.
|
|
570
|
-
|
|
556
|
+
response_data = utils.unmarshal_json_response(
|
|
557
|
+
errors.UnauthorizedData, http_res
|
|
558
|
+
)
|
|
559
|
+
raise errors.Unauthorized(response_data, http_res)
|
|
571
560
|
if utils.match_response(http_res, "403", "application/json"):
|
|
572
|
-
response_data = utils.
|
|
573
|
-
|
|
561
|
+
response_data = utils.unmarshal_json_response(
|
|
562
|
+
errors.ForbiddenData, http_res
|
|
563
|
+
)
|
|
564
|
+
raise errors.Forbidden(response_data, http_res)
|
|
574
565
|
if utils.match_response(http_res, "404", "application/json"):
|
|
575
|
-
response_data = utils.
|
|
576
|
-
raise errors.NotFound(
|
|
566
|
+
response_data = utils.unmarshal_json_response(errors.NotFoundData, http_res)
|
|
567
|
+
raise errors.NotFound(response_data, http_res)
|
|
577
568
|
if utils.match_response(http_res, "409", "application/json"):
|
|
578
|
-
response_data = utils.
|
|
579
|
-
raise errors.Conflict(
|
|
569
|
+
response_data = utils.unmarshal_json_response(errors.ConflictData, http_res)
|
|
570
|
+
raise errors.Conflict(response_data, http_res)
|
|
580
571
|
if utils.match_response(http_res, "410", "application/json"):
|
|
581
|
-
response_data = utils.
|
|
582
|
-
|
|
572
|
+
response_data = utils.unmarshal_json_response(
|
|
573
|
+
errors.InviteExpiredData, http_res
|
|
583
574
|
)
|
|
584
|
-
raise errors.InviteExpired(
|
|
575
|
+
raise errors.InviteExpired(response_data, http_res)
|
|
585
576
|
if utils.match_response(http_res, "422", "application/json"):
|
|
586
|
-
response_data = utils.
|
|
587
|
-
|
|
577
|
+
response_data = utils.unmarshal_json_response(
|
|
578
|
+
errors.UnprocessableEntityData, http_res
|
|
588
579
|
)
|
|
589
|
-
raise errors.UnprocessableEntity(
|
|
580
|
+
raise errors.UnprocessableEntity(response_data, http_res)
|
|
590
581
|
if utils.match_response(http_res, "429", "application/json"):
|
|
591
|
-
response_data = utils.
|
|
592
|
-
|
|
582
|
+
response_data = utils.unmarshal_json_response(
|
|
583
|
+
errors.RateLimitExceededData, http_res
|
|
593
584
|
)
|
|
594
|
-
raise errors.RateLimitExceeded(
|
|
585
|
+
raise errors.RateLimitExceeded(response_data, http_res)
|
|
595
586
|
if utils.match_response(http_res, "500", "application/json"):
|
|
596
|
-
response_data = utils.
|
|
597
|
-
|
|
587
|
+
response_data = utils.unmarshal_json_response(
|
|
588
|
+
errors.InternalServerErrorData, http_res
|
|
598
589
|
)
|
|
599
|
-
raise errors.InternalServerError(
|
|
590
|
+
raise errors.InternalServerError(response_data, http_res)
|
|
600
591
|
if utils.match_response(http_res, "4XX", "*"):
|
|
601
592
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
602
|
-
raise errors.SDKError(
|
|
603
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
604
|
-
)
|
|
593
|
+
raise errors.SDKError("API error occurred", http_res, http_res_text)
|
|
605
594
|
if utils.match_response(http_res, "5XX", "*"):
|
|
606
595
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
607
|
-
raise errors.SDKError(
|
|
608
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
609
|
-
)
|
|
596
|
+
raise errors.SDKError("API error occurred", http_res, http_res_text)
|
|
610
597
|
|
|
611
|
-
|
|
612
|
-
http_res_text = await utils.stream_to_text_async(http_res)
|
|
613
|
-
raise errors.SDKError(
|
|
614
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
615
|
-
http_res.status_code,
|
|
616
|
-
http_res_text,
|
|
617
|
-
http_res,
|
|
618
|
-
)
|
|
598
|
+
raise errors.SDKError("Unexpected response received", http_res)
|
dub/utils/__init__.py
CHANGED
|
@@ -28,6 +28,7 @@ if TYPE_CHECKING:
|
|
|
28
28
|
marshal_json,
|
|
29
29
|
unmarshal,
|
|
30
30
|
unmarshal_json,
|
|
31
|
+
unmarshal_json_response,
|
|
31
32
|
serialize_decimal,
|
|
32
33
|
serialize_float,
|
|
33
34
|
serialize_int,
|
|
@@ -96,6 +97,7 @@ __all__ = [
|
|
|
96
97
|
"template_url",
|
|
97
98
|
"unmarshal",
|
|
98
99
|
"unmarshal_json",
|
|
100
|
+
"unmarshal_json_response",
|
|
99
101
|
"validate_decimal",
|
|
100
102
|
"validate_const",
|
|
101
103
|
"validate_float",
|
|
@@ -149,6 +151,7 @@ _dynamic_imports: dict[str, str] = {
|
|
|
149
151
|
"template_url": ".url",
|
|
150
152
|
"unmarshal": ".serializers",
|
|
151
153
|
"unmarshal_json": ".serializers",
|
|
154
|
+
"unmarshal_json_response": ".serializers",
|
|
152
155
|
"validate_decimal": ".serializers",
|
|
153
156
|
"validate_const": ".serializers",
|
|
154
157
|
"validate_float": ".serializers",
|
dub/utils/serializers.py
CHANGED
|
@@ -4,7 +4,7 @@ from decimal import Decimal
|
|
|
4
4
|
import functools
|
|
5
5
|
import json
|
|
6
6
|
import typing
|
|
7
|
-
from typing import Any, Dict, List, Tuple, Union, get_args
|
|
7
|
+
from typing import Any, Dict, List, Optional, Tuple, Union, get_args
|
|
8
8
|
import typing_extensions
|
|
9
9
|
from typing_extensions import get_origin
|
|
10
10
|
|
|
@@ -13,6 +13,7 @@ from pydantic import ConfigDict, create_model
|
|
|
13
13
|
from pydantic_core import from_json
|
|
14
14
|
|
|
15
15
|
from ..types.basemodel import BaseModel, Nullable, OptionalNullable, Unset
|
|
16
|
+
from dub.models import errors
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
def serialize_decimal(as_str: bool):
|
|
@@ -140,6 +141,22 @@ def unmarshal_json(raw, typ: Any) -> Any:
|
|
|
140
141
|
return unmarshal(from_json(raw), typ)
|
|
141
142
|
|
|
142
143
|
|
|
144
|
+
def unmarshal_json_response(
|
|
145
|
+
typ: Any, http_res: httpx.Response, body: Optional[str] = None
|
|
146
|
+
) -> Any:
|
|
147
|
+
if body is None:
|
|
148
|
+
body = http_res.text
|
|
149
|
+
try:
|
|
150
|
+
return unmarshal_json(body, typ)
|
|
151
|
+
except Exception as e:
|
|
152
|
+
raise errors.ResponseValidationError(
|
|
153
|
+
"Response validation failed",
|
|
154
|
+
http_res,
|
|
155
|
+
e,
|
|
156
|
+
body,
|
|
157
|
+
) from e
|
|
158
|
+
|
|
159
|
+
|
|
143
160
|
def unmarshal(val, typ: Any) -> Any:
|
|
144
161
|
unmarshaller = create_model(
|
|
145
162
|
"Unmarshaller",
|
|
@@ -192,7 +209,9 @@ def is_union(obj: object) -> bool:
|
|
|
192
209
|
"""
|
|
193
210
|
Returns True if the given object is a typing.Union or typing_extensions.Union.
|
|
194
211
|
"""
|
|
195
|
-
return any(
|
|
212
|
+
return any(
|
|
213
|
+
obj is typing_obj for typing_obj in _get_typing_objects_by_name_of("Union")
|
|
214
|
+
)
|
|
196
215
|
|
|
197
216
|
|
|
198
217
|
def stream_to_text(stream: httpx.Response) -> str:
|
|
@@ -245,4 +264,3 @@ def _get_typing_objects_by_name_of(name: str) -> Tuple[Any, ...]:
|
|
|
245
264
|
f"Neither typing nor typing_extensions has an object called {name!r}"
|
|
246
265
|
)
|
|
247
266
|
return result
|
|
248
|
-
|