arpakitlib 3.0.4__tar.gz → 3.0.10__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.
Files changed (63) hide show
  1. {arpakitlib-3.0.4 → arpakitlib-3.0.10}/LICENSE +1 -1
  2. {arpakitlib-3.0.4 → arpakitlib-3.0.10}/PKG-INFO +65 -31
  3. arpakitlib-3.0.10/README.md +147 -0
  4. arpakitlib-3.0.4/arpakitlib/aiogram_/aiogram_as_tg_command_util.py → arpakitlib-3.0.10/arpakitlib/aiogram_util/aiogram_as_tg_command.py +2 -24
  5. arpakitlib-3.0.4/arpakitlib/common_/base64_util.py → arpakitlib-3.0.10/arpakitlib/common_util/base64_etc.py +18 -68
  6. arpakitlib-3.0.4/arpakitlib/common_/base_worker_util.py → arpakitlib-3.0.10/arpakitlib/common_util/base_worker.py +5 -75
  7. arpakitlib-3.0.4/arpakitlib/common_/blank_util.py → arpakitlib-3.0.10/arpakitlib/common_util/blank.py +1 -1
  8. arpakitlib-3.0.4/arpakitlib/common_/cache_file_util.py → arpakitlib-3.0.10/arpakitlib/common_util/cache_file.py +4 -34
  9. arpakitlib-3.0.4/arpakitlib/common_/clone_pydantic_model_fields_util.py → arpakitlib-3.0.10/arpakitlib/common_util/clone_pydantic_model_fields.py +1 -52
  10. arpakitlib-3.0.4/arpakitlib/common_/datetime_etc_util.py → arpakitlib-3.0.10/arpakitlib/common_util/datetime_etc.py +1 -14
  11. arpakitlib-3.0.4/arpakitlib/common_/dict_as_object_util.py → arpakitlib-3.0.10/arpakitlib/common_util/dict_as_object.py +3 -38
  12. arpakitlib-3.0.4/arpakitlib/common_/dict_util.py → arpakitlib-3.0.10/arpakitlib/common_util/dict_etc.py +1 -5
  13. arpakitlib-3.0.4/arpakitlib/common_/logging_util.py → arpakitlib-3.0.10/arpakitlib/common_util/easy_logging.py +1 -13
  14. arpakitlib-3.0.4/arpakitlib/common_/file_storage_in_dir_util.py → arpakitlib-3.0.10/arpakitlib/common_util/file_storage_in_dir.py +2 -2
  15. arpakitlib-3.0.4/arpakitlib/common_/func_etc_util.py → arpakitlib-3.0.10/arpakitlib/common_util/func_etc.py +1 -56
  16. arpakitlib-3.0.10/arpakitlib/common_util/generate_difficult_password.py +52 -0
  17. arpakitlib-3.0.10/arpakitlib/common_util/generate_simple_code.py +34 -0
  18. arpakitlib-3.0.4/arpakitlib/common_/json_db_util.py → arpakitlib-3.0.10/arpakitlib/common_util/json_db.py +5 -23
  19. arpakitlib-3.0.10/arpakitlib/common_util/json_etc.py +92 -0
  20. arpakitlib-3.0.4/arpakitlib/common_/log_async_func_if_error_util.py → arpakitlib-3.0.10/arpakitlib/common_util/log_async_func_if_error.py +1 -1
  21. arpakitlib-3.0.4/arpakitlib/common_/not_set_util.py → arpakitlib-3.0.10/arpakitlib/common_util/not_set.py +7 -0
  22. arpakitlib-3.0.4/arpakitlib/common_/parse_command_util.py → arpakitlib-3.0.10/arpakitlib/common_util/parse_command.py +2 -28
  23. arpakitlib-3.0.4/arpakitlib/common_/postgresql_db_dump_util.py → arpakitlib-3.0.10/arpakitlib/common_util/postgresql_db_dump.py +1 -33
  24. arpakitlib-3.0.4/arpakitlib/common_/rat_func_util.py → arpakitlib-3.0.10/arpakitlib/common_util/rat_func.py +1 -1
  25. arpakitlib-3.0.4/arpakitlib/common_/really_validate_email_util.py → arpakitlib-3.0.10/arpakitlib/common_util/really_validate_email.py +1 -21
  26. arpakitlib-3.0.4/arpakitlib/common_/retry_func_util.py → arpakitlib-3.0.10/arpakitlib/common_util/retry_func.py +3 -58
  27. arpakitlib-3.0.4/arpakitlib/common_/str_etc_util.py → arpakitlib-3.0.10/arpakitlib/common_util/str_etc.py +2 -0
  28. arpakitlib-3.0.10/arpakitlib/http_client_util/__init__.py +0 -0
  29. arpakitlib-3.0.10/arpakitlib/http_client_util/base_http_client.py +54 -0
  30. arpakitlib-3.0.10/arpakitlib/http_client_util/http_request.py +304 -0
  31. arpakitlib-3.0.4/arpakitlib/sqlalchemy_/pydantic_schema_from_sqlalchemy_model_util.py → arpakitlib-3.0.10/arpakitlib/sqlalchemy_util/pydantic_schema_from_sqlalchemy_model.py +2 -85
  32. arpakitlib-3.0.4/arpakitlib/sqlalchemy_/sqlalchemy_base_dbm_util.py → arpakitlib-3.0.10/arpakitlib/sqlalchemy_util/sqlalchemy_base_dbm.py +1 -64
  33. arpakitlib-3.0.10/arpakitlib/sqlalchemy_util/sqlalchemy_db.py +555 -0
  34. arpakitlib-3.0.4/arpakitlib/sqlalchemy_/sqlalchemy_declarative_base_info_util.py → arpakitlib-3.0.10/arpakitlib/sqlalchemy_util/sqlalchemy_declarative_base_info.py +4 -29
  35. arpakitlib-3.0.10/arpakitlib/zip_util/__init__.py +0 -0
  36. arpakitlib-3.0.10/arpakitlib/zip_util/make_zip_archive.py +168 -0
  37. {arpakitlib-3.0.4 → arpakitlib-3.0.10}/pyproject.toml +26 -19
  38. arpakitlib-3.0.4/README.md +0 -113
  39. arpakitlib-3.0.4/arpakitlib/common_/base_http_api_client_util.py +0 -66
  40. arpakitlib-3.0.4/arpakitlib/common_/generate_connection_url_util.py +0 -108
  41. arpakitlib-3.0.4/arpakitlib/common_/generate_difficult_password_util.py +0 -83
  42. arpakitlib-3.0.4/arpakitlib/common_/generate_simple_code_util.py +0 -57
  43. arpakitlib-3.0.4/arpakitlib/common_/http_request_util.py +0 -280
  44. arpakitlib-3.0.4/arpakitlib/common_/json_util.py +0 -142
  45. arpakitlib-3.0.4/arpakitlib/common_/make_zip_with_passwd_util.py +0 -154
  46. arpakitlib-3.0.4/arpakitlib/sqladmin_/sqladmin_model_view_info.py +0 -94
  47. arpakitlib-3.0.4/arpakitlib/sqlalchemy_/__init__.py +0 -1
  48. arpakitlib-3.0.4/arpakitlib/sqlalchemy_/sqlalchemy_db_util.py +0 -244
  49. arpakitlib-3.0.4/arpakitlib/sqlalchemy_/sqlalchemy_drop_check_constraints_util.py +0 -101
  50. arpakitlib-3.0.4/arpakitlib/sqlalchemy_/sqlalchemy_ensure_check_constraints_util.py +0 -138
  51. {arpakitlib-3.0.4 → arpakitlib-3.0.10}/arpakitlib/__init__.py +0 -0
  52. {arpakitlib-3.0.4/arpakitlib/aiogram_ → arpakitlib-3.0.10/arpakitlib/aiogram_util}/__init__.py +0 -0
  53. {arpakitlib-3.0.4/arpakitlib/common_ → arpakitlib-3.0.10/arpakitlib/common_util}/__init__.py +0 -0
  54. /arpakitlib-3.0.4/arpakitlib/common_/enumeration_util.py → /arpakitlib-3.0.10/arpakitlib/common_util/enumeration.py +0 -0
  55. /arpakitlib-3.0.4/arpakitlib/common_/exception_etc_util.py → /arpakitlib-3.0.10/arpakitlib/common_util/exception_etc.py +0 -0
  56. /arpakitlib-3.0.4/arpakitlib/common_/ip_util.py → /arpakitlib-3.0.10/arpakitlib/common_util/ip_etc.py +0 -0
  57. /arpakitlib-3.0.4/arpakitlib/common_/run_cmd_util.py → /arpakitlib-3.0.10/arpakitlib/common_util/run_cmd.py +0 -0
  58. /arpakitlib-3.0.4/arpakitlib/common_/safe_sleep_util.py → /arpakitlib-3.0.10/arpakitlib/common_util/safe_sleep.py +0 -0
  59. /arpakitlib-3.0.4/arpakitlib/common_/simple_settings_util.py → /arpakitlib-3.0.10/arpakitlib/common_util/simple_settings.py +0 -0
  60. /arpakitlib-3.0.4/arpakitlib/common_/type_etc_util.py → /arpakitlib-3.0.10/arpakitlib/common_util/type_etc.py +0 -0
  61. /arpakitlib-3.0.4/arpakitlib/common_/typed_objects_from_dir_util.py → /arpakitlib-3.0.10/arpakitlib/common_util/typed_objects_from_dir.py +0 -0
  62. /arpakitlib-3.0.4/arpakitlib/common_/uuid_etc_util.py → /arpakitlib-3.0.10/arpakitlib/common_util/uuid_etc.py +0 -0
  63. {arpakitlib-3.0.4/arpakitlib/sqladmin_ → arpakitlib-3.0.10/arpakitlib/sqlalchemy_util}/__init__.py +0 -0
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2024-present ARPAKIT-Company
189
+ Copyright 2024-present arpakit
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: arpakitlib
3
- Version: 3.0.4
4
- Summary: Lightweight and convenient development tools by ARPAKIT Company
3
+ Version: 3.0.10
4
+ Summary: Lightweight and convenient development tools by arpakit
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE
7
7
  Keywords: arpakitlib,arpakit,arpakit-company,arpakitcompany,arpakit_company
