utkit 0.14.0__tar.gz → 0.15.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.
- {utkit-0.14.0 → utkit-0.15.0}/PKG-INFO +3 -1
- {utkit-0.14.0 → utkit-0.15.0}/pyproject.toml +3 -1
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/index.md +2 -2
- utkit-0.15.0/src/utkit/documentation/docs/utils/file.md +134 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/zensical.toml +1 -0
- utkit-0.15.0/src/utkit/utils/file.py +60 -0
- utkit-0.14.0/src/utkit/documentation/.github/workflows/docs.yml +0 -29
- {utkit-0.14.0 → utkit-0.15.0}/README.md +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/__init__.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/api/rate_limit/__init__.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/api/rate_limit/error.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/api/rate_limit/middleware.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/api/schema/query.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/auth/__init__.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/cli/__init__.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/communication/__init__.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/communication/mail/__init__.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/communication/mail/smtp.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/core/logging.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/.gitignore +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/10042715452264249772 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/10986014347042203044 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/11038628458439117958 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/11306067049371264785 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/13386297405578974681 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/14061902412565698710 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/14675097771134305488 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/15066256594918372991 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/15312684519617069940 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/15661711846603463071 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/15724107283881488306 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/16166828772222643061 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/17695336329032716848 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/17985671397626253671 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/2940665334038842907 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/3226154870166803660 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/326316130724058699 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/3476900567878811119 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/3541202890535126406 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/360188204203718330 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/403326901327389294 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/4969546423033644587 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/5530722400779903482 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/5696925338617156769 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/5859600648538783245 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/5974781288462474643 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/5976522500417319979 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/6210600303880993421 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/6916343365748484443 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/9033698058957892258 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/9102534330981319844 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.cache/9811225078116513287 +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/.gitignore +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/api/rate-limit.md +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/api/schema.md +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/auth.md +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/communication/mail.md +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/core/logging.md +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/images/logo-old.png +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/images/logo.png +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/privacy/mask.md +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/privacy/security.md +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/store/mongo.md +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/store/r2.md +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/store/redis.md +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/store/s3.md +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/stylesheets/extra.css +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/template/render.md +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/utils/performance.md +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/docs/validators/data.md +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/404.html +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/api/rate-limit/index.html +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/api/schema/index.html +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/assets/images/favicon.png +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/assets/javascripts/LICENSE +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/assets/javascripts/bundle.dbc0afdc.min.js +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/assets/javascripts/workers/search.e2d2d235.min.js +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/assets/stylesheets/classic/main.a2001754.min.css +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/assets/stylesheets/classic/palette.7dc9a0ad.min.css +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/assets/stylesheets/modern/main.1e981d71.min.css +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/assets/stylesheets/modern/palette.dfe2e883.min.css +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/auth/index.html +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/communication/mail/index.html +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/core/logging/index.html +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/images/logo-old.png +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/images/logo.png +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/index.html +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/objects.inv +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/privacy/mask/index.html +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/privacy/security/index.html +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/search.json +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/sitemap.xml +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/store/mongo/index.html +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/store/r2/index.html +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/store/redis/index.html +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/store/s3/index.html +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/stylesheets/extra.css +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/template/render/index.html +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/utils/performance/index.html +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/validators/data/index.html +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/privacy/__init__.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/privacy/mask.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/privacy/security.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/store/aws/__init__.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/store/aws/s3.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/store/cloudflare/r2.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/store/mongo/__init__.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/store/redis/__init__.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/template/__init__.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/template/render.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/utils/performance.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/validators/__init__.py +0 -0
- {utkit-0.14.0 → utkit-0.15.0}/src/utkit/validators/data.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: utkit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.15.0
|
|
4
4
|
Summary: core libraries for development
|
|
5
5
|
Author: TINS PJ
|
|
6
6
|
Author-email: TINS PJ <tinspj1997@gmail.com>
|
|
@@ -14,6 +14,7 @@ Requires-Dist: slowapi>=0.1.9 ; extra == 'all'
|
|
|
14
14
|
Requires-Dist: pydantic>=2.13.3 ; extra == 'all'
|
|
15
15
|
Requires-Dist: psutil>=7.2.2 ; extra == 'all'
|
|
16
16
|
Requires-Dist: jinja2>=3.1.6 ; extra == 'all'
|
|
17
|
+
Requires-Dist: python-magic>=0.4.27 ; extra == 'all'
|
|
17
18
|
Requires-Dist: redis>=7.4.0 ; extra == 'all'
|
|
18
19
|
Requires-Dist: boto3>=1.43.2 ; extra == 'all'
|
|
19
20
|
Requires-Dist: certifi>=2026.4.22 ; extra == 'all'
|
|
@@ -22,6 +23,7 @@ Requires-Dist: slowapi>=0.1.9 ; extra == 'api'
|
|
|
22
23
|
Requires-Dist: pydantic>=2.13.3 ; extra == 'api'
|
|
23
24
|
Requires-Dist: psutil>=7.2.2 ; extra == 'standard'
|
|
24
25
|
Requires-Dist: jinja2>=3.1.6 ; extra == 'standard'
|
|
26
|
+
Requires-Dist: python-magic>=0.4.27 ; extra == 'standard'
|
|
25
27
|
Requires-Dist: redis>=7.4.0 ; extra == 'store'
|
|
26
28
|
Requires-Dist: boto3>=1.43.2 ; extra == 'store'
|
|
27
29
|
Requires-Dist: certifi>=2026.4.22 ; extra == 'store'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "utkit"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.15.0"
|
|
4
4
|
description = "core libraries for development"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [
|
|
@@ -24,6 +24,7 @@ api=[
|
|
|
24
24
|
standard=[
|
|
25
25
|
"psutil>=7.2.2",
|
|
26
26
|
"jinja2>=3.1.6",
|
|
27
|
+
"python-magic>=0.4.27",
|
|
27
28
|
]
|
|
28
29
|
store=[
|
|
29
30
|
"redis>=7.4.0",
|
|
@@ -36,6 +37,7 @@ all=[
|
|
|
36
37
|
"pydantic>=2.13.3",
|
|
37
38
|
"psutil>=7.2.2",
|
|
38
39
|
"jinja2>=3.1.6",
|
|
40
|
+
"python-magic>=0.4.27",
|
|
39
41
|
"redis>=7.4.0",
|
|
40
42
|
"boto3>=1.43.2",
|
|
41
43
|
"certifi>=2026.4.22",
|
|
@@ -95,6 +95,7 @@ utkit --version
|
|
|
95
95
|
| `api` | pydantic | `>=2.13.3` |
|
|
96
96
|
| `standard` | psutil | `>=7.2.2` |
|
|
97
97
|
| `standard` | jinja2 | `>=3.1.6` |
|
|
98
|
+
| `standard` | python-magic | `>=0.4.27` |
|
|
98
99
|
| `store` | redis | `>=7.4.0` |
|
|
99
100
|
| `all` | all of the above | — |
|
|
100
101
|
|
|
@@ -132,8 +133,7 @@ utkit docs
|
|
|
132
133
|
|---|---|---|
|
|
133
134
|
| [`api.rate_limit`](api/rate-limit.md) | `api` | Rate limiting for FastAPI via SlowAPI |
|
|
134
135
|
| [`api.schema`](api/schema.md) | `api` | Reusable Pydantic query models (pagination) |
|
|
135
|
-
| [`utils.performance`](utils/performance.md) | `standard` | Execution time decorator and memory usage |
|
|
136
|
-
| [`template.render`](template/render.md) | `standard` | HTML rendering from Jinja2 files and strings |
|
|
136
|
+
| [`utils.performance`](utils/performance.md) | `standard` | Execution time decorator and memory usage || [`utils.file`](utils/file.md) | `standard` | File checksum and content-based type detection || [`template.render`](template/render.md) | `standard` | HTML rendering from Jinja2 files and strings |
|
|
137
137
|
| [`store.redis`](store/redis.md) | `store` | Singleton Redis client with JSON serialisation |
|
|
138
138
|
|
|
139
139
|
---
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
---
|
|
2
|
+
icon: lucide/file
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# File utilities
|
|
6
|
+
|
|
7
|
+
The `utkit.utils.file` module provides lightweight helpers for working with files: computing content checksums and identifying file types from their binary content (magic numbers).
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
`python-magic` is part of the optional `standard` extras. Install `utkit` with the `standard` extra for file-type detection support:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install "utkit[standard]"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or with [uv](https://docs.astral.sh/uv/):
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
uv add "utkit[standard]"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
> `python-magic` is only required for `get_file_type`. The `get_file_checksum` function relies solely on the standard library (`hashlib`) and has no external dependencies.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Quick start
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from utkit.utils.file import get_file_checksum, get_file_type
|
|
33
|
+
|
|
34
|
+
# Compute a SHA-256 checksum of a file
|
|
35
|
+
checksum = get_file_checksum("report.pdf")
|
|
36
|
+
print(checksum) # "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
|
|
37
|
+
|
|
38
|
+
# Identify a file's type from its content
|
|
39
|
+
file_type = get_file_type("report.pdf")
|
|
40
|
+
print(file_type) # "pdf"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## `get_file_checksum`
|
|
46
|
+
|
|
47
|
+
Calculate a file checksum by reading the file in chunks. Reading in chunks keeps memory usage low even for very large files.
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
def get_file_checksum(file_path: str, algorithm: str = "sha256", chunk_size: int = 8192) -> str
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| Parameter | Type | Default | Description |
|
|
54
|
+
|---|---|---|---|
|
|
55
|
+
| `file_path` | `str` | — | Path to the file to checksum. |
|
|
56
|
+
| `algorithm` | `str` | `"sha256"` | Hash algorithm supported by `hashlib` (e.g. `"md5"`, `"sha1"`, `"sha256"`, `"sha512"`). |
|
|
57
|
+
| `chunk_size` | `int` | `8192` | Number of bytes to read at a time. |
|
|
58
|
+
|
|
59
|
+
**Returns:** `str` — Hex digest of the file checksum.
|
|
60
|
+
|
|
61
|
+
### Default algorithm (SHA-256)
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from utkit.utils.file import get_file_checksum
|
|
65
|
+
|
|
66
|
+
checksum = get_file_checksum("data.csv")
|
|
67
|
+
print(checksum) # "a1b2c3...64-hex-characters"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Custom algorithm
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from utkit.utils.file import get_file_checksum
|
|
74
|
+
|
|
75
|
+
# Use SHA-1 instead of the default SHA-256
|
|
76
|
+
checksum = get_file_checksum("data.csv", algorithm="sha1")
|
|
77
|
+
print(checksum) # "da39a3ee5e6b4b0d3255bfef95601890afd80709"
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Verifying file integrity
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from utkit.utils.file import get_file_checksum
|
|
84
|
+
|
|
85
|
+
expected = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
|
|
86
|
+
|
|
87
|
+
if get_file_checksum("report.pdf") == expected:
|
|
88
|
+
print("File is intact")
|
|
89
|
+
else:
|
|
90
|
+
print("File has been modified or corrupted")
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## `get_file_type`
|
|
96
|
+
|
|
97
|
+
Identify a file's type based on its content using magic numbers, rather than its extension. This is more reliable than trusting a file suffix.
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
def get_file_type(file_path: str) -> str
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
| Parameter | Type | Description |
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| `file_path` | `str` | Path to the file to identify. |
|
|
106
|
+
|
|
107
|
+
**Returns:** `str` — File type identifier. One of: `"pdf"`, `"docx"`, `"csv"`, `"xlsx"`, `"xls"`, `"png"`, `"jpeg"`, `"jpg"`. Returns `"unknown"` for any unrecognised type.
|
|
108
|
+
|
|
109
|
+
### Identifying a document
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from utkit.utils.file import get_file_type
|
|
113
|
+
|
|
114
|
+
file_type = get_file_type("document.docx")
|
|
115
|
+
print(file_type) # "docx"
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Identifying an image
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from utkit.utils.file import get_file_type
|
|
122
|
+
|
|
123
|
+
file_type = get_file_type("photo.jpg")
|
|
124
|
+
print(file_type) # "jpg"
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Handling unknown types
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from utkit.utils.file import get_file_type
|
|
131
|
+
|
|
132
|
+
file_type = get_file_type("notes.txt")
|
|
133
|
+
print(file_type) # "unknown" (plain text is not in the recognised set)
|
|
134
|
+
```
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from collections import defaultdict
|
|
2
|
+
import hashlib
|
|
3
|
+
import magic
|
|
4
|
+
|
|
5
|
+
def get_file_checksum(file_path, algorithm="sha256", chunk_size=8192):
|
|
6
|
+
"""
|
|
7
|
+
Calculate a file checksum by reading the file in chunks.
|
|
8
|
+
|
|
9
|
+
Args:
|
|
10
|
+
file_path: Path to the file to checksum
|
|
11
|
+
algorithm: Hash algorithm supported by hashlib (default: "sha256")
|
|
12
|
+
chunk_size: Number of bytes to read at a time
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
str: Hex digest of the file checksum
|
|
16
|
+
"""
|
|
17
|
+
hasher = hashlib.new(algorithm)
|
|
18
|
+
|
|
19
|
+
with open(file_path, "rb") as f:
|
|
20
|
+
for chunk in iter(lambda: f.read(chunk_size), b""):
|
|
21
|
+
hasher.update(chunk)
|
|
22
|
+
|
|
23
|
+
return hasher.hexdigest()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def get_file_type(file_path):
|
|
27
|
+
"""
|
|
28
|
+
Identify file type based on content using magic numbers.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
file_path: Path to the file to identify
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
str: File type identifier ("pdf", "docx", "csv", "xlsx", "xls", "png", "jpeg", "jpg", "unknown")
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
# Read file content
|
|
38
|
+
with open(file_path, "rb") as f:
|
|
39
|
+
data = f.read()
|
|
40
|
+
|
|
41
|
+
# Use python-magic to identify file type from content
|
|
42
|
+
mime = magic.Magic(mime=True)
|
|
43
|
+
mime_type = mime.from_buffer(data)
|
|
44
|
+
|
|
45
|
+
# Map MIME types to file type identifiers
|
|
46
|
+
mime_to_type = defaultdict(
|
|
47
|
+
lambda: "unknown",
|
|
48
|
+
{
|
|
49
|
+
"application/pdf": "pdf",
|
|
50
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
|
|
51
|
+
"text/csv": "csv",
|
|
52
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
|
|
53
|
+
"application/vnd.ms-excel": "xls",
|
|
54
|
+
"image/png": "png",
|
|
55
|
+
"image/jpeg": "jpeg",
|
|
56
|
+
"image/jpg": "jpg",
|
|
57
|
+
},
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
return mime_to_type[mime_type]
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
name: Documentation
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
branches:
|
|
5
|
-
- master
|
|
6
|
-
- main
|
|
7
|
-
permissions:
|
|
8
|
-
contents: read
|
|
9
|
-
pages: write
|
|
10
|
-
id-token: write
|
|
11
|
-
jobs:
|
|
12
|
-
deploy:
|
|
13
|
-
environment:
|
|
14
|
-
name: github-pages
|
|
15
|
-
url: ${{ steps.deployment.outputs.page_url }}
|
|
16
|
-
runs-on: ubuntu-latest
|
|
17
|
-
steps:
|
|
18
|
-
- uses: actions/configure-pages@v6
|
|
19
|
-
- uses: actions/checkout@v6
|
|
20
|
-
- uses: actions/setup-python@v6
|
|
21
|
-
with:
|
|
22
|
-
python-version: 3.x
|
|
23
|
-
- run: pip install zensical
|
|
24
|
-
- run: zensical build --clean
|
|
25
|
-
- uses: actions/upload-pages-artifact@v5
|
|
26
|
-
with:
|
|
27
|
-
path: site
|
|
28
|
-
- uses: actions/deploy-pages@v5
|
|
29
|
-
id: deployment
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{utkit-0.14.0 → utkit-0.15.0}/src/utkit/documentation/site/assets/javascripts/bundle.dbc0afdc.min.js
RENAMED
|
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
|
|
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
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|