|
2 | 2 |
|
3 | 3 | import sys |
4 | 4 | from typing import TYPE_CHECKING |
5 | | -from zipfile import ZipInfo |
6 | 5 |
|
| 6 | +from upath.core import UnsupportedOperation |
7 | 7 | from upath.core import UPath |
8 | 8 | from upath.types import JoinablePathLike |
9 | 9 |
|
@@ -35,41 +35,36 @@ def __init__( |
35 | 35 | **storage_options: Unpack[ZipStorageOptions], |
36 | 36 | ) -> None: ... |
37 | 37 |
|
38 | | - if sys.version_info >= (3, 11): |
| 38 | + @classmethod |
| 39 | + def _transform_init_args(cls, args, protocol, storage_options): |
| 40 | + if storage_options.get("mode") in {"a", "x", "w"}: |
| 41 | + raise UnsupportedOperation( |
| 42 | + "ZipPath write mode disabled in universal-pathlib" |
| 43 | + ) |
| 44 | + return super()._transform_init_args(args, protocol, storage_options) |
39 | 45 |
|
40 | | - def mkdir( |
41 | | - self, |
42 | | - mode: int = 0o777, |
43 | | - parents: bool = False, |
44 | | - exist_ok: bool = False, |
45 | | - ) -> None: |
46 | | - is_dir = self.is_dir() |
47 | | - if is_dir and not exist_ok: |
48 | | - raise FileExistsError(f"File exists: {self.path!r}") |
49 | | - elif not is_dir: |
50 | | - zipfile = self.fs.zip |
51 | | - zipfile.mkdir(self.path, mode) |
| 46 | + def touch(self, mode: int = 0o666, exist_ok: bool = True) -> None: |
| 47 | + raise UnsupportedOperation |
52 | 48 |
|
53 | | - else: |
| 49 | + def mkdir( |
| 50 | + self, |
| 51 | + mode: int = 0o777, |
| 52 | + parents: bool = False, |
| 53 | + exist_ok: bool = False, |
| 54 | + ) -> None: |
| 55 | + raise UnsupportedOperation |
54 | 56 |
|
55 | | - def mkdir( |
56 | | - self, |
57 | | - mode: int = 0o777, |
58 | | - parents: bool = False, |
59 | | - exist_ok: bool = False, |
60 | | - ) -> None: |
61 | | - is_dir = self.is_dir() |
62 | | - if is_dir and not exist_ok: |
63 | | - raise FileExistsError(f"File exists: {self.path!r}") |
64 | | - elif not is_dir: |
65 | | - dirname = self.path |
66 | | - if dirname and not dirname.endswith("/"): |
67 | | - dirname += "/" |
68 | | - zipfile = self.fs.zip |
69 | | - zinfo = ZipInfo(dirname) |
70 | | - zinfo.compress_size = 0 |
71 | | - zinfo.CRC = 0 |
72 | | - zinfo.external_attr = ((0o40000 | mode) & 0xFFFF) << 16 |
73 | | - zinfo.file_size = 0 |
74 | | - zinfo.external_attr |= 0x10 |
75 | | - zipfile.writestr(zinfo, b"") |
| 57 | + def unlink(self, missing_ok: bool = False) -> None: |
| 58 | + raise UnsupportedOperation |
| 59 | + |
| 60 | + def write_bytes(self, data: bytes) -> int: |
| 61 | + raise UnsupportedOperation("DataPath does not support writing") |
| 62 | + |
| 63 | + def write_text( |
| 64 | + self, |
| 65 | + data: str, |
| 66 | + encoding: str | None = None, |
| 67 | + errors: str | None = None, |
| 68 | + newline: str | None = None, |
| 69 | + ) -> int: |
| 70 | + raise UnsupportedOperation("DataPath does not support writing") |
0 commit comments