8
- Author: arpakit_company
9
- Author-email: support@arpakit.com
10
- Requires-Python: >=3.13.4,<3.15
8
+ Author: arpakit
9
+ Author-email: arpakit@gmail.com
10
+ Requires-Python: >=3.13.4,<4
11
11
  Classifier: Development Status :: 5 - Production/Stable
12
12
  Classifier: Intended Audience :: Developers
13
13
  Classifier: Programming Language :: Python
@@ -18,20 +18,20 @@ Classifier: Operating System :: OS Independent
18
18
  Classifier: Topic :: Software Development :: Libraries
19
19
  Classifier: Topic :: Utilities
20
20
  Classifier: Framework :: AsyncIO
21
- Requires-Dist: aiogram (>=3.31.0,<4.0.0)
22
- Requires-Dist: aiohttp (>=3.14.3,<4.0.0)
23
- Requires-Dist: aiohttp-socks (>=0.12.0,<0.13.0)
24
- Requires-Dist: asyncpg (>=0.31.0,<0.32.0)
21
+ Provides-Extra: aiogram-util
22
+ Provides-Extra: http-client-util
23
+ Provides-Extra: sqlalchemy-util
24
+ Provides-Extra: zip-util
25
+ Requires-Dist: aiogram (>=3.31.0,<4.0.0) ; (python_version < "3.15") and (extra == "aiogram-util")
26
+ Requires-Dist: asyncpg (>=0.31.0,<0.32.0) ; extra == "sqlalchemy-util"
25
27
  Requires-Dist: email-validator (>=2.2.0,<3.0.0)
