aiohttp-zip-response 1.0.0__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.
- aiohttp_zip_response-1.0.0/LICENSE +7 -0
- aiohttp_zip_response-1.0.0/PKG-INFO +54 -0
- aiohttp_zip_response-1.0.0/README.md +25 -0
- aiohttp_zip_response-1.0.0/aiohttp_zip_response/__init__.py +3 -0
- aiohttp_zip_response-1.0.0/aiohttp_zip_response/zip_response.py +48 -0
- aiohttp_zip_response-1.0.0/pyproject.toml +49 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2024 Jonathan Ehwald
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: aiohttp-zip-response
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A AIOHTTP response class streaming a directory as ZIP archive
|
|
5
|
+
Home-page: https://github.com/DoctorJohn/aiohttp-zip-response
|
|
6
|
+
License: MIT
|
|
7
|
+
Author: Jonathan Ehwald
|
|
8
|
+
Author-email: github@ehwald.info
|
|
9
|
+
Requires-Python: >=3.9,<4.0
|
|
10
|
+
Classifier: Environment :: Web Environment
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
21
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
22
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
23
|
+
Requires-Dist: aiohttp (>=3.9.5,<4.0.0)
|
|
24
|
+
Requires-Dist: stream-zip (>=0.0.71,<0.0.72)
|
|
25
|
+
Project-URL: Documentation, https://github.com/DoctorJohn/aiohttp-zip-response
|
|
26
|
+
Project-URL: Repository, https://github.com/DoctorJohn/aiohttp-zip-response
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# AIOHTTP ZIP Response
|
|
30
|
+
|
|
31
|
+
A AIOHTTP response class streaming a directory as ZIP archive.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install aiohttp-zip-response
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from aiohttp import web
|
|
43
|
+
from aiohttp_zip_response import ZipResponse
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
async def handle_zip(request):
|
|
47
|
+
return ZipResponse('path/to/directory')
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
app = web.Application()
|
|
51
|
+
app.router.add_get('/zip', handle_zip)
|
|
52
|
+
web.run_app(app)
|
|
53
|
+
```
|
|
54
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# AIOHTTP ZIP Response
|
|
2
|
+
|
|
3
|
+
A AIOHTTP response class streaming a directory as ZIP archive.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install aiohttp-zip-response
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from aiohttp import web
|
|
15
|
+
from aiohttp_zip_response import ZipResponse
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async def handle_zip(request):
|
|
19
|
+
return ZipResponse('path/to/directory')
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
app = web.Application()
|
|
23
|
+
app.router.add_get('/zip', handle_zip)
|
|
24
|
+
web.run_app(app)
|
|
25
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import AsyncGenerator, Optional
|
|
4
|
+
|
|
5
|
+
from aiohttp import web
|
|
6
|
+
from aiohttp.typedefs import LooseHeaders, PathLike
|
|
7
|
+
from stream_zip import ZIP_32, async_stream_zip # type: ignore
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ZipResponse(web.Response):
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
path: PathLike,
|
|
14
|
+
chunk_size: int = 256 * 1024,
|
|
15
|
+
status: int = 200,
|
|
16
|
+
reason: Optional[str] = None,
|
|
17
|
+
headers: Optional[LooseHeaders] = None,
|
|
18
|
+
) -> None:
|
|
19
|
+
self._path = Path(path)
|
|
20
|
+
self._chunk_size = chunk_size
|
|
21
|
+
return super().__init__(
|
|
22
|
+
body=async_stream_zip(self.yield_members()),
|
|
23
|
+
status=status,
|
|
24
|
+
reason=reason,
|
|
25
|
+
headers=headers,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
async def yield_members(self):
|
|
29
|
+
for sub_path in self._path.glob("**/*"):
|
|
30
|
+
lstat = sub_path.lstat()
|
|
31
|
+
yield (
|
|
32
|
+
str(sub_path.relative_to(self._path)),
|
|
33
|
+
datetime.fromtimestamp(lstat.st_mtime),
|
|
34
|
+
lstat.st_mode,
|
|
35
|
+
ZIP_32,
|
|
36
|
+
self.yield_contents(sub_path),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
async def yield_contents(self, file_path: Path) -> AsyncGenerator[bytes, None]:
|
|
40
|
+
if file_path.is_dir():
|
|
41
|
+
return
|
|
42
|
+
|
|
43
|
+
with file_path.open("rb") as file:
|
|
44
|
+
while True:
|
|
45
|
+
chunk = file.read(self._chunk_size)
|
|
46
|
+
if not chunk:
|
|
47
|
+
break
|
|
48
|
+
yield chunk
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "aiohttp-zip-response"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "A AIOHTTP response class streaming a directory as ZIP archive"
|
|
5
|
+
authors = ["Jonathan Ehwald <github@ehwald.info>"]
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
homepage = "https://github.com/DoctorJohn/aiohttp-zip-response"
|
|
9
|
+
repository = "https://github.com/DoctorJohn/aiohttp-zip-response"
|
|
10
|
+
documentation = "https://github.com/DoctorJohn/aiohttp-zip-response"
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Environment :: Web Environment",
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"License :: OSI Approved :: MIT License",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
"Programming Language :: Python",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.8",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
24
|
+
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[tool.poetry.dependencies]
|
|
28
|
+
python = "^3.9"
|
|
29
|
+
aiohttp = "^3.9.5"
|
|
30
|
+
stream-zip = "^0.0.71"
|
|
31
|
+
|
|
32
|
+
[tool.poetry.group.dev.dependencies]
|
|
33
|
+
pre-commit = "^3.7.1"
|
|
34
|
+
pytest = "^8.2.0"
|
|
35
|
+
pytest-cov = "^5.0.0"
|
|
36
|
+
pytest-asyncio = "^0.23.6"
|
|
37
|
+
pytest-aiohttp = "^1.0.5"
|
|
38
|
+
ruff = "^0.4.4"
|
|
39
|
+
mypy = "^1.10.0"
|
|
40
|
+
|
|
41
|
+
[tool.ruff.lint]
|
|
42
|
+
extend-select = ["I"]
|
|
43
|
+
|
|
44
|
+
[tool.pytest.ini_options]
|
|
45
|
+
asyncio_mode = "auto"
|
|
46
|
+
|
|
47
|
+
[build-system]
|
|
48
|
+
requires = ["poetry-core"]
|
|
49
|
+
build-backend = "poetry.core.masonry.api"
|