|
2 | 2 | from __future__ import absolute_import, division, print_function, unicode_literals |
3 | 3 |
|
4 | 4 | import tinify |
5 | | -from . import Result, ResultMeta |
| 5 | +import sys |
| 6 | +from tinify.result import Result |
| 7 | +from tinify.result_meta import ResultMeta |
6 | 8 |
|
7 | 9 | try: |
8 | | - from typing import Union, Dict, IO, Any, TypedDict, List, Literal, Optional, Unpack, TYPE_CHECKING, overload |
9 | | - |
10 | | - class ResizeOptions(TypedDict, total=False): |
11 | | - method: Literal['scale', 'fit', 'cover', 'thumb'] |
12 | | - width: int |
13 | | - height: int |
14 | | - |
15 | | - ConvertTypes = Literal['image/webp', 'image/jpeg', 'image/png', "image/avif", "*/*"] |
16 | | - class ConvertOptions(TypedDict, total=False): |
17 | | - type: Union[ConvertTypes, List[ConvertTypes]] |
18 | | - |
19 | | - class TransformOptions(TypedDict, total=False): |
20 | | - background: str | Literal["white", "black"] |
21 | | - |
22 | | - class S3StoreOptions(TypedDict, total=False): |
23 | | - service: Literal['s3'] |
24 | | - aws_access_key_id: str |
25 | | - aws_secret_access_key: str |
26 | | - region: str |
27 | | - path: str |
28 | | - headers: Optional[Dict[str, str]] |
29 | | - acl: Optional[Literal["no-acl"]] |
30 | | - |
31 | | - class GCSStoreOptions(TypedDict, total=False): |
32 | | - service: Literal['gcs'] |
33 | | - gcp_access_token: str |
34 | | - path: str |
35 | | - headers: Optional[Dict[str, str]] |
36 | | - |
37 | | - PreserveOption = Literal['copyright', 'creation', 'location'] |
| 10 | + from typing import Union, Dict, IO, Any, List, Literal, Optional, Unpack, TYPE_CHECKING, overload |
| 11 | + if sys.version_info.major > 3 and sys.version_info.minor > 8: |
| 12 | + from tinify.typed import * |
38 | 13 | except ImportError: |
39 | 14 | TYPE_CHECKING = False # type: ignore |
40 | 15 |
|
41 | | - |
42 | | - |
43 | 16 | class Source(object): |
44 | 17 | @classmethod |
45 | 18 | def from_file(cls, path): # type: (Union[str, IO]) -> Source |
@@ -81,11 +54,11 @@ def transform(self, **options): # type: (Unpack[TransformOptions]) -> "Source" |
81 | 54 | if TYPE_CHECKING: |
82 | 55 | @overload |
83 | 56 | def store(self, **options): # type: (Unpack[S3StoreOptions]) -> ResultMeta |
84 | | - ... |
| 57 | + pass |
85 | 58 |
|
86 | 59 | @overload |
87 | 60 | def store(self, **options): # type: (Unpack[GCSStoreOptions]) -> ResultMeta |
88 | | - ... |
| 61 | + pass |
89 | 62 |
|
90 | 63 | def store(self, **options): # type: (Any) -> ResultMeta |
91 | 64 | response = tinify.get_client().request('POST', self.url, self._merge_commands(store=options)) |
|
0 commit comments