26
- Requires-Dist: fastapi (>=0.141.1,<0.142.0)
28
+ Requires-Dist: httpx[http2,socks] (>=0.28.1,<0.29.0) ; extra == "http-client-util"
27
29
  Requires-Dist: orjson (>=3.12.0,<4.0.0)
28
- Requires-Dist: psycopg2-binary (>=2.9.12,<3.0.0)
30
+ Requires-Dist: psycopg2-binary (>=2.9.13,<3.0.0) ; extra == "sqlalchemy-util"
29
31
  Requires-Dist: pydantic (>=2.13.5,<3.0.0)
30
32
  Requires-Dist: pydantic-settings (>=2.7.1,<3.0.0)
31
- Requires-Dist: pyminizip (>=0.2.6,<0.3.0)
32
- Requires-Dist: requests (>=2.34.2,<3.0.0)
33
- Requires-Dist: sqladmin (>=0.31.1,<0.32.0)
34
- Requires-Dist: sqlalchemy (>=2.0.52,<3.0.0)
33
+ Requires-Dist: pyzipper (>=0.4.0,<0.5.0) ; extra == "zip-util"
34
+ Requires-Dist: sqlalchemy (>=2.0.53,<3.0.0) ; extra == "sqlalchemy-util"
35
35
  Project-URL: ARPAKIT Company, https://arpakit.com
36
36
  Project-URL: Documentation, https://github.com/ARPAKIT-Company/arpakitlib
37
37
  Project-URL: Homepage, https://github.com/ARPAKIT-Company/arpakitlib
@@ -45,7 +45,7 @@ Description-Content-Type: text/markdown
45
45
 
46
46
  ## 🚀 Simplify Your Development Workflow
47
47
 
48
- A collection of lightweight and convenient development tools by ARPAKIT Company, designed to simplify and accelerate
48
+ A collection of lightweight and convenient development tools by arpakit, designed to simplify and accelerate
49
49
  your workflow.
50
50
 
