|
2 | 2 |
|
3 | 3 | import io |
4 | 4 | import os |
5 | | -from typing import IO, Dict, Union, Literal, Callable, cast |
| 5 | +from typing import Dict, Union, Literal, Callable |
6 | 6 | from pathlib import Path |
7 | 7 |
|
8 | | -from .._types import FileTypes |
9 | | -from .._utils import file_from_path |
10 | | - |
11 | 8 | LogCallback = Callable[[str], None] |
12 | | -UploadInput = Union[FileTypes, str, os.PathLike[str], Path, bytes, bytearray, io.IOBase] |
13 | 9 |
|
14 | 10 | ContentType = Literal["unspecified", "text", "binary", "gzip", "tar", "tgz"] |
15 | 11 | UploadData = Union[str, bytes, bytearray, Path, os.PathLike[str], io.IOBase] |
@@ -59,28 +55,3 @@ def read_upload_data(data: UploadData) -> bytes: |
59 | 55 | return result.encode("utf-8") |
60 | 56 | return result |
61 | 57 | raise TypeError("Unsupported upload data type. Provide str, bytes, path, or file-like object.") |
62 | | - |
63 | | - |
64 | | -def normalize_upload_input(file: UploadInput) -> FileTypes: |
65 | | - """ |
66 | | - Normalize a variety of Python file representations into the generated client's FileTypes. |
67 | | - """ |
68 | | - if isinstance(file, tuple): |
69 | | - return file |
70 | | - if isinstance(file, bytes): |
71 | | - return file |
72 | | - if isinstance(file, bytearray): |
73 | | - return bytes(file) |
74 | | - if isinstance(file, (str, Path, os.PathLike)): |
75 | | - path_str = str(file) |
76 | | - return file_from_path(path_str) |
77 | | - if isinstance(file, io.TextIOBase): |
78 | | - return file.read().encode("utf-8") |
79 | | - if isinstance(file, io.BufferedIOBase) or isinstance(file, io.RawIOBase): |
80 | | - return cast(IO[bytes], file) |
81 | | - if isinstance(file, io.IOBase) and hasattr(file, "read"): |
82 | | - data = file.read() |
83 | | - if isinstance(data, str): |
84 | | - return data.encode("utf-8") |
85 | | - return data |
86 | | - raise TypeError("Unsupported file type for upload. Provide path, bytes, or file-like object.") |
0 commit comments