Coverage for /home/fedora/jumpstarter/packages/jumpstarter-driver-opendal/jumpstarter_driver_opendal/common.py: 90%
72 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-05 20:29 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-05 20:29 +0000
1# Reference: https://github.com/apache/opendal/blob/main/bindings/python/python/opendal/__init__.pyi
2import warnings
3from os import PathLike
4from typing import Any, Literal, Optional
6import opendal
7from pydantic import BaseModel, Field, model_validator
9warnings.filterwarnings(
10 "ignore", 'Field name "copy" in "Capability" shadows an attribute in parent "BaseModel"', UserWarning
11)
13Mode = Literal["rb", "wb"]
14HashAlgo = Literal["md5", "sha256"]
15PathBuf = str | PathLike
18class EntryMode(BaseModel):
19 entry_is_file: bool = Field(serialization_alias="is_file")
20 entry_is_dir: bool = Field(serialization_alias="is_dir")
22 @model_validator(mode="before")
23 @classmethod
24 def __validate(cls, data: Any):
25 match data:
26 case opendal.EntryMode():
27 return EntryMode(
28 entry_is_file=data.is_file(),
29 entry_is_dir=data.is_dir(),
30 )
31 case _:
32 return data
34 def is_file(self) -> bool:
35 return self.entry_is_file
37 def is_dir(self) -> bool:
38 return self.entry_is_dir
41class Metadata(BaseModel):
42 content_disposition: Optional[str]
43 content_length: int
44 content_md5: Optional[str]
45 content_type: Optional[str]
46 etag: Optional[str]
47 mode: EntryMode
50class PresignedRequest(BaseModel):
51 """
52 Presigned HTTP request
54 Allows you to delegate access to a specific file in your storage backend
55 without sharing access credentials
56 """
58 url: str
59 """
60 HTTP request URL
61 """
62 method: str
63 """
64 HTTP method
66 GET: download file
68 PUT: upload file
70 DELETE: delete file
71 """
72 headers: dict[str, str]
73 """
74 Additional HTTP headers to send with the request
75 """
78class Capability(BaseModel):
79 stat: bool
80 stat_with_if_match: bool
81 stat_with_if_none_match: bool
83 read: bool
84 read_with_if_match: bool
85 read_with_if_none_match: bool
86 read_with_override_cache_control: bool
87 read_with_override_content_disposition: bool
88 read_with_override_content_type: bool
90 write: bool
91 write_can_multi: bool
92 write_can_empty: bool
93 write_can_append: bool
94 write_with_content_type: bool
95 write_with_content_disposition: bool
96 write_with_cache_control: bool
97 write_multi_max_size: Optional[int]
98 write_multi_min_size: Optional[int]
99 write_total_max_size: Optional[int]
101 create_dir: bool
102 delete: bool
103 copy: bool
104 rename: bool
106 list: bool
107 list_with_limit: bool
108 list_with_start_after: bool
109 list_with_recursive: bool
111 presign: bool
112 presign_read: bool
113 presign_stat: bool
114 presign_write: bool
116 shared: bool
117 blocking: bool