51
51
  [![PyPI](https://img.shields.io/pypi/v/arpakitlib.svg)](https://pypi.org/project/arpakitlib/)
@@ -56,20 +56,31 @@ your workflow.
56
56
 
57
57
  ### What is inside
58
58
 
59
- A set of small, self-contained utilities you pick from one at a time:
59
+ A set of small, self-contained utilities you pick from one at a time.
60
60
 
61
- - **Everyday helpers** — JSON, dates, strings, dictionaries, files, settings, background workers, retries, enumerations
62
- - **Databases** — declarative base with introspection, database helper, check constraints, schemas from existing models
63
- - **HTTP** — sync and async requests with retries and proxy support, plus a base API client
64
- - **Telegram bots** — parsing commands
65
- - **Admin panels** — introspection for admin model views
66
- - **Operations** — password protected archives, database dumps, shell commands, email validation
61
+ The base install stays light and pulls only a handful of packages. Everything that needs a heavier library lives in
62
+ its own subpackage behind an optional extra, so you install a web framework or a bot framework only if you actually
63
+ use that part.
64
+
65
+ | Subpackage | Extra | What is inside |
66
+ |---|---|---|
67
+ | `common_util` | always installed | JSON, dates, strings, dictionaries, files, settings, background workers, retries, enumerations, shell commands, database dumps, email validation |
68
+ | `http_client_util` | `http-client-util` | sync and async requests with retries and proxy support, plus a base API client |
69
+ | `sqlalchemy_util` | `sqlalchemy-util` | declarative base with introspection, database helper, check constraints, pydantic schemas from existing models |
70
+ | `sqladmin_util` | `sqladmin-util` | introspection for admin model views |
71
+ | `aiogram_util` | `aiogram-util` | parsing telegram bot commands |
67
72
 
68
73
  Every module keeps its own runnable example, so the fastest way to see what a utility does is to run that
69
74
  module directly:
70
75
 
71
76
  ```bash
72
- python -m arpakitlib.<package>.<module>
77
+ python -m arpakitlib.<subpackage>.<module>
78
+ ```
79
+
80
+ For example:
81
+
82
+ ```bash
83
+ python -m arpakitlib.common_util.json
73
84
  ```
74
85
 
75
86
  ---
@@ -82,6 +93,8 @@ python -m arpakitlib.<package>.<module>
82
93
 
83
94
  ### Installation
84
95
 
96
+ The base install gives you everything in `common_util`:
97
+
85
98
  ```bash
86
99
  pip install arpakitlib
87
100
  ```
@@ -94,10 +107,24 @@ poetry add arpakitlib
94
107
  uv add arpakitlib
95
108
  ```
96
109
 
110
+ Add the extras you need, separately or several at once:
111
+
112
+ ```bash
113
+ pip install "arpakitlib[sqlalchemy-util]"
114
+ ```
115
+
116
+ ```bash
117
+ pip install "arpakitlib[aiogram-util,http-client-util]"
118
+ ```
119
+
120
+ ```bash
121
+ poetry add "arpakitlib[sqlalchemy-util,sqladmin-util]"
122
+ ```
123
+
97
124
  Pin an exact version:
98
125
 
99
126
  ```bash
100
- pip install arpakitlib==2.0.0
127
+ pip install arpakitlib==3.0.5
101
128
  ```
102
129
 
103
130
  Install straight from the repository:
@@ -120,15 +147,15 @@ pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://
120
147
  from datetime import datetime
121
148
  from decimal import Decimal
122
149
 
123
- from arpakitlib.common_.json_util import transfer_data_to_json_str
150
+ from arpakitlib.common_util.json_etc import convert_data_to_json_str
124
151
 
125
- print(transfer_data_to_json_str({"when": datetime(2026, 9, 4), "price": Decimal("1.5")}))
152
+ print(convert_data_to_json_str({"when": datetime(2026, 9, 4), "price": Decimal("1.5")}))
126
153
  # {
127
154
  # "when": "2026-09-04T00:00:00",
128
155
  # "price": "1.5"
129
156
  # }
130
157
 
131
- print(transfer_data_to_json_str({"when": datetime(2026, 9, 4)}, beautify=False))
158
+ print(convert_data_to_json_str({"when": datetime(2026, 9, 4)}, beautify=False))
132
159
  # {"when":"2026-09-04T00:00:00"}
133
160
  ```
134
161
 
@@ -136,9 +163,16 @@ print(transfer_data_to_json_str({"when": datetime(2026, 9, 4)}, beautify=False))
136
163
 
137
164
  ### Development
138
165
 
166
+ Extras are not installed by default, so use `--all-extras` to get a full environment:
167
+
168
+ ```bash
169
+ poetry install --all-extras
170
+ ```
171
+
172
+ Then run any module's example to check things work:
173
+
139
174
  ```bash
140
- poetry install
141
- poetry run pytest
175
+ python -m arpakitlib.common_util.json
142
176
  ```
143
177
 
144
178
  ---
@@ -153,5 +187,5 @@ poetry run pytest
153
187
 
154
188
  ---
155
189
 
156
- ## ❤️ Made by ARPAKIT Company ❤️
190
+ ## ❤️ Made by arpakit ❤️
157
191
 
@@ -0,0 +1,147 @@
1
+ # arpakitlib
2
+
3
+ ## 🚀 Simplify Your Development Workflow
4
+
5
+ A collection of lightweight and convenient development tools by arpakit, designed to simplify and accelerate
6
+ your workflow.
7
+
8
+ [![PyPI](https://img.shields.io/pypi/v/arpakitlib.svg)](https://pypi.org/project/arpakitlib/)
9
+ [![Python](https://img.shields.io/pypi/pyversions/arpakitlib.svg)](https://pypi.org/project/arpakitlib/)
10
+ [![License](https://img.shields.io/pypi/l/arpakitlib.svg)](https://github.com/ARPAKIT-Company/arpakitlib/blob/master/LICENSE)
11
+
12
+ ---
13
+
14
+ ### What is inside
15
+
16
+ A set of small, self-contained utilities you pick from one at a time.
17
+
18
+ The base install stays light and pulls only a handful of packages. Everything that needs a heavier library lives in
19
+ its own subpackage behind an optional extra, so you install a web framework or a bot framework only if you actually
20
+ use that part.
21
+
22
+ | Subpackage | Extra | What is inside |
23
+ |---|---|---|
24
+ | `common_util` | always installed | JSON, dates, strings, dictionaries, files, settings, background workers, retries, enumerations, shell commands, database dumps, email validation |
25
+ | `http_client_util` | `http-client-util` | sync and async requests with retries and proxy support, plus a base API client |
26
+ | `sqlalchemy_util` | `sqlalchemy-util` | declarative base with introspection, database helper, check constraints, pydantic schemas from existing models |
27
+ | `sqladmin_util` | `sqladmin-util` | introspection for admin model views |
28
+ | `aiogram_util` | `aiogram-util` | parsing telegram bot commands |
29
+
30
+ Every module keeps its own runnable example, so the fastest way to see what a utility does is to run that
31
+ module directly:
32
+
33
+ ```bash
34
+ python -m arpakitlib.<subpackage>.<module>
35
+ ```
36
+
37
+ For example:
38
+
39
+ ```bash
40
+ python -m arpakitlib.common_util.json
41
+ ```
42
+
43
+ ---
44
+
45
+ ### Supported Python version
46
+
47
+ - Python 3.13.4 and above
48
+
49
+ ---
50
+
51
+ ### Installation
52
+
53
+ The base install gives you everything in `common_util`:
54
+
55
+ ```bash
56
+ pip install arpakitlib
57
+ ```
58
+
59
+ ```bash
60
+ poetry add arpakitlib
61
+ ```
62
+
63
+ ```bash
64
+ uv add arpakitlib
65
+ ```
66
+
67
+ Add the extras you need, separately or several at once:
68
+
69
+ ```bash
70
+ pip install "arpakitlib[sqlalchemy-util]"
71
+ ```
72
+
73
+ ```bash
74
+ pip install "arpakitlib[aiogram-util,http-client-util]"
75
+ ```
76
+
77
+ ```bash
78
+ poetry add "arpakitlib[sqlalchemy-util,sqladmin-util]"
79
+ ```
80
+
81
+ Pin an exact version:
82
+
83
+ ```bash
84
+ pip install arpakitlib==3.0.5
85
+ ```
86
+
87
+ Install straight from the repository:
88
+
89
+ ```bash
90
+ pip install git+https://github.com/ARPAKIT-Company/arpakitlib.git
91
+ ```
92
+
93
+ Install a pre-release from TestPyPI:
94
+
95
+ ```bash
96
+ pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ arpakitlib
97
+ ```
98
+
99
+ ---
100
+
101
+ ### Quick start
102
+
103
+ ```python
104
+ from datetime import datetime
105
+ from decimal import Decimal
106
+
107
+ from arpakitlib.common_util.json_etc import convert_data_to_json_str
108
+
109
+ print(convert_data_to_json_str({"when": datetime(2026, 9, 4), "price": Decimal("1.5")}))
110
+ # {
111
+ # "when": "2026-09-04T00:00:00",
112
+ # "price": "1.5"
113
+ # }
114
+
115
+ print(convert_data_to_json_str({"when": datetime(2026, 9, 4)}, beautify=False))
116
+ # {"when":"2026-09-04T00:00:00"}
117
+ ```
118
+
119
+ ---
120
+
121
+ ### Development
122
+
123
+ Extras are not installed by default, so use `--all-extras` to get a full environment:
124
+
125
+ ```bash
126
+ poetry install --all-extras
127
+ ```
128
+
129
+ Then run any module's example to check things work:
130
+
131
+ ```bash
132
+ python -m arpakitlib.common_util.json
133
+ ```
134
+
135
+ ---
136
+
137
+ ### Links
138
+
139
+ - [GitHub](https://github.com/ARPAKIT-Company/arpakitlib)
140
+ - [PyPI](https://pypi.org/project/arpakitlib/)
141
+ - [Telegram channel](https://t.me/arpakitlib)
142
+ - [ARPAKIT Company](https://arpakit.com)
143
+ - [Support](https://t.me/arpakit_company_support)
144
+
145
+ ---
146
+
147
+ ## ❤️ Made by arpakit ❤️
@@ -12,7 +12,7 @@ from aiogram.enums import ParseMode
12
12
  from aiogram.filters import CommandObject
13
13
  from pydantic import BaseModel, Field, ConfigDict
14
14
 
15
- from arpakitlib.common_.parse_command_util import parse_command
15
+ from arpakitlib.common_util.parse_command import parse_command
16
16
 
17
17
  _logger = logging.getLogger(__name__)
18
18
 
@@ -245,29 +245,7 @@ def as_tg_command_handler(
245
245
 
246
246
 
247
247
  def __example():
248
- print("--- help-текст по модели ---")
249
- print(_generate_help_text(command_name="hello-world", model_class=ExampleTgCommandModel))
250
-
251
- print("\n--- описание и значения экранируются ---")
252
-
253
- class DangerousTgCommandModel(BaseTgCommandModel):
254
- """Ставит лимит <b>жирным</b> шрифтом"""
255
-
256
- limit: int = Field(description="должен быть < 100")
257
-
258
- print(_generate_help_text(command_name="set", model_class=DangerousTgCommandModel))
259
-
260
- print("\n--- текст ошибки тоже экранируется ---")
261
- print(_generate_error_text(
262
- command_name="set",
263
- exception=ValueError("expected <class 'str'>, got int: 123")
264
- ))
265
-
266
- print("\n--- разбор значений из команды ---")
267
- samples = ["123", "true", "3.14", "None", "[1, 2, 3]", "[1, 'a']", '{"a": true}', "hello world"]
268
- for sample in samples:
269
- result = _parse_tg_param(value=sample)
270
- print(f"{sample!r:16} -> {result!r} ({type(result).__name__})")
248
+ pass
271
249
 
272
250
 
273
251
  async def __async_example():
@@ -7,15 +7,15 @@ import os
7
7
  _URLSAFE_TO_STANDARD = str.maketrans({"-": "+", "_": "/"})
8
8
 
9
9
 
10
- def _prepare_base64_string(base64_string: str | bytes) -> str:
10
+ def _prepare_base64_value(base64_value: str | bytes) -> str:
11
11
  # пробелы и переносы в копипасте, urlsafe-алфавит, без паддинга — типичный
12
12
  # вид subscription-ссылки; b64decode сам это не добирает
13
- if isinstance(base64_string, (bytes, bytearray)):
14
- base64_string = base64_string.decode("ascii")
15
- if not isinstance(base64_string, str):
16
- raise TypeError(f"base64_string must be str or bytes, got {type(base64_string).__name__}")
13
+ if isinstance(base64_value, (bytes, bytearray)):
14
+ base64_value = base64_value.decode("ascii")
15
+ if not isinstance(base64_value, str):
16
+ raise TypeError(f"base64_value must be str or bytes, got {type(base64_value).__name__}")
17
17
 
18
- compact = "".join(base64_string.split()).translate(_URLSAFE_TO_STANDARD)
18
+ compact = "".join(base64_value.split()).translate(_URLSAFE_TO_STANDARD)
19
19
  compact = compact.rstrip("=")
20
20
  remainder = len(compact) % 4
21
21
  if remainder:
@@ -23,9 +23,9 @@ def _prepare_base64_string(base64_string: str | bytes) -> str:
23
23
  return compact
24
24
 
25
25
 
26
- def convert_base64_string_to_bytes(
26
+ def convert_base64_value_to_bytes(
27
27
  *,
28
- base64_string: str | bytes,
28
+ base64_value: str | bytes,
29
29
  raise_for_error: bool = False
30
30
  ) -> bytes | None:
31
31
  """
@@ -35,20 +35,20 @@ def convert_base64_string_to_bytes(
35
35
  к стандартному, добирается паддинг. Всё остальное, чего нет в алфавите base64,
36
36
  считается ошибкой, а не молча выбрасывается.
37
37
 
38
- :param base64_string: строка или bytes с base64.
38
+ :param base64_value: строка или bytes с base64.
39
39
  :param raise_for_error: поднимать исключение вместо возврата None.
40
40
  """
41
41
  try:
42
- return base64.b64decode(_prepare_base64_string(base64_string), validate=True)
42
+ return base64.b64decode(_prepare_base64_value(base64_value), validate=True)
43
43
  except Exception:
44
44
  if raise_for_error:
45
45
  raise
46
46
  return None
47
47
 
48
48
 
49
- def convert_base64_string_to_string(
49
+ def convert_base64_value_to_string(
50
50
  *,
51
- base64_string: str | bytes,
51
+ base64_value: str | bytes,
52
52
  encoding: str = "utf-8",
53
53
  raise_for_error: bool = False
54
54
  ) -> str | None:
@@ -60,13 +60,13 @@ def convert_base64_string_to_string(
60
60
  с raise_for_error=True: в первом случае это binascii.Error, во втором
61
61
  UnicodeDecodeError.
62
62
 
63
- :param base64_string: строка или bytes с base64.
63
+ :param base64_value: строка или bytes с base64.
64
64
  :param encoding: кодировка декодированных байтов.
65
65
  :param raise_for_error: поднимать исключение вместо возврата None.
66
66
  """
67
67
  try:
68
- return convert_base64_string_to_bytes(
69
- base64_string=base64_string,
68
+ return convert_base64_value_to_bytes(
69
+ base64_value=base64_value,
70
70
  raise_for_error=True
71
71
  ).decode(encoding)
72
72
  except Exception:
@@ -120,7 +120,7 @@ def convert_file_to_base64_string(
120
120
  return None
121
121
 
122
122
 
123
- def convert_base64_string_to_file(
123
+ def convert_base64_value_to_file(
124
124
  *,
125
125
  base64_value: str | bytes,
126
126
  filepath: str,
@@ -134,7 +134,7 @@ def convert_base64_string_to_file(
134
134
  :param raise_for_error: поднимать исключение вместо возврата None.
135
135
  """
136
136
  try:
137
- bytes_ = convert_base64_string_to_bytes(base64_string=base64_value, raise_for_error=True)
137
+ bytes_ = convert_base64_value_to_bytes(base64_value=base64_value, raise_for_error=True)
138
138
  dirpath = os.path.dirname(filepath)
139
139
  if dirpath:
140
140
  os.makedirs(dirpath, exist_ok=True)
@@ -148,57 +148,7 @@ def convert_base64_string_to_file(
148
148
 
149
149
 
150
150
  def __example():
151
- import tempfile
152
-
153
- print("--- туда-обратно из bytes ---")
154
- encoded = convert_to_base64_string(value=b"hello")
155
- print(encoded)
156
- print(convert_base64_string_to_bytes(base64_string=encoded))
157
- print(convert_base64_string_to_string(base64_string=encoded))
158
-
159
- print("--- туда-обратно из строки ---")
160
- encoded = convert_to_base64_string(value="привет")
161
- print(encoded)
162
- print(convert_base64_string_to_string(base64_string=encoded))
163
- print(convert_to_base64_string(value="привет", encoding="cp1251"))
164
-
165
- print("--- без паддинга / urlsafe / переносы / bytes на входе ---")
166
- print(convert_base64_string_to_string(base64_string="aGVsbG8"))
167
- print(convert_base64_string_to_string(base64_string="aGVs\nbG8="))
168
- print(convert_base64_string_to_bytes(base64_string="-_8="))
169
- print(convert_base64_string_to_string(base64_string=b"aGVsbG8="))
170
-
171
- print("--- битые данные больше не декодируются молча ---")
172
- for value in ("c2Vj!!!cmV0LWRhdGE=", "YWJ`~j", "A"):
173
- print(f" {value!r} -> {convert_base64_string_to_bytes(base64_string=value)}")
174
- try:
175
- convert_base64_string_to_bytes(base64_string="YWJ`~j", raise_for_error=True)
176
- print(" ошибки не было")
177
- except Exception as exception:
178
- print(f" с raise: {type(exception).__name__}")
179
-
180
- print("--- не UTF-8 ---")
181
- encoded = convert_to_base64_string(value=bytes([0xff, 0xfe]))
182
- print(f" {convert_base64_string_to_string(base64_string=encoded)}")
183
- try:
184
- convert_base64_string_to_string(base64_string=encoded, raise_for_error=True)
185
- print(" ошибки не было")
186
- except Exception as exception:
187
- print(f" с raise: {type(exception).__name__}")
188
-
189
- print("--- файл ---")
190
- filepath = os.path.join(tempfile.mkdtemp(), "example.bin")
191
- with open(filepath, mode="wb") as f:
192
- f.write(b"file-bytes")
193
- encoded = convert_file_to_base64_string(filepath=filepath)
194
- print(encoded)
195
- print(convert_file_to_base64_string(filepath=filepath + ".missing"))
196
-
197
- print("--- обратно в файл ---")
198
- out_filepath = os.path.join(os.path.dirname(filepath), "новая", "папка", "out.bin")
199
- print(convert_base64_string_to_file(base64_value=encoded, filepath=out_filepath))
200
- with open(out_filepath, mode="rb") as f:
201
- print(f.read())
151
+ pass
202
152
 
203
153
 
204
154
  async def __async_example():
@@ -8,9 +8,9 @@ from datetime import timedelta
8
8
  from typing import Any
9
9
  from uuid import uuid4
10
10
 
11
- from arpakitlib.common_.enumeration_util import Enumeration
12
- from arpakitlib.common_.func_etc_util import is_async_func, is_sync_func
13
- from arpakitlib.common_.safe_sleep_util import async_safe_sleep, sync_safe_sleep
11
+ from arpakitlib.common_util.enumeration import Enumeration
12
+ from arpakitlib.common_util.func_etc import is_async_func, is_sync_func
13
+ from arpakitlib.common_util.safe_sleep import async_safe_sleep, sync_safe_sleep
14
14
 
15
15
  BackgroundHandle = asyncio.Task[None] | threading.Thread | multiprocessing.Process
16
16
 
@@ -179,81 +179,11 @@ def safe_run_workers_in_background(
179
179
 
180
180
 
181
181
  def __example():
182
- logging.basicConfig(level=logging.INFO)
183
-
184
- def startup():
185
- print("startup")
186
-
187
- class TickWorker(BaseWorker):
188
- def __init__(self):
189
- super().__init__(
190
- timeout_after_run=timedelta(seconds=0.05),
191
- timeout_after_error_in_run=timedelta(seconds=0.05),
192
- startup_funcs=[startup],
193
- worker_name="tick",
194
- data={"k": 1},
195
- )
196
- self.n = 0
197
-
198
- def sync_run(self):
199
- self.n += 1
200
- print(f"sync_run n={self.n} data={self.data}")
201
- if self.n == 2:
202
- raise RuntimeError("boom")
203
- if self.n >= 4:
204
- raise KeyboardInterrupt
205
-
206
- def sync_on_error(self, exception: Exception):
207
- print(f"on_error: {exception}")
208
-
209
- print("--- worker ---")
210
- worker = TickWorker()
211
- print(worker.worker_fullname)
212
-
213
- print("--- sync_safe_run ---")
214
- try:
215
- worker.sync_safe_run()
216
- except KeyboardInterrupt:
217
- print("stop")
182
+ pass
218
183
 
219
184
 
220
185
  async def __async_example():
221
- def startup():
222
- print("async startup")
223
-
224
- class TickWorker(BaseWorker):
225
- def __init__(self):
226
- super().__init__(
227
- timeout_after_run=timedelta(seconds=0.05),
228
- timeout_after_error_in_run=timedelta(seconds=0.05),
229
- startup_funcs=[startup],
230
- worker_name="async_tick",
231
- )
232
- self.n = 0
233
-
234
- async def async_run(self):
235
- self.n += 1
236
- print(f"async_run n={self.n}")
237
- if self.n == 2:
238
- raise RuntimeError("boom")
239
-
240
- async def async_on_error(self, exception: Exception):
241
- print(f"on_error: {exception}")
242
-
243
- print("--- async_task ---")
244
- worker = TickWorker()
245
- task = safe_run_worker_in_background(
246
- worker=worker,
247
- mode=SafeRunInBackgroundModes.async_task,
248
- )
249
- print(task)
250
- await async_safe_sleep(timedelta(seconds=0.3))
251
- task.cancel()
252
- try:
253
- await task
254
- except asyncio.CancelledError:
255
- pass
256
- print(f"stop n={worker.n}")
186
+ pass
257
187
 
258
188
 
259
189
  if __name__ == '__main__':
@@ -2,7 +2,7 @@
2
2
 
3
3
  import asyncio
4
4
 
5
- from arpakitlib.common_.enumeration_util import Enumeration
5
+ from arpakitlib.common_util.enumeration import Enumeration
6
6
 
7
7
 
8
8
  class BaseBlank:
@@ -6,9 +6,9 @@ from typing import Any
6
6
 
7
7
  from pydantic import BaseModel
8
8
 
9
- from arpakitlib.common_.datetime_etc_util import UTC, now_utc_dt
10
- from arpakitlib.common_.json_db_util import JSONDbFile
11
- from arpakitlib.common_.type_etc_util import raise_for_type
9
+ from arpakitlib.common_util.datetime_etc import UTC, now_utc_dt
10
+ from arpakitlib.common_util.json_db import JSONDbFile
11
+ from arpakitlib.common_util.type_etc import raise_for_type
12
12
 
13
13
 
14
14
  class CacheBlock(BaseModel):
@@ -95,37 +95,7 @@ class CacheFile:
95
95
 
96
96
 
97
97
  def __example():
98
- import os
99
- import tempfile
100
-
101
- filepath = os.path.join(tempfile.mkdtemp(), "cache.json")
102
- cache = CacheFile(json_db_file=JSONDbFile(filepath=filepath))
103
-
104
- print("--- create / get ---")
105
- block = cache.create_block(key="user:1", data={"name": "ada"})
106
- print(block)
107
- print(cache.get_block(key="user:1"))
108
-
109
- print("--- update ---")
110
- print(cache.update_block(key="user:1", data={"name": "ada", "city": "london"}))
111
- print(cache.get_blocks())
112
-
113
- print("--- data обязателен, пишется всегда, в том числе None ---")
114
- cache.update_block(key="user:1", data=None)
115
- print(cache.get_block(key="user:1"))
116
- try:
117
- cache.update_block(key="user:1")
118
- print("без data: ошибки не было")
119
- except TypeError as exception:
120
- print(f"без data: {exception}")
121
-
122
- print("--- время проставляется само ---")
123
- block = cache.create_block(key="when", data=1)
124
- print(f"при создании: {block.last_update_dt}")
125
- print(f"после обновления: {cache.update_block(key='when', data=2).last_update_dt}")
126
-
127
- cache.remove_blocks()
128
- print(f"len after clear: {len(cache)}")
98
+ pass
129
99
 
130
100
 
131
101
  async def __async_example():