alogithms 1.0.1__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.
- alogithms-1.0.1/LICENSE +21 -0
- alogithms-1.0.1/PKG-INFO +80 -0
- alogithms-1.0.1/README.md +46 -0
- alogithms-1.0.1/README_PLS.md +63 -0
- alogithms-1.0.1/alogithms/__init__.py +48 -0
- alogithms-1.0.1/alogithms/add.py +5 -0
- alogithms-1.0.1/alogithms/devide.py +174 -0
- alogithms-1.0.1/alogithms/exponents.py +406 -0
- alogithms-1.0.1/alogithms/multi.py +251 -0
- alogithms-1.0.1/alogithms/subtract.py +5 -0
- alogithms-1.0.1/alogithms.egg-info/PKG-INFO +80 -0
- alogithms-1.0.1/alogithms.egg-info/SOURCES.txt +23 -0
- alogithms-1.0.1/alogithms.egg-info/dependency_links.txt +1 -0
- alogithms-1.0.1/alogithms.egg-info/top_level.txt +1 -0
- alogithms-1.0.1/alogithms.pth +1 -0
- alogithms-1.0.1/pyproject.toml +18 -0
- alogithms-1.0.1/setup.cfg +4 -0
- alogithms-1.0.1/setup.py +19 -0
- alogithms-1.0.1/tests/test_devide.py +184 -0
- alogithms-1.0.1/tests/test_exponents.py +154 -0
- alogithms-1.0.1/tests/test_module1.py +12 -0
- alogithms-1.0.1/tests/test_module2.py +83 -0
- alogithms-1.0.1/tests/test_multi.py +52 -0
- alogithms-1.0.1/tests/test_release.py +79 -0
- alogithms-1.0.1/tests/test_reply.py +91 -0
alogithms-1.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wsc33332f
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
alogithms-1.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: alogithms
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: A simple Python library
|
|
5
|
+
Home-page: https://github.com/wsc33332f/reply
|
|
6
|
+
Author: Kirik
|
|
7
|
+
Author-email: Your Name <email@example.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Requires-Python: >=3.6
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Dynamic: author
|
|
14
|
+
Dynamic: home-page
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
Dynamic: requires-python
|
|
17
|
+
|
|
18
|
+
# alogithms
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
`alogithms` is a small Python package for studying basic library design and
|
|
22
|
+
common Python tasks:
|
|
23
|
+
|
|
24
|
+
- arithmetic helpers
|
|
25
|
+
|
|
26
|
+
## Requirements
|
|
27
|
+
|
|
28
|
+
- Python 3.9 or newer
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Install the package from the repository root:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
python -m pip install .
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## Public API
|
|
39
|
+
|
|
40
|
+
The package exports these helpers:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import alogithms
|
|
44
|
+
|
|
45
|
+
alogithms.add(2, 3)
|
|
46
|
+
alogithms.subtract(7, 4)
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import alogithms
|
|
53
|
+
|
|
54
|
+
print(alogithms.add(2, 3)) # 5
|
|
55
|
+
print(alogithms.subtract(7, 4)) # 3
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## File transfer CLI
|
|
59
|
+
|
|
60
|
+
Download a URL to a local path:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
python3 -m alogithms.devide --download https://example.com/file.bin --output file.bin
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Upload a local file to a URL:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
python3 -m alogithms.devide --upload https://example.com/upload --file file.bin
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Downloads refuse to overwrite an existing file unless `--overwrite` is given.
|
|
73
|
+
Uploads send the file as the raw request body using HTTP POST.
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
Run the unit tests:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
python -m unittest discover -s tests -v
|
|
80
|
+
```
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# alogithms
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
`alogithms` is a small Python package for studying basic library design and
|
|
5
|
+
common Python tasks:
|
|
6
|
+
|
|
7
|
+
- arithmetic helpers
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- Python 3.9 or newer
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Install the package from the repository root:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
python -m pip install .
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Public API
|
|
22
|
+
|
|
23
|
+
The package exports these helpers:
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import alogithms
|
|
27
|
+
|
|
28
|
+
alogithms.add(2, 3)
|
|
29
|
+
alogithms.subtract(7, 4)
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
import alogithms
|
|
36
|
+
|
|
37
|
+
print(alogithms.add(2, 3)) # 5
|
|
38
|
+
print(alogithms.subtract(7, 4)) # 3
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
Run the unit tests:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
python -m unittest discover -s tests -v
|
|
46
|
+
```
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# alogithms
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
`alogithms` is a small Python package for studying basic library design and
|
|
5
|
+
common Python tasks:
|
|
6
|
+
|
|
7
|
+
- arithmetic helpers
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- Python 3.9 or newer
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Install the package from the repository root:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
python -m pip install .
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Public API
|
|
22
|
+
|
|
23
|
+
The package exports these helpers:
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import alogithms
|
|
27
|
+
|
|
28
|
+
alogithms.add(2, 3)
|
|
29
|
+
alogithms.subtract(7, 4)
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
import alogithms
|
|
36
|
+
|
|
37
|
+
print(alogithms.add(2, 3)) # 5
|
|
38
|
+
print(alogithms.subtract(7, 4)) # 3
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## File transfer CLI
|
|
42
|
+
|
|
43
|
+
Download a URL to a local path:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
python3 -m alogithms.devide --download https://example.com/file.bin --output file.bin
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Upload a local file to a URL:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
python3 -m alogithms.devide --upload https://example.com/upload --file file.bin
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Downloads refuse to overwrite an existing file unless `--overwrite` is given.
|
|
56
|
+
Uploads send the file as the raw request body using HTTP POST.
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
Run the unit tests:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
python -m unittest discover -s tests -v
|
|
63
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from importlib import import_module
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from .add import add
|
|
5
|
+
from .subtract import subtract
|
|
6
|
+
from .multi import multi, multi_args, MultiError
|
|
7
|
+
|
|
8
|
+
_EXPONENT_EXPORTS = {
|
|
9
|
+
"compute_exponents",
|
|
10
|
+
"ExponentTerm",
|
|
11
|
+
"read_power_series",
|
|
12
|
+
"sync_exponents",
|
|
13
|
+
"read_coeff_map",
|
|
14
|
+
"ExponentError",
|
|
15
|
+
}
|
|
16
|
+
_TRANSFER_EXPORTS = {"download", "upload", "DownloadError"}
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"add",
|
|
20
|
+
"subtract",
|
|
21
|
+
"multi",
|
|
22
|
+
"multi_args",
|
|
23
|
+
"MultiError",
|
|
24
|
+
"download",
|
|
25
|
+
"upload",
|
|
26
|
+
"DownloadError",
|
|
27
|
+
"compute_exponents",
|
|
28
|
+
"ExponentTerm",
|
|
29
|
+
"read_power_series",
|
|
30
|
+
"sync_exponents",
|
|
31
|
+
"read_coeff_map",
|
|
32
|
+
"ExponentError",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
def __getattr__(name: str) -> Any:
|
|
36
|
+
if name == "exponents":
|
|
37
|
+
return import_module(f".{name}", __name__)
|
|
38
|
+
if name in _TRANSFER_EXPORTS:
|
|
39
|
+
module = import_module(".devide", __name__)
|
|
40
|
+
value = getattr(module, name)
|
|
41
|
+
globals()[name] = value
|
|
42
|
+
return value
|
|
43
|
+
if name in _EXPONENT_EXPORTS:
|
|
44
|
+
module = import_module(".exponents", __name__)
|
|
45
|
+
value = getattr(module, name)
|
|
46
|
+
globals()[name] = value
|
|
47
|
+
return value
|
|
48
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import tempfile
|
|
3
|
+
import urllib.error
|
|
4
|
+
import urllib.request
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Callable, Optional
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class DevideError(Exception):
|
|
10
|
+
"""Raised when a file transfer fails."""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
DownloadError = DevideError
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def download(
|
|
17
|
+
url: str,
|
|
18
|
+
dest: str,
|
|
19
|
+
*,
|
|
20
|
+
timeout: float = 30.0,
|
|
21
|
+
overwrite: bool = False,
|
|
22
|
+
chunk_size: int = 64 * 1024,
|
|
23
|
+
progress: Optional[Callable[[int, Optional[int]], None]] = None,
|
|
24
|
+
headers: Optional[dict] = None,
|
|
25
|
+
) -> dict:
|
|
26
|
+
dest_path = Path(dest).expanduser()
|
|
27
|
+
|
|
28
|
+
if dest_path.exists() and not overwrite:
|
|
29
|
+
raise FileExistsError(f"Refusing to overwrite existing file: {dest_path}")
|
|
30
|
+
|
|
31
|
+
dest_path.parent.mkdir(parents=True, exist_ok=True)
|
|
32
|
+
req = urllib.request.Request(url, headers=headers or {})
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
36
|
+
content_length = resp.headers.get("Content-Length")
|
|
37
|
+
total = (
|
|
38
|
+
int(content_length)
|
|
39
|
+
if content_length and content_length.isdigit()
|
|
40
|
+
else None
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
fd, tmp_name = tempfile.mkstemp(
|
|
44
|
+
prefix=dest_path.name + ".", suffix=".part", dir=dest_path.parent
|
|
45
|
+
)
|
|
46
|
+
downloaded = 0
|
|
47
|
+
try:
|
|
48
|
+
with os.fdopen(fd, "wb") as file:
|
|
49
|
+
while True:
|
|
50
|
+
chunk = resp.read(chunk_size)
|
|
51
|
+
if not chunk:
|
|
52
|
+
break
|
|
53
|
+
file.write(chunk)
|
|
54
|
+
downloaded += len(chunk)
|
|
55
|
+
if progress:
|
|
56
|
+
progress(downloaded, total)
|
|
57
|
+
|
|
58
|
+
os.replace(tmp_name, dest_path)
|
|
59
|
+
except BaseException:
|
|
60
|
+
try:
|
|
61
|
+
os.unlink(tmp_name)
|
|
62
|
+
except OSError:
|
|
63
|
+
pass
|
|
64
|
+
raise
|
|
65
|
+
|
|
66
|
+
except urllib.error.HTTPError as exc:
|
|
67
|
+
raise DevideError(f"HTTP {exc.code} for {url}: {exc.reason}") from exc
|
|
68
|
+
except urllib.error.URLError as exc:
|
|
69
|
+
raise DevideError(f"Failed to reach {url}: {exc.reason}") from exc
|
|
70
|
+
except TimeoutError as exc:
|
|
71
|
+
raise DevideError(f"Timed out downloading {url}") from exc
|
|
72
|
+
|
|
73
|
+
return {"path": str(dest_path), "size": downloaded, "url": url}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def upload(
|
|
77
|
+
url: str,
|
|
78
|
+
source: str,
|
|
79
|
+
*,
|
|
80
|
+
timeout: float = 30.0,
|
|
81
|
+
method: str = "POST",
|
|
82
|
+
content_type: str = "application/octet-stream",
|
|
83
|
+
headers: Optional[dict] = None,
|
|
84
|
+
) -> dict:
|
|
85
|
+
"""Send a local file as the HTTP request body and return transfer metadata."""
|
|
86
|
+
if not url.startswith(("http://", "https://")):
|
|
87
|
+
raise ValueError("Only http(s) URLs are supported for uploads")
|
|
88
|
+
|
|
89
|
+
source_path = Path(source).expanduser()
|
|
90
|
+
size = source_path.stat().st_size
|
|
91
|
+
request_headers = {
|
|
92
|
+
"Content-Type": content_type,
|
|
93
|
+
"Content-Length": str(size),
|
|
94
|
+
}
|
|
95
|
+
if headers:
|
|
96
|
+
request_headers.update(headers)
|
|
97
|
+
|
|
98
|
+
try:
|
|
99
|
+
with source_path.open("rb") as source_file:
|
|
100
|
+
req = urllib.request.Request(
|
|
101
|
+
url,
|
|
102
|
+
data=source_file,
|
|
103
|
+
headers=request_headers,
|
|
104
|
+
method=method,
|
|
105
|
+
)
|
|
106
|
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
107
|
+
status = getattr(resp, "status", 200)
|
|
108
|
+
if not 200 <= status < 300:
|
|
109
|
+
raise DevideError(f"HTTP {status} when uploading to {url}")
|
|
110
|
+
except urllib.error.HTTPError as exc:
|
|
111
|
+
raise DevideError(
|
|
112
|
+
f"HTTP {exc.code} when uploading to {url}: {exc.reason}"
|
|
113
|
+
) from exc
|
|
114
|
+
except urllib.error.URLError as exc:
|
|
115
|
+
raise DevideError(f"Failed to reach {url}: {exc.reason}") from exc
|
|
116
|
+
except TimeoutError as exc:
|
|
117
|
+
raise DevideError(f"Timed out uploading to {url}") from exc
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
"path": str(source_path),
|
|
121
|
+
"size": size,
|
|
122
|
+
"url": url,
|
|
123
|
+
"status": status,
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def main(argv: Optional[list] = None) -> None:
|
|
128
|
+
import argparse
|
|
129
|
+
|
|
130
|
+
parser = argparse.ArgumentParser(description="Download or upload a file over HTTP")
|
|
131
|
+
transfer = parser.add_mutually_exclusive_group(required=True)
|
|
132
|
+
transfer.add_argument("--download", metavar="URL")
|
|
133
|
+
transfer.add_argument("--upload", metavar="URL")
|
|
134
|
+
parser.add_argument("--output", metavar="PATH", help="destination path for downloads")
|
|
135
|
+
parser.add_argument("--file", metavar="PATH", help="local file to upload")
|
|
136
|
+
parser.add_argument(
|
|
137
|
+
"--overwrite", action="store_true", help="replace an existing download"
|
|
138
|
+
)
|
|
139
|
+
parser.add_argument("--timeout", type=float, default=30.0)
|
|
140
|
+
args = parser.parse_args(argv)
|
|
141
|
+
|
|
142
|
+
try:
|
|
143
|
+
if args.download:
|
|
144
|
+
if args.file:
|
|
145
|
+
parser.error("--file can only be used with --upload")
|
|
146
|
+
if not args.output:
|
|
147
|
+
parser.error("--output is required with --download")
|
|
148
|
+
result = download(
|
|
149
|
+
args.download,
|
|
150
|
+
args.output,
|
|
151
|
+
timeout=args.timeout,
|
|
152
|
+
overwrite=args.overwrite,
|
|
153
|
+
)
|
|
154
|
+
else:
|
|
155
|
+
if args.output:
|
|
156
|
+
parser.error("--output can only be used with --download")
|
|
157
|
+
if args.overwrite:
|
|
158
|
+
parser.error("--overwrite can only be used with --download")
|
|
159
|
+
if not args.file:
|
|
160
|
+
parser.error("--file is required with --upload")
|
|
161
|
+
result = upload(args.upload, args.file, timeout=args.timeout)
|
|
162
|
+
except (DevideError, OSError, ValueError) as exc:
|
|
163
|
+
parser.error(str(exc))
|
|
164
|
+
|
|
165
|
+
print(result)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
devide = download
|
|
169
|
+
|
|
170
|
+
if __name__ == "__main__":
|
|
171
|
+
main()
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
__all__ = ["download", "upload", "devide", "DownloadError", "DevideError", "main"]
|