dodopayments 1.51.1__py3-none-any.whl → 1.56.5__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.
- dodopayments/__init__.py +5 -1
- dodopayments/_base_client.py +12 -12
- dodopayments/_client.py +52 -14
- dodopayments/_compat.py +48 -48
- dodopayments/_exceptions.py +4 -0
- dodopayments/_models.py +50 -44
- dodopayments/_qs.py +7 -7
- dodopayments/_streaming.py +4 -6
- dodopayments/_types.py +18 -11
- dodopayments/_utils/__init__.py +8 -2
- dodopayments/_utils/_compat.py +45 -0
- dodopayments/_utils/_datetime_parse.py +136 -0
- dodopayments/_utils/_transform.py +13 -3
- dodopayments/_utils/_typing.py +1 -1
- dodopayments/_utils/_utils.py +5 -6
- dodopayments/_version.py +1 -1
- dodopayments/resources/__init__.py +28 -0
- dodopayments/resources/addons.py +29 -29
- dodopayments/resources/brands.py +29 -29
- dodopayments/resources/checkout_sessions.py +110 -27
- dodopayments/resources/customers/__init__.py +14 -0
- dodopayments/resources/customers/customer_portal.py +5 -5
- dodopayments/resources/customers/customers.py +53 -21
- dodopayments/resources/customers/wallets/__init__.py +33 -0
- dodopayments/resources/customers/wallets/ledger_entries.py +318 -0
- dodopayments/resources/customers/wallets/wallets.py +191 -0
- dodopayments/resources/discounts.py +44 -44
- dodopayments/resources/disputes.py +19 -19
- dodopayments/resources/invoices/payments.py +83 -3
- dodopayments/resources/license_key_instances.py +13 -13
- dodopayments/resources/license_keys.py +23 -23
- dodopayments/resources/licenses.py +14 -14
- dodopayments/resources/meters.py +554 -0
- dodopayments/resources/misc.py +3 -3
- dodopayments/resources/payments.py +49 -41
- dodopayments/resources/payouts.py +26 -7
- dodopayments/resources/products/images.py +5 -5
- dodopayments/resources/products/products.py +82 -82
- dodopayments/resources/refunds.py +39 -30
- dodopayments/resources/subscriptions.py +316 -73
- dodopayments/resources/usage_events.py +597 -0
- dodopayments/resources/webhooks/headers.py +5 -5
- dodopayments/resources/webhooks/webhooks.py +119 -44
- dodopayments/types/__init__.py +48 -0
- dodopayments/types/add_meter_to_price.py +29 -0
- dodopayments/types/add_meter_to_price_param.py +30 -0
- dodopayments/types/checkout_session_create_params.py +6 -0
- dodopayments/types/checkout_session_status.py +35 -0
- dodopayments/types/customer_limited_details.py +5 -0
- dodopayments/types/customers/__init__.py +2 -0
- dodopayments/types/customers/customer_wallet.py +20 -0
- dodopayments/types/customers/wallet_list_response.py +15 -0
- dodopayments/types/customers/wallets/__init__.py +7 -0
- dodopayments/types/customers/wallets/customer_wallet_transaction.py +38 -0
- dodopayments/types/customers/wallets/ledger_entry_create_params.py +25 -0
- dodopayments/types/customers/wallets/ledger_entry_list_params.py +18 -0
- dodopayments/types/discount_create_params.py +3 -2
- dodopayments/types/discount_update_params.py +3 -2
- dodopayments/types/dispute_accepted_webhook_event.py +29 -0
- dodopayments/types/dispute_accepted_webhook_event1.py +29 -0
- dodopayments/types/dispute_cancelled_webhook_event.py +29 -0
- dodopayments/types/dispute_cancelled_webhook_event1.py +29 -0
- dodopayments/types/dispute_challenged_webhook_event.py +29 -0
- dodopayments/types/dispute_challenged_webhook_event1.py +29 -0
- dodopayments/types/dispute_expired_webhook_event.py +29 -0
- dodopayments/types/dispute_expired_webhook_event1.py +29 -0
- dodopayments/types/dispute_lost_webhook_event.py +29 -0
- dodopayments/types/dispute_lost_webhook_event1.py +29 -0
- dodopayments/types/dispute_opened_webhook_event.py +29 -0
- dodopayments/types/dispute_opened_webhook_event1.py +29 -0
- dodopayments/types/dispute_won_webhook_event.py +29 -0
- dodopayments/types/dispute_won_webhook_event1.py +29 -0
- dodopayments/types/event.py +26 -0
- dodopayments/types/event_input_param.py +38 -0
- dodopayments/types/license_activate_response.py +40 -0
- dodopayments/types/license_key_created_webhook_event.py +29 -0
- dodopayments/types/license_key_created_webhook_event1.py +29 -0
- dodopayments/types/meter.py +40 -0
- dodopayments/types/meter_aggregation.py +16 -0
- dodopayments/types/meter_aggregation_param.py +16 -0
- dodopayments/types/meter_create_params.py +31 -0
- dodopayments/types/meter_filter.py +131 -0
- dodopayments/types/meter_filter_param.py +143 -0
- dodopayments/types/meter_list_params.py +18 -0
- dodopayments/types/new_customer_param.py +7 -1
- dodopayments/types/payment.py +37 -2
- dodopayments/types/payment_cancelled_webhook_event.py +29 -0
- dodopayments/types/payment_cancelled_webhook_event1.py +29 -0
- dodopayments/types/payment_create_params.py +3 -0
- dodopayments/types/payment_failed_webhook_event.py +29 -0
- dodopayments/types/payment_failed_webhook_event1.py +29 -0
- dodopayments/types/payment_method_types.py +1 -0
- dodopayments/types/payment_processing_webhook_event.py +29 -0
- dodopayments/types/payment_processing_webhook_event1.py +29 -0
- dodopayments/types/payment_succeeded_webhook_event.py +29 -0
- dodopayments/types/payment_succeeded_webhook_event1.py +29 -0
- dodopayments/types/payout_list_params.py +11 -1
- dodopayments/types/price.py +52 -5
- dodopayments/types/price_param.py +52 -5
- dodopayments/types/product_create_params.py +3 -2
- dodopayments/types/product_update_params.py +4 -3
- dodopayments/types/refund.py +8 -1
- dodopayments/types/refund_create_params.py +4 -1
- dodopayments/types/refund_failed_webhook_event.py +29 -0
- dodopayments/types/refund_failed_webhook_event1.py +29 -0
- dodopayments/types/refund_list_response.py +39 -0
- dodopayments/types/refund_succeeded_webhook_event.py +29 -0
- dodopayments/types/refund_succeeded_webhook_event1.py +29 -0
- dodopayments/types/subscription.py +23 -1
- dodopayments/types/subscription_active_webhook_event.py +29 -0
- dodopayments/types/subscription_active_webhook_event1.py +29 -0
- dodopayments/types/subscription_cancelled_webhook_event.py +29 -0
- dodopayments/types/subscription_cancelled_webhook_event1.py +29 -0
- dodopayments/types/subscription_charge_params.py +12 -1
- dodopayments/types/subscription_create_params.py +3 -0
- dodopayments/types/subscription_expired_webhook_event.py +29 -0
- dodopayments/types/subscription_expired_webhook_event1.py +29 -0
- dodopayments/types/subscription_failed_webhook_event.py +29 -0
- dodopayments/types/subscription_failed_webhook_event1.py +29 -0
- dodopayments/types/subscription_list_response.py +3 -0
- dodopayments/types/subscription_on_hold_webhook_event.py +29 -0
- dodopayments/types/subscription_on_hold_webhook_event1.py +29 -0
- dodopayments/types/subscription_plan_changed_webhook_event.py +29 -0
- dodopayments/types/subscription_plan_changed_webhook_event1.py +29 -0
- dodopayments/types/subscription_renewed_webhook_event.py +29 -0
- dodopayments/types/subscription_renewed_webhook_event1.py +29 -0
- dodopayments/types/subscription_retrieve_usage_history_params.py +28 -0
- dodopayments/types/subscription_retrieve_usage_history_response.py +46 -0
- dodopayments/types/subscription_update_params.py +2 -0
- dodopayments/types/unsafe_unwrap_webhook_event.py +52 -0
- dodopayments/types/unwrap_webhook_event.py +52 -0
- dodopayments/types/usage_event_ingest_params.py +15 -0
- dodopayments/types/usage_event_ingest_response.py +9 -0
- dodopayments/types/usage_event_list_params.py +42 -0
- {dodopayments-1.51.1.dist-info → dodopayments-1.56.5.dist-info}/METADATA +6 -4
- dodopayments-1.56.5.dist-info/RECORD +239 -0
- dodopayments-1.51.1.dist-info/RECORD +0 -163
- {dodopayments-1.51.1.dist-info → dodopayments-1.56.5.dist-info}/WHEEL +0 -0
- {dodopayments-1.51.1.dist-info → dodopayments-1.56.5.dist-info}/licenses/LICENSE +0 -0
dodopayments/_models.py
CHANGED
|
@@ -50,7 +50,7 @@ from ._utils import (
|
|
|
50
50
|
strip_annotated_type,
|
|
51
51
|
)
|
|
52
52
|
from ._compat import (
|
|
53
|
-
|
|
53
|
+
PYDANTIC_V1,
|
|
54
54
|
ConfigDict,
|
|
55
55
|
GenericModel as BaseGenericModel,
|
|
56
56
|
get_args,
|
|
@@ -81,11 +81,7 @@ class _ConfigProtocol(Protocol):
|
|
|
81
81
|
|
|
82
82
|
|
|
83
83
|
class BaseModel(pydantic.BaseModel):
|
|
84
|
-
if
|
|
85
|
-
model_config: ClassVar[ConfigDict] = ConfigDict(
|
|
86
|
-
extra="allow", defer_build=coerce_boolean(os.environ.get("DEFER_PYDANTIC_BUILD", "true"))
|
|
87
|
-
)
|
|
88
|
-
else:
|
|
84
|
+
if PYDANTIC_V1:
|
|
89
85
|
|
|
90
86
|
@property
|
|
91
87
|
@override
|
|
@@ -95,6 +91,10 @@ class BaseModel(pydantic.BaseModel):
|
|
|
95
91
|
|
|
96
92
|
class Config(pydantic.BaseConfig): # pyright: ignore[reportDeprecated]
|
|
97
93
|
extra: Any = pydantic.Extra.allow # type: ignore
|
|
94
|
+
else:
|
|
95
|
+
model_config: ClassVar[ConfigDict] = ConfigDict(
|
|
96
|
+
extra="allow", defer_build=coerce_boolean(os.environ.get("DEFER_PYDANTIC_BUILD", "true"))
|
|
97
|
+
)
|
|
98
98
|
|
|
99
99
|
def to_dict(
|
|
100
100
|
self,
|
|
@@ -215,25 +215,25 @@ class BaseModel(pydantic.BaseModel):
|
|
|
215
215
|
if key not in model_fields:
|
|
216
216
|
parsed = construct_type(value=value, type_=extra_field_type) if extra_field_type is not None else value
|
|
217
217
|
|
|
218
|
-
if
|
|
219
|
-
_extra[key] = parsed
|
|
220
|
-
else:
|
|
218
|
+
if PYDANTIC_V1:
|
|
221
219
|
_fields_set.add(key)
|
|
222
220
|
fields_values[key] = parsed
|
|
221
|
+
else:
|
|
222
|
+
_extra[key] = parsed
|
|
223
223
|
|
|
224
224
|
object.__setattr__(m, "__dict__", fields_values)
|
|
225
225
|
|
|
226
|
-
if
|
|
227
|
-
# these properties are copied from Pydantic's `model_construct()` method
|
|
228
|
-
object.__setattr__(m, "__pydantic_private__", None)
|
|
229
|
-
object.__setattr__(m, "__pydantic_extra__", _extra)
|
|
230
|
-
object.__setattr__(m, "__pydantic_fields_set__", _fields_set)
|
|
231
|
-
else:
|
|
226
|
+
if PYDANTIC_V1:
|
|
232
227
|
# init_private_attributes() does not exist in v2
|
|
233
228
|
m._init_private_attributes() # type: ignore
|
|
234
229
|
|
|
235
230
|
# copied from Pydantic v1's `construct()` method
|
|
236
231
|
object.__setattr__(m, "__fields_set__", _fields_set)
|
|
232
|
+
else:
|
|
233
|
+
# these properties are copied from Pydantic's `model_construct()` method
|
|
234
|
+
object.__setattr__(m, "__pydantic_private__", None)
|
|
235
|
+
object.__setattr__(m, "__pydantic_extra__", _extra)
|
|
236
|
+
object.__setattr__(m, "__pydantic_fields_set__", _fields_set)
|
|
237
237
|
|
|
238
238
|
return m
|
|
239
239
|
|
|
@@ -243,7 +243,7 @@ class BaseModel(pydantic.BaseModel):
|
|
|
243
243
|
# although not in practice
|
|
244
244
|
model_construct = construct
|
|
245
245
|
|
|
246
|
-
if
|
|
246
|
+
if PYDANTIC_V1:
|
|
247
247
|
# we define aliases for some of the new pydantic v2 methods so
|
|
248
248
|
# that we can just document these methods without having to specify
|
|
249
249
|
# a specific pydantic version as some users may not know which
|
|
@@ -256,7 +256,7 @@ class BaseModel(pydantic.BaseModel):
|
|
|
256
256
|
mode: Literal["json", "python"] | str = "python",
|
|
257
257
|
include: IncEx | None = None,
|
|
258
258
|
exclude: IncEx | None = None,
|
|
259
|
-
by_alias: bool =
|
|
259
|
+
by_alias: bool | None = None,
|
|
260
260
|
exclude_unset: bool = False,
|
|
261
261
|
exclude_defaults: bool = False,
|
|
262
262
|
exclude_none: bool = False,
|
|
@@ -264,6 +264,7 @@ class BaseModel(pydantic.BaseModel):
|
|
|
264
264
|
warnings: bool | Literal["none", "warn", "error"] = True,
|
|
265
265
|
context: dict[str, Any] | None = None,
|
|
266
266
|
serialize_as_any: bool = False,
|
|
267
|
+
fallback: Callable[[Any], Any] | None = None,
|
|
267
268
|
) -> dict[str, Any]:
|
|
268
269
|
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump
|
|
269
270
|
|
|
@@ -295,10 +296,12 @@ class BaseModel(pydantic.BaseModel):
|
|
|
295
296
|
raise ValueError("context is only supported in Pydantic v2")
|
|
296
297
|
if serialize_as_any != False:
|
|
297
298
|
raise ValueError("serialize_as_any is only supported in Pydantic v2")
|
|
299
|
+
if fallback is not None:
|
|
300
|
+
raise ValueError("fallback is only supported in Pydantic v2")
|
|
298
301
|
dumped = super().dict( # pyright: ignore[reportDeprecated]
|
|
299
302
|
include=include,
|
|
300
303
|
exclude=exclude,
|
|
301
|
-
by_alias=by_alias,
|
|
304
|
+
by_alias=by_alias if by_alias is not None else False,
|
|
302
305
|
exclude_unset=exclude_unset,
|
|
303
306
|
exclude_defaults=exclude_defaults,
|
|
304
307
|
exclude_none=exclude_none,
|
|
@@ -313,13 +316,14 @@ class BaseModel(pydantic.BaseModel):
|
|
|
313
316
|
indent: int | None = None,
|
|
314
317
|
include: IncEx | None = None,
|
|
315
318
|
exclude: IncEx | None = None,
|
|
316
|
-
by_alias: bool =
|
|
319
|
+
by_alias: bool | None = None,
|
|
317
320
|
exclude_unset: bool = False,
|
|
318
321
|
exclude_defaults: bool = False,
|
|
319
322
|
exclude_none: bool = False,
|
|
320
323
|
round_trip: bool = False,
|
|
321
324
|
warnings: bool | Literal["none", "warn", "error"] = True,
|
|
322
325
|
context: dict[str, Any] | None = None,
|
|
326
|
+
fallback: Callable[[Any], Any] | None = None,
|
|
323
327
|
serialize_as_any: bool = False,
|
|
324
328
|
) -> str:
|
|
325
329
|
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump_json
|
|
@@ -348,11 +352,13 @@ class BaseModel(pydantic.BaseModel):
|
|
|
348
352
|
raise ValueError("context is only supported in Pydantic v2")
|
|
349
353
|
if serialize_as_any != False:
|
|
350
354
|
raise ValueError("serialize_as_any is only supported in Pydantic v2")
|
|
355
|
+
if fallback is not None:
|
|
356
|
+
raise ValueError("fallback is only supported in Pydantic v2")
|
|
351
357
|
return super().json( # type: ignore[reportDeprecated]
|
|
352
358
|
indent=indent,
|
|
353
359
|
include=include,
|
|
354
360
|
exclude=exclude,
|
|
355
|
-
by_alias=by_alias,
|
|
361
|
+
by_alias=by_alias if by_alias is not None else False,
|
|
356
362
|
exclude_unset=exclude_unset,
|
|
357
363
|
exclude_defaults=exclude_defaults,
|
|
358
364
|
exclude_none=exclude_none,
|
|
@@ -363,10 +369,10 @@ def _construct_field(value: object, field: FieldInfo, key: str) -> object:
|
|
|
363
369
|
if value is None:
|
|
364
370
|
return field_get_default(field)
|
|
365
371
|
|
|
366
|
-
if
|
|
367
|
-
type_ = field.annotation
|
|
368
|
-
else:
|
|
372
|
+
if PYDANTIC_V1:
|
|
369
373
|
type_ = cast(type, field.outer_type_) # type: ignore
|
|
374
|
+
else:
|
|
375
|
+
type_ = field.annotation # type: ignore
|
|
370
376
|
|
|
371
377
|
if type_ is None:
|
|
372
378
|
raise RuntimeError(f"Unexpected field type is None for {key}")
|
|
@@ -375,7 +381,7 @@ def _construct_field(value: object, field: FieldInfo, key: str) -> object:
|
|
|
375
381
|
|
|
376
382
|
|
|
377
383
|
def _get_extra_fields_type(cls: type[pydantic.BaseModel]) -> type | None:
|
|
378
|
-
if
|
|
384
|
+
if PYDANTIC_V1:
|
|
379
385
|
# TODO
|
|
380
386
|
return None
|
|
381
387
|
|
|
@@ -628,30 +634,30 @@ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any,
|
|
|
628
634
|
for variant in get_args(union):
|
|
629
635
|
variant = strip_annotated_type(variant)
|
|
630
636
|
if is_basemodel_type(variant):
|
|
631
|
-
if
|
|
632
|
-
|
|
633
|
-
if not
|
|
637
|
+
if PYDANTIC_V1:
|
|
638
|
+
field_info = cast("dict[str, FieldInfo]", variant.__fields__).get(discriminator_field_name) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
|
|
639
|
+
if not field_info:
|
|
634
640
|
continue
|
|
635
641
|
|
|
636
642
|
# Note: if one variant defines an alias then they all should
|
|
637
|
-
discriminator_alias =
|
|
638
|
-
|
|
639
|
-
field_schema = field["schema"]
|
|
643
|
+
discriminator_alias = field_info.alias
|
|
640
644
|
|
|
641
|
-
if
|
|
642
|
-
for entry in
|
|
645
|
+
if (annotation := getattr(field_info, "annotation", None)) and is_literal_type(annotation):
|
|
646
|
+
for entry in get_args(annotation):
|
|
643
647
|
if isinstance(entry, str):
|
|
644
648
|
mapping[entry] = variant
|
|
645
649
|
else:
|
|
646
|
-
|
|
647
|
-
if not
|
|
650
|
+
field = _extract_field_schema_pv2(variant, discriminator_field_name)
|
|
651
|
+
if not field:
|
|
648
652
|
continue
|
|
649
653
|
|
|
650
654
|
# Note: if one variant defines an alias then they all should
|
|
651
|
-
discriminator_alias =
|
|
655
|
+
discriminator_alias = field.get("serialization_alias")
|
|
652
656
|
|
|
653
|
-
|
|
654
|
-
|
|
657
|
+
field_schema = field["schema"]
|
|
658
|
+
|
|
659
|
+
if field_schema["type"] == "literal":
|
|
660
|
+
for entry in cast("LiteralSchema", field_schema)["expected"]:
|
|
655
661
|
if isinstance(entry, str):
|
|
656
662
|
mapping[entry] = variant
|
|
657
663
|
|
|
@@ -714,7 +720,7 @@ else:
|
|
|
714
720
|
pass
|
|
715
721
|
|
|
716
722
|
|
|
717
|
-
if
|
|
723
|
+
if not PYDANTIC_V1:
|
|
718
724
|
from pydantic import TypeAdapter as _TypeAdapter
|
|
719
725
|
|
|
720
726
|
_CachedTypeAdapter = cast("TypeAdapter[object]", lru_cache(maxsize=None)(_TypeAdapter))
|
|
@@ -782,12 +788,12 @@ class FinalRequestOptions(pydantic.BaseModel):
|
|
|
782
788
|
json_data: Union[Body, None] = None
|
|
783
789
|
extra_json: Union[AnyMapping, None] = None
|
|
784
790
|
|
|
785
|
-
if
|
|
786
|
-
model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True)
|
|
787
|
-
else:
|
|
791
|
+
if PYDANTIC_V1:
|
|
788
792
|
|
|
789
793
|
class Config(pydantic.BaseConfig): # pyright: ignore[reportDeprecated]
|
|
790
794
|
arbitrary_types_allowed: bool = True
|
|
795
|
+
else:
|
|
796
|
+
model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True)
|
|
791
797
|
|
|
792
798
|
def get_max_retries(self, max_retries: int) -> int:
|
|
793
799
|
if isinstance(self.max_retries, NotGiven):
|
|
@@ -820,9 +826,9 @@ class FinalRequestOptions(pydantic.BaseModel):
|
|
|
820
826
|
key: strip_not_given(value)
|
|
821
827
|
for key, value in values.items()
|
|
822
828
|
}
|
|
823
|
-
if
|
|
824
|
-
return super().
|
|
825
|
-
return
|
|
829
|
+
if PYDANTIC_V1:
|
|
830
|
+
return cast(FinalRequestOptions, super().construct(_fields_set, **kwargs)) # pyright: ignore[reportDeprecated]
|
|
831
|
+
return super().model_construct(_fields_set, **kwargs)
|
|
826
832
|
|
|
827
833
|
if not TYPE_CHECKING:
|
|
828
834
|
# type checkers incorrectly complain about this assignment
|
dodopayments/_qs.py
CHANGED
|
@@ -4,7 +4,7 @@ from typing import Any, List, Tuple, Union, Mapping, TypeVar
|
|
|
4
4
|
from urllib.parse import parse_qs, urlencode
|
|
5
5
|
from typing_extensions import Literal, get_args
|
|
6
6
|
|
|
7
|
-
from ._types import
|
|
7
|
+
from ._types import NotGiven, not_given
|
|
8
8
|
from ._utils import flatten
|
|
9
9
|
|
|
10
10
|
_T = TypeVar("_T")
|
|
@@ -41,8 +41,8 @@ class Querystring:
|
|
|
41
41
|
self,
|
|
42
42
|
params: Params,
|
|
43
43
|
*,
|
|
44
|
-
array_format:
|
|
45
|
-
nested_format:
|
|
44
|
+
array_format: ArrayFormat | NotGiven = not_given,
|
|
45
|
+
nested_format: NestedFormat | NotGiven = not_given,
|
|
46
46
|
) -> str:
|
|
47
47
|
return urlencode(
|
|
48
48
|
self.stringify_items(
|
|
@@ -56,8 +56,8 @@ class Querystring:
|
|
|
56
56
|
self,
|
|
57
57
|
params: Params,
|
|
58
58
|
*,
|
|
59
|
-
array_format:
|
|
60
|
-
nested_format:
|
|
59
|
+
array_format: ArrayFormat | NotGiven = not_given,
|
|
60
|
+
nested_format: NestedFormat | NotGiven = not_given,
|
|
61
61
|
) -> list[tuple[str, str]]:
|
|
62
62
|
opts = Options(
|
|
63
63
|
qs=self,
|
|
@@ -143,8 +143,8 @@ class Options:
|
|
|
143
143
|
self,
|
|
144
144
|
qs: Querystring = _qs,
|
|
145
145
|
*,
|
|
146
|
-
array_format:
|
|
147
|
-
nested_format:
|
|
146
|
+
array_format: ArrayFormat | NotGiven = not_given,
|
|
147
|
+
nested_format: NestedFormat | NotGiven = not_given,
|
|
148
148
|
) -> None:
|
|
149
149
|
self.array_format = qs.array_format if isinstance(array_format, NotGiven) else array_format
|
|
150
150
|
self.nested_format = qs.nested_format if isinstance(nested_format, NotGiven) else nested_format
|
dodopayments/_streaming.py
CHANGED
|
@@ -57,9 +57,8 @@ class Stream(Generic[_T]):
|
|
|
57
57
|
for sse in iterator:
|
|
58
58
|
yield process_data(data=sse.json(), cast_to=cast_to, response=response)
|
|
59
59
|
|
|
60
|
-
#
|
|
61
|
-
|
|
62
|
-
...
|
|
60
|
+
# As we might not fully consume the response stream, we need to close it explicitly
|
|
61
|
+
response.close()
|
|
63
62
|
|
|
64
63
|
def __enter__(self) -> Self:
|
|
65
64
|
return self
|
|
@@ -121,9 +120,8 @@ class AsyncStream(Generic[_T]):
|
|
|
121
120
|
async for sse in iterator:
|
|
122
121
|
yield process_data(data=sse.json(), cast_to=cast_to, response=response)
|
|
123
122
|
|
|
124
|
-
#
|
|
125
|
-
|
|
126
|
-
...
|
|
123
|
+
# As we might not fully consume the response stream, we need to close it explicitly
|
|
124
|
+
await response.aclose()
|
|
127
125
|
|
|
128
126
|
async def __aenter__(self) -> Self:
|
|
129
127
|
return self
|
dodopayments/_types.py
CHANGED
|
@@ -117,18 +117,21 @@ class RequestOptions(TypedDict, total=False):
|
|
|
117
117
|
# Sentinel class used until PEP 0661 is accepted
|
|
118
118
|
class NotGiven:
|
|
119
119
|
"""
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
For parameters with a meaningful None value, we need to distinguish between
|
|
121
|
+
the user explicitly passing None, and the user not passing the parameter at
|
|
122
|
+
all.
|
|
123
|
+
|
|
124
|
+
User code shouldn't need to use not_given directly.
|
|
122
125
|
|
|
123
126
|
For example:
|
|
124
127
|
|
|
125
128
|
```py
|
|
126
|
-
def
|
|
129
|
+
def create(timeout: Timeout | None | NotGiven = not_given): ...
|
|
127
130
|
|
|
128
131
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
+
create(timeout=1) # 1s timeout
|
|
133
|
+
create(timeout=None) # No timeout
|
|
134
|
+
create() # Default timeout behavior
|
|
132
135
|
```
|
|
133
136
|
"""
|
|
134
137
|
|
|
@@ -140,13 +143,14 @@ class NotGiven:
|
|
|
140
143
|
return "NOT_GIVEN"
|
|
141
144
|
|
|
142
145
|
|
|
143
|
-
|
|
146
|
+
not_given = NotGiven()
|
|
147
|
+
# for backwards compatibility:
|
|
144
148
|
NOT_GIVEN = NotGiven()
|
|
145
149
|
|
|
146
150
|
|
|
147
151
|
class Omit:
|
|
148
|
-
"""
|
|
149
|
-
|
|
152
|
+
"""
|
|
153
|
+
To explicitly omit something from being sent in a request, use `omit`.
|
|
150
154
|
|
|
151
155
|
```py
|
|
152
156
|
# as the default `Content-Type` header is `application/json` that will be sent
|
|
@@ -156,8 +160,8 @@ class Omit:
|
|
|
156
160
|
# to look something like: 'multipart/form-data; boundary=0d8382fcf5f8c3be01ca2e11002d2983'
|
|
157
161
|
client.post(..., headers={"Content-Type": "multipart/form-data"})
|
|
158
162
|
|
|
159
|
-
# instead you can remove the default `application/json` header by passing
|
|
160
|
-
client.post(..., headers={"Content-Type":
|
|
163
|
+
# instead you can remove the default `application/json` header by passing omit
|
|
164
|
+
client.post(..., headers={"Content-Type": omit})
|
|
161
165
|
```
|
|
162
166
|
"""
|
|
163
167
|
|
|
@@ -165,6 +169,9 @@ class Omit:
|
|
|
165
169
|
return False
|
|
166
170
|
|
|
167
171
|
|
|
172
|
+
omit = Omit()
|
|
173
|
+
|
|
174
|
+
|
|
168
175
|
@runtime_checkable
|
|
169
176
|
class ModelBuilderProtocol(Protocol):
|
|
170
177
|
@classmethod
|
dodopayments/_utils/__init__.py
CHANGED
|
@@ -10,7 +10,6 @@ from ._utils import (
|
|
|
10
10
|
lru_cache as lru_cache,
|
|
11
11
|
is_mapping as is_mapping,
|
|
12
12
|
is_tuple_t as is_tuple_t,
|
|
13
|
-
parse_date as parse_date,
|
|
14
13
|
is_iterable as is_iterable,
|
|
15
14
|
is_sequence as is_sequence,
|
|
16
15
|
coerce_float as coerce_float,
|
|
@@ -23,7 +22,6 @@ from ._utils import (
|
|
|
23
22
|
coerce_boolean as coerce_boolean,
|
|
24
23
|
coerce_integer as coerce_integer,
|
|
25
24
|
file_from_path as file_from_path,
|
|
26
|
-
parse_datetime as parse_datetime,
|
|
27
25
|
strip_not_given as strip_not_given,
|
|
28
26
|
deepcopy_minimal as deepcopy_minimal,
|
|
29
27
|
get_async_library as get_async_library,
|
|
@@ -32,6 +30,13 @@ from ._utils import (
|
|
|
32
30
|
maybe_coerce_boolean as maybe_coerce_boolean,
|
|
33
31
|
maybe_coerce_integer as maybe_coerce_integer,
|
|
34
32
|
)
|
|
33
|
+
from ._compat import (
|
|
34
|
+
get_args as get_args,
|
|
35
|
+
is_union as is_union,
|
|
36
|
+
get_origin as get_origin,
|
|
37
|
+
is_typeddict as is_typeddict,
|
|
38
|
+
is_literal_type as is_literal_type,
|
|
39
|
+
)
|
|
35
40
|
from ._typing import (
|
|
36
41
|
is_list_type as is_list_type,
|
|
37
42
|
is_union_type as is_union_type,
|
|
@@ -56,3 +61,4 @@ from ._reflection import (
|
|
|
56
61
|
function_has_argument as function_has_argument,
|
|
57
62
|
assert_signatures_in_sync as assert_signatures_in_sync,
|
|
58
63
|
)
|
|
64
|
+
from ._datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import typing_extensions
|
|
5
|
+
from typing import Any, Type, Union, Literal, Optional
|
|
6
|
+
from datetime import date, datetime
|
|
7
|
+
from typing_extensions import get_args as _get_args, get_origin as _get_origin
|
|
8
|
+
|
|
9
|
+
from .._types import StrBytesIntFloat
|
|
10
|
+
from ._datetime_parse import parse_date as _parse_date, parse_datetime as _parse_datetime
|
|
11
|
+
|
|
12
|
+
_LITERAL_TYPES = {Literal, typing_extensions.Literal}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def get_args(tp: type[Any]) -> tuple[Any, ...]:
|
|
16
|
+
return _get_args(tp)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_origin(tp: type[Any]) -> type[Any] | None:
|
|
20
|
+
return _get_origin(tp)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def is_union(tp: Optional[Type[Any]]) -> bool:
|
|
24
|
+
if sys.version_info < (3, 10):
|
|
25
|
+
return tp is Union # type: ignore[comparison-overlap]
|
|
26
|
+
else:
|
|
27
|
+
import types
|
|
28
|
+
|
|
29
|
+
return tp is Union or tp is types.UnionType
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def is_typeddict(tp: Type[Any]) -> bool:
|
|
33
|
+
return typing_extensions.is_typeddict(tp)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def is_literal_type(tp: Type[Any]) -> bool:
|
|
37
|
+
return get_origin(tp) in _LITERAL_TYPES
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def parse_date(value: Union[date, StrBytesIntFloat]) -> date:
|
|
41
|
+
return _parse_date(value)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def parse_datetime(value: Union[datetime, StrBytesIntFloat]) -> datetime:
|
|
45
|
+
return _parse_datetime(value)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This file contains code from https://github.com/pydantic/pydantic/blob/main/pydantic/v1/datetime_parse.py
|
|
3
|
+
without the Pydantic v1 specific errors.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import re
|
|
9
|
+
from typing import Dict, Union, Optional
|
|
10
|
+
from datetime import date, datetime, timezone, timedelta
|
|
11
|
+
|
|
12
|
+
from .._types import StrBytesIntFloat
|
|
13
|
+
|
|
14
|
+
date_expr = r"(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})"
|
|
15
|
+
time_expr = (
|
|
16
|
+
r"(?P<hour>\d{1,2}):(?P<minute>\d{1,2})"
|
|
17
|
+
r"(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?"
|
|
18
|
+
r"(?P<tzinfo>Z|[+-]\d{2}(?::?\d{2})?)?$"
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
date_re = re.compile(f"{date_expr}$")
|
|
22
|
+
datetime_re = re.compile(f"{date_expr}[T ]{time_expr}")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
EPOCH = datetime(1970, 1, 1)
|
|
26
|
+
# if greater than this, the number is in ms, if less than or equal it's in seconds
|
|
27
|
+
# (in seconds this is 11th October 2603, in ms it's 20th August 1970)
|
|
28
|
+
MS_WATERSHED = int(2e10)
|
|
29
|
+
# slightly more than datetime.max in ns - (datetime.max - EPOCH).total_seconds() * 1e9
|
|
30
|
+
MAX_NUMBER = int(3e20)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _get_numeric(value: StrBytesIntFloat, native_expected_type: str) -> Union[None, int, float]:
|
|
34
|
+
if isinstance(value, (int, float)):
|
|
35
|
+
return value
|
|
36
|
+
try:
|
|
37
|
+
return float(value)
|
|
38
|
+
except ValueError:
|
|
39
|
+
return None
|
|
40
|
+
except TypeError:
|
|
41
|
+
raise TypeError(f"invalid type; expected {native_expected_type}, string, bytes, int or float") from None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _from_unix_seconds(seconds: Union[int, float]) -> datetime:
|
|
45
|
+
if seconds > MAX_NUMBER:
|
|
46
|
+
return datetime.max
|
|
47
|
+
elif seconds < -MAX_NUMBER:
|
|
48
|
+
return datetime.min
|
|
49
|
+
|
|
50
|
+
while abs(seconds) > MS_WATERSHED:
|
|
51
|
+
seconds /= 1000
|
|
52
|
+
dt = EPOCH + timedelta(seconds=seconds)
|
|
53
|
+
return dt.replace(tzinfo=timezone.utc)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _parse_timezone(value: Optional[str]) -> Union[None, int, timezone]:
|
|
57
|
+
if value == "Z":
|
|
58
|
+
return timezone.utc
|
|
59
|
+
elif value is not None:
|
|
60
|
+
offset_mins = int(value[-2:]) if len(value) > 3 else 0
|
|
61
|
+
offset = 60 * int(value[1:3]) + offset_mins
|
|
62
|
+
if value[0] == "-":
|
|
63
|
+
offset = -offset
|
|
64
|
+
return timezone(timedelta(minutes=offset))
|
|
65
|
+
else:
|
|
66
|
+
return None
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def parse_datetime(value: Union[datetime, StrBytesIntFloat]) -> datetime:
|
|
70
|
+
"""
|
|
71
|
+
Parse a datetime/int/float/string and return a datetime.datetime.
|
|
72
|
+
|
|
73
|
+
This function supports time zone offsets. When the input contains one,
|
|
74
|
+
the output uses a timezone with a fixed offset from UTC.
|
|
75
|
+
|
|
76
|
+
Raise ValueError if the input is well formatted but not a valid datetime.
|
|
77
|
+
Raise ValueError if the input isn't well formatted.
|
|
78
|
+
"""
|
|
79
|
+
if isinstance(value, datetime):
|
|
80
|
+
return value
|
|
81
|
+
|
|
82
|
+
number = _get_numeric(value, "datetime")
|
|
83
|
+
if number is not None:
|
|
84
|
+
return _from_unix_seconds(number)
|
|
85
|
+
|
|
86
|
+
if isinstance(value, bytes):
|
|
87
|
+
value = value.decode()
|
|
88
|
+
|
|
89
|
+
assert not isinstance(value, (float, int))
|
|
90
|
+
|
|
91
|
+
match = datetime_re.match(value)
|
|
92
|
+
if match is None:
|
|
93
|
+
raise ValueError("invalid datetime format")
|
|
94
|
+
|
|
95
|
+
kw = match.groupdict()
|
|
96
|
+
if kw["microsecond"]:
|
|
97
|
+
kw["microsecond"] = kw["microsecond"].ljust(6, "0")
|
|
98
|
+
|
|
99
|
+
tzinfo = _parse_timezone(kw.pop("tzinfo"))
|
|
100
|
+
kw_: Dict[str, Union[None, int, timezone]] = {k: int(v) for k, v in kw.items() if v is not None}
|
|
101
|
+
kw_["tzinfo"] = tzinfo
|
|
102
|
+
|
|
103
|
+
return datetime(**kw_) # type: ignore
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def parse_date(value: Union[date, StrBytesIntFloat]) -> date:
|
|
107
|
+
"""
|
|
108
|
+
Parse a date/int/float/string and return a datetime.date.
|
|
109
|
+
|
|
110
|
+
Raise ValueError if the input is well formatted but not a valid date.
|
|
111
|
+
Raise ValueError if the input isn't well formatted.
|
|
112
|
+
"""
|
|
113
|
+
if isinstance(value, date):
|
|
114
|
+
if isinstance(value, datetime):
|
|
115
|
+
return value.date()
|
|
116
|
+
else:
|
|
117
|
+
return value
|
|
118
|
+
|
|
119
|
+
number = _get_numeric(value, "date")
|
|
120
|
+
if number is not None:
|
|
121
|
+
return _from_unix_seconds(number).date()
|
|
122
|
+
|
|
123
|
+
if isinstance(value, bytes):
|
|
124
|
+
value = value.decode()
|
|
125
|
+
|
|
126
|
+
assert not isinstance(value, (float, int))
|
|
127
|
+
match = date_re.match(value)
|
|
128
|
+
if match is None:
|
|
129
|
+
raise ValueError("invalid date format")
|
|
130
|
+
|
|
131
|
+
kw = {k: int(v) for k, v in match.groupdict().items()}
|
|
132
|
+
|
|
133
|
+
try:
|
|
134
|
+
return date(**kw)
|
|
135
|
+
except ValueError:
|
|
136
|
+
raise ValueError("invalid date format") from None
|
|
@@ -16,18 +16,20 @@ from ._utils import (
|
|
|
16
16
|
lru_cache,
|
|
17
17
|
is_mapping,
|
|
18
18
|
is_iterable,
|
|
19
|
+
is_sequence,
|
|
19
20
|
)
|
|
20
21
|
from .._files import is_base64_file_input
|
|
22
|
+
from ._compat import get_origin, is_typeddict
|
|
21
23
|
from ._typing import (
|
|
22
24
|
is_list_type,
|
|
23
25
|
is_union_type,
|
|
24
26
|
extract_type_arg,
|
|
25
27
|
is_iterable_type,
|
|
26
28
|
is_required_type,
|
|
29
|
+
is_sequence_type,
|
|
27
30
|
is_annotated_type,
|
|
28
31
|
strip_annotated_type,
|
|
29
32
|
)
|
|
30
|
-
from .._compat import get_origin, model_dump, is_typeddict
|
|
31
33
|
|
|
32
34
|
_T = TypeVar("_T")
|
|
33
35
|
|
|
@@ -167,6 +169,8 @@ def _transform_recursive(
|
|
|
167
169
|
|
|
168
170
|
Defaults to the same value as the `annotation` argument.
|
|
169
171
|
"""
|
|
172
|
+
from .._compat import model_dump
|
|
173
|
+
|
|
170
174
|
if inner_type is None:
|
|
171
175
|
inner_type = annotation
|
|
172
176
|
|
|
@@ -184,6 +188,8 @@ def _transform_recursive(
|
|
|
184
188
|
(is_list_type(stripped_type) and is_list(data))
|
|
185
189
|
# Iterable[T]
|
|
186
190
|
or (is_iterable_type(stripped_type) and is_iterable(data) and not isinstance(data, str))
|
|
191
|
+
# Sequence[T]
|
|
192
|
+
or (is_sequence_type(stripped_type) and is_sequence(data) and not isinstance(data, str))
|
|
187
193
|
):
|
|
188
194
|
# dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually
|
|
189
195
|
# intended as an iterable, so we don't transform it.
|
|
@@ -262,7 +268,7 @@ def _transform_typeddict(
|
|
|
262
268
|
annotations = get_type_hints(expected_type, include_extras=True)
|
|
263
269
|
for key, value in data.items():
|
|
264
270
|
if not is_given(value):
|
|
265
|
-
# we don't need to include
|
|
271
|
+
# we don't need to include omitted values here as they'll
|
|
266
272
|
# be stripped out before the request is sent anyway
|
|
267
273
|
continue
|
|
268
274
|
|
|
@@ -329,6 +335,8 @@ async def _async_transform_recursive(
|
|
|
329
335
|
|
|
330
336
|
Defaults to the same value as the `annotation` argument.
|
|
331
337
|
"""
|
|
338
|
+
from .._compat import model_dump
|
|
339
|
+
|
|
332
340
|
if inner_type is None:
|
|
333
341
|
inner_type = annotation
|
|
334
342
|
|
|
@@ -346,6 +354,8 @@ async def _async_transform_recursive(
|
|
|
346
354
|
(is_list_type(stripped_type) and is_list(data))
|
|
347
355
|
# Iterable[T]
|
|
348
356
|
or (is_iterable_type(stripped_type) and is_iterable(data) and not isinstance(data, str))
|
|
357
|
+
# Sequence[T]
|
|
358
|
+
or (is_sequence_type(stripped_type) and is_sequence(data) and not isinstance(data, str))
|
|
349
359
|
):
|
|
350
360
|
# dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually
|
|
351
361
|
# intended as an iterable, so we don't transform it.
|
|
@@ -424,7 +434,7 @@ async def _async_transform_typeddict(
|
|
|
424
434
|
annotations = get_type_hints(expected_type, include_extras=True)
|
|
425
435
|
for key, value in data.items():
|
|
426
436
|
if not is_given(value):
|
|
427
|
-
# we don't need to include
|
|
437
|
+
# we don't need to include omitted values here as they'll
|
|
428
438
|
# be stripped out before the request is sent anyway
|
|
429
439
|
continue
|
|
430
440
|
|
dodopayments/_utils/_typing.py
CHANGED