rtzip 0.5.1__tar.gz → 0.5.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {rtzip-0.5.1 → rtzip-0.5.3}/PKG-INFO +1 -1
- {rtzip-0.5.1 → rtzip-0.5.3}/pyproject.toml +1 -1
- {rtzip-0.5.1 → rtzip-0.5.3}/pyproject.toml.orig +1 -1
- {rtzip-0.5.1 → rtzip-0.5.3}/src/rtzip/remotezip.py +29 -8
- {rtzip-0.5.1 → rtzip-0.5.3}/src/rtzip/wzaes_backends/cryptography_impl.py +2 -4
- {rtzip-0.5.1 → rtzip-0.5.3}/src/rtzip/zip_aes.py +3 -3
- {rtzip-0.5.1 → rtzip-0.5.3}/src/rtzip/zip_crypto.py +1 -1
- {rtzip-0.5.1 → rtzip-0.5.3}/src/rtzip/__init__.py +0 -0
- {rtzip-0.5.1 → rtzip-0.5.3}/src/rtzip/algorithm_register.py +0 -0
- {rtzip-0.5.1 → rtzip-0.5.3}/src/rtzip/codec_wrappers.py +0 -0
- {rtzip-0.5.1 → rtzip-0.5.3}/src/rtzip/const.py +0 -0
- {rtzip-0.5.1 → rtzip-0.5.3}/src/rtzip/errors.py +0 -0
- {rtzip-0.5.1 → rtzip-0.5.3}/src/rtzip/models.py +0 -0
- {rtzip-0.5.1 → rtzip-0.5.3}/src/rtzip/path_methods.py +0 -0
- {rtzip-0.5.1 → rtzip-0.5.3}/src/rtzip/wzaes_backends/__init__.py +0 -0
- {rtzip-0.5.1 → rtzip-0.5.3}/src/rtzip/wzaes_backends/pycryptodome_impl.py +0 -0
|
@@ -39,7 +39,7 @@ class DataSource:
|
|
|
39
39
|
"""
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
async def single_chunk_wrapper(__data:
|
|
42
|
+
async def single_chunk_wrapper[T](__data: T, /):
|
|
43
43
|
yield __data
|
|
44
44
|
|
|
45
45
|
|
|
@@ -54,6 +54,10 @@ class RemoteZip:
|
|
|
54
54
|
:ivar files: 中央目录文件列表
|
|
55
55
|
:ivar file_mapping: 构建的文件映射表,可能为 None
|
|
56
56
|
:ivar is_zip64: 此 zip 文件是否启动了 zip64 扩展,默认为 False
|
|
57
|
+
:ivar context: 上下文字典
|
|
58
|
+
上下文字典信息:
|
|
59
|
+
- ``pwd``: 字节形式的密码,用于解密加密的 zip 文件
|
|
60
|
+
|
|
57
61
|
"""
|
|
58
62
|
|
|
59
63
|
async def _read_range(self, offset, length):
|
|
@@ -81,7 +85,7 @@ class RemoteZip:
|
|
|
81
85
|
|
|
82
86
|
self.is_zip64 = False
|
|
83
87
|
self.context = kwargs
|
|
84
|
-
self._namelist = None
|
|
88
|
+
self._namelist: list[bytes] | None = None
|
|
85
89
|
|
|
86
90
|
def _merge_context(self, overrides: dict[str, Any]):
|
|
87
91
|
return {
|
|
@@ -89,10 +93,15 @@ class RemoteZip:
|
|
|
89
93
|
**overrides
|
|
90
94
|
}
|
|
91
95
|
|
|
92
|
-
def namelist(self):
|
|
96
|
+
def namelist(self) -> list[bytes]:
|
|
97
|
+
"""
|
|
98
|
+
获取所有的文件名(bytes)列表
|
|
99
|
+
:return: 文件名列表
|
|
100
|
+
"""
|
|
93
101
|
if self._namelist is None:
|
|
94
102
|
if self.files is None:
|
|
95
103
|
raise ValueError("No files. Please call `fetch_file_list()` first")
|
|
104
|
+
|
|
96
105
|
self._namelist = [
|
|
97
106
|
f.filename for f in self.files
|
|
98
107
|
]
|
|
@@ -167,7 +176,7 @@ class RemoteZip:
|
|
|
167
176
|
|
|
168
177
|
# print(zip64_eocd_disk_id, zip64_eocd_offset, zip64_total_disks)
|
|
169
178
|
|
|
170
|
-
zip64_eocd_data = await self._read_range(zip64_eocd_offset, 96)
|
|
179
|
+
zip64_eocd_data = bytes(await self._read_range(zip64_eocd_offset, 96))
|
|
171
180
|
# print(zip64_eocd_data[:64])
|
|
172
181
|
assert zip64_eocd_data[:4] == ZIP64_EOCD_SIGNATURE
|
|
173
182
|
|
|
@@ -324,7 +333,7 @@ class RemoteZip:
|
|
|
324
333
|
从本地已有的数据获取 filename 对应的 CDEntry 对象
|
|
325
334
|
|
|
326
335
|
如果已有构建好的文件映射,则直接查找文件映射内容
|
|
327
|
-
|
|
336
|
+
否则将遍历中央目录找到文件
|
|
328
337
|
|
|
329
338
|
若是发现文件不存在,将会抛出 FileNotFoundError
|
|
330
339
|
|
|
@@ -390,7 +399,7 @@ class RemoteZip:
|
|
|
390
399
|
|
|
391
400
|
async def read(self, filename: bytes, **kwargs) -> bytearray:
|
|
392
401
|
"""
|
|
393
|
-
|
|
402
|
+
全量加载文件的内容(底层仍然调用 .stream 方法)
|
|
394
403
|
|
|
395
404
|
建议在小文件上使用此方法
|
|
396
405
|
|
|
@@ -404,7 +413,16 @@ class RemoteZip:
|
|
|
404
413
|
return buffer
|
|
405
414
|
|
|
406
415
|
|
|
407
|
-
async def resolve(self, filename: bytes, max_resolve=24, **kwargs) -> bytes:
|
|
416
|
+
async def resolve(self, filename: bytes, max_resolve: float | int = 24, **kwargs) -> bytes:
|
|
417
|
+
"""
|
|
418
|
+
解析一个文件的最终路径(基于 zip 的符号链接规范)
|
|
419
|
+
|
|
420
|
+
:param filename: 文件名
|
|
421
|
+
:param max_resolve: 最大可解析次数(你可以通过传入 ``float('inf')`` 来不限制解析次数,但不建议这样做
|
|
422
|
+
:param kwargs: 上下文信息
|
|
423
|
+
:raise ValueError: 当解析次数达到指定的上限时抛出
|
|
424
|
+
:return:
|
|
425
|
+
"""
|
|
408
426
|
kwargs = self._merge_context(kwargs)
|
|
409
427
|
entry = self.find_file_entry(filename)
|
|
410
428
|
target = entry.filename
|
|
@@ -419,6 +437,9 @@ class RemoteZip:
|
|
|
419
437
|
|
|
420
438
|
cnt += 1
|
|
421
439
|
|
|
440
|
+
if cnt >= max_resolve:
|
|
441
|
+
raise ValueError("Too many resolved files")
|
|
442
|
+
|
|
422
443
|
return target
|
|
423
444
|
|
|
424
445
|
def listdir(self, path: bytes) -> list[bytes]:
|
|
@@ -454,7 +475,7 @@ class RemoteZip:
|
|
|
454
475
|
return (await self.read(path, **kwargs)).decode(encoding, errors=errors)
|
|
455
476
|
|
|
456
477
|
def rglob(self, pattern):
|
|
457
|
-
for file in self.
|
|
478
|
+
for file in self.namelist():
|
|
458
479
|
if fnmatch(file, pattern):
|
|
459
480
|
yield file
|
|
460
481
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# Written by DeepSeek
|
|
2
|
-
import itertools
|
|
3
2
|
import warnings
|
|
4
3
|
|
|
5
4
|
from cryptography.hazmat.primitives import hashes
|
|
@@ -25,13 +24,12 @@ class CryptographyAESCipher:
|
|
|
25
24
|
self._c = 1
|
|
26
25
|
self._b = bytearray()
|
|
27
26
|
|
|
28
|
-
|
|
29
27
|
@classmethod
|
|
30
28
|
def get_cipher(cls, enc_key: bytes):
|
|
31
29
|
return cls(enc_key)
|
|
32
30
|
|
|
33
31
|
def update(self, encrypted_data: bytes) -> bytes:
|
|
34
|
-
print(f"拼接:{len(self._b)} + {len(encrypted_data)} = {len(self._b) + len(encrypted_data)}")
|
|
32
|
+
# print(f"拼接:{len(self._b)} + {len(encrypted_data)} = {len(self._b) + len(encrypted_data)}")
|
|
35
33
|
self._b.extend(encrypted_data)
|
|
36
34
|
buffer = bytearray()
|
|
37
35
|
|
|
@@ -49,7 +47,7 @@ class CryptographyAESCipher:
|
|
|
49
47
|
|
|
50
48
|
else:
|
|
51
49
|
self._b = self._b[offset:]
|
|
52
|
-
print("裁剪:", len(self._b))
|
|
50
|
+
# print("裁剪:", len(self._b))
|
|
53
51
|
break
|
|
54
52
|
|
|
55
53
|
return buffer
|
|
@@ -291,7 +291,7 @@ def zip_aes_wrapper(raw_data, entry, header, ctx):
|
|
|
291
291
|
)
|
|
292
292
|
|
|
293
293
|
|
|
294
|
-
def install(pbkdf2_hmac: PBKDF2_HMAC_FunctionType, aes_cipher: type[AESDecryptor]):
|
|
295
|
-
pbkdf2_hmac_implement(pbkdf2_hmac)
|
|
296
|
-
aes_cipher_implement(aes_cipher)
|
|
294
|
+
def install(pbkdf2_hmac: PBKDF2_HMAC_FunctionType | None = None, aes_cipher: type[AESDecryptor] | None = None):
|
|
295
|
+
pbkdf2_hmac_implement(pbkdf2_hmac) if pbkdf2_hmac else None
|
|
296
|
+
aes_cipher_implement(aes_cipher) if aes_cipher else None
|
|
297
297
|
algorithm_handler(0x0063)(zip_aes_wrapper) if not is_algorithm_handlier_available(0x0063) else None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|