Repository navigation
Expand file tree
/
Copy pathbase.py
More file actions
55 lines (44 loc) · 2.7 KB
/
Copy pathbase.py
File metadata and controls
55 lines (44 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from typing import List, Dict, Protocol, runtime_checkable, Tuple, AsyncIterator, Any
from models import StorageAdapter
# 约定:任意新适配器模块需定义:
# ADAPTER_TYPE: str
# CONFIG_SCHEMA: List[Dict]
# ADAPTER_FACTORY: Callable[[StorageAdapter], BaseAdapter] (可省略, 会自动寻找 *Adapter 类)
@runtime_checkable
class BaseAdapter(Protocol):
record: StorageAdapter
async def list_dir(self, root: str, rel: str, page_num: int = 1, page_size: int = 50, sort_by: str = "name", sort_order: str = "asc", cursor: str | None = None) -> Tuple[List[Dict], int] | Dict[str, Any]: ...
async def read_file(self, root: str, rel: str) -> bytes: ...
async def write_file(self, root: str, rel: str, data: bytes): ...
async def write_file_stream(self, root: str, rel: str, data_iter: AsyncIterator[bytes]): ...
async def mkdir(self, root: str, rel: str): ...
async def delete(self, root: str, rel: str): ...
async def move(self, root: str, src_rel: str, dst_rel: str): ...
async def rename(self, root: str, src_rel: str, dst_rel: str): ...
async def copy(self, root: str, src_rel: str, dst_rel: str, overwrite: bool = False): ...
async def stream_file(self, root: str, rel: str, range_header: str | None): ...
async def stat_file(self, root: str, rel: str): ...
def get_effective_root(self, sub_path: str | None) -> str: ...
@runtime_checkable
class UsageCapableAdapter(Protocol):
async def get_usage(self, root: str) -> Dict: ...
@runtime_checkable
class CompressionCapableAdapter(Protocol):
async def get_compression_capabilities(self, root: str, rel: str) -> Dict: ...
async def compress(self, root: str, source_rels: List[str], dst_rel: str) -> Dict: ...
@runtime_checkable
class ExtractionCapableAdapter(Protocol):
async def get_extraction_capabilities(self, root: str, rel: str) -> Dict: ...
async def extract(self, root: str, src_rel: str, dst_rel: str) -> Dict: ...
@runtime_checkable
class ExtractionCleanupAdapter(Protocol):
"""Optional exclusive creation and guarded, nonrecursive extraction cleanup.
Creation fills an opaque receipt only after acquiring the new path. File receipts
must also cover partial writes on failure. Cleanup preserves changed objects and
returns a public reason, None for removal, or "" for an already missing path.
An adapter without these guarantees must leave extraction output in place.
"""
supports_safe_extraction_cleanup: bool
async def create_extraction_directory(self, root: str, rel: str, receipt: dict): ...
async def write_extraction_file(self, root: str, rel: str, incoming, receipt: dict): ...
async def cleanup_extraction_path(self, root: str, rel: str, receipt: dict) -> str | None: ...