|
5 | 5 | from collections.abc import Generator
|
6 | 6 | from datetime import date, datetime
|
7 | 7 | from decimal import Decimal
|
8 |
| -from typing import Any, Callable |
9 | 8 |
|
10 | 9 | import requests
|
11 | 10 | from tenacity import (
|
|
15 | 14 | wait_random_exponential,
|
16 | 15 | )
|
17 | 16 |
|
18 |
| - |
19 |
| -__all__ = ("FioBank", "ThrottlingError") |
20 |
| - |
21 |
| - |
22 |
| -def coerce_amount(value: int | float) -> Decimal: |
23 |
| - if isinstance(value, int): |
24 |
| - return Decimal(value) |
25 |
| - if isinstance(value, float): |
26 |
| - return Decimal(str(value)) |
27 |
| - raise ValueError(value) |
28 |
| - |
29 |
| - |
30 |
| -def coerce_date(value: datetime | date | str) -> date: |
31 |
| - if isinstance(value, datetime): |
32 |
| - return value.date() |
33 |
| - if isinstance(value, date): |
34 |
| - return value |
35 |
| - return datetime.strptime(value[:10], "%Y-%m-%d").date() |
36 |
| - |
37 |
| - |
38 |
| -def sanitize_value(value: Any, convert: Callable | None = None) -> Any: |
39 |
| - if isinstance(value, str): |
40 |
| - value = value.strip() or None |
41 |
| - if convert and value is not None: |
42 |
| - return convert(value) |
43 |
| - return value |
44 |
| - |
45 |
| - |
46 |
| -class ThrottlingError(Exception): |
47 |
| - """Throttling error raised when the API is being used too fast.""" |
48 |
| - |
49 |
| - def __str__(self) -> str: |
50 |
| - return "Token can be used only once per 30s" |
| 17 | +from .exceptions import ThrottlingError |
| 18 | +from .utils import coerce_date, sanitize_value |
51 | 19 |
|
52 | 20 |
|
53 | 21 | class FioBank:
|
|
0 commit comments