morebuiltins 0.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.
- morebuiltins-0.0.1/.github/workflows/pythonpackage.yml +59 -0
- morebuiltins-0.0.1/.gitignore +133 -0
- morebuiltins-0.0.1/LICENSE +21 -0
- morebuiltins-0.0.1/PKG-INFO +108 -0
- morebuiltins-0.0.1/README.md +97 -0
- morebuiltins-0.0.1/doc.md +658 -0
- morebuiltins-0.0.1/doc.py +52 -0
- morebuiltins-0.0.1/morebuiltins/__init__.py +7 -0
- morebuiltins-0.0.1/morebuiltins/functools.py +169 -0
- morebuiltins-0.0.1/morebuiltins/ipc.py +376 -0
- morebuiltins-0.0.1/morebuiltins/request.py +343 -0
- morebuiltins-0.0.1/morebuiltins/utils.py +810 -0
- morebuiltins-0.0.1/pyproject.toml +16 -0
- morebuiltins-0.0.1/test.py +30 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
name: Python package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
- master
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test-linux:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
max-parallel: 3
|
|
14
|
+
matrix:
|
|
15
|
+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
|
|
16
|
+
timeout-minutes: 3
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
20
|
+
uses: actions/setup-python@v4
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
- name: Test
|
|
24
|
+
run: |
|
|
25
|
+
python test.py
|
|
26
|
+
|
|
27
|
+
test-mac:
|
|
28
|
+
runs-on: macos-latest
|
|
29
|
+
strategy:
|
|
30
|
+
max-parallel: 3
|
|
31
|
+
matrix:
|
|
32
|
+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
|
|
33
|
+
timeout-minutes: 3
|
|
34
|
+
steps:
|
|
35
|
+
- uses: actions/checkout@v4
|
|
36
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
37
|
+
uses: actions/setup-python@v4
|
|
38
|
+
with:
|
|
39
|
+
python-version: ${{ matrix.python-version }}
|
|
40
|
+
- name: Test
|
|
41
|
+
run: |
|
|
42
|
+
python test.py
|
|
43
|
+
|
|
44
|
+
test-win32:
|
|
45
|
+
runs-on: windows-latest
|
|
46
|
+
strategy:
|
|
47
|
+
max-parallel: 3
|
|
48
|
+
matrix:
|
|
49
|
+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
|
|
50
|
+
timeout-minutes: 3
|
|
51
|
+
steps:
|
|
52
|
+
- uses: actions/checkout@v4
|
|
53
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
54
|
+
uses: actions/setup-python@v4
|
|
55
|
+
with:
|
|
56
|
+
python-version: ${{ matrix.python-version }}
|
|
57
|
+
- name: Test
|
|
58
|
+
run: |
|
|
59
|
+
python test.py
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
pip-wheel-metadata/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
# Usually these files are written by a python script from a template
|
|
32
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
33
|
+
*.manifest
|
|
34
|
+
*.spec
|
|
35
|
+
|
|
36
|
+
# Installer logs
|
|
37
|
+
pip-log.txt
|
|
38
|
+
pip-delete-this-directory.txt
|
|
39
|
+
|
|
40
|
+
# Unit test / coverage reports
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
.nox/
|
|
44
|
+
.coverage
|
|
45
|
+
.coverage.*
|
|
46
|
+
.cache
|
|
47
|
+
nosetests.xml
|
|
48
|
+
coverage.xml
|
|
49
|
+
*.cover
|
|
50
|
+
*.py,cover
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
target/
|
|
76
|
+
|
|
77
|
+
# Jupyter Notebook
|
|
78
|
+
.ipynb_checkpoints
|
|
79
|
+
|
|
80
|
+
# IPython
|
|
81
|
+
profile_default/
|
|
82
|
+
ipython_config.py
|
|
83
|
+
|
|
84
|
+
# pyenv
|
|
85
|
+
.python-version
|
|
86
|
+
|
|
87
|
+
# pipenv
|
|
88
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
89
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
90
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
91
|
+
# install all needed dependencies.
|
|
92
|
+
#Pipfile.lock
|
|
93
|
+
|
|
94
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
95
|
+
__pypackages__/
|
|
96
|
+
|
|
97
|
+
# Celery stuff
|
|
98
|
+
celerybeat-schedule
|
|
99
|
+
celerybeat.pid
|
|
100
|
+
|
|
101
|
+
# SageMath parsed files
|
|
102
|
+
*.sage.py
|
|
103
|
+
|
|
104
|
+
# Environments
|
|
105
|
+
.env
|
|
106
|
+
.venv
|
|
107
|
+
env/
|
|
108
|
+
venv/
|
|
109
|
+
ENV/
|
|
110
|
+
env.bak/
|
|
111
|
+
venv.bak/
|
|
112
|
+
|
|
113
|
+
# Spyder project settings
|
|
114
|
+
.spyderproject
|
|
115
|
+
.spyproject
|
|
116
|
+
|
|
117
|
+
# Rope project settings
|
|
118
|
+
.ropeproject
|
|
119
|
+
|
|
120
|
+
# mkdocs documentation
|
|
121
|
+
/site
|
|
122
|
+
|
|
123
|
+
# mypy
|
|
124
|
+
.mypy_cache/
|
|
125
|
+
.dmypy.json
|
|
126
|
+
dmypy.json
|
|
127
|
+
|
|
128
|
+
# Pyre type checker
|
|
129
|
+
.pyre/
|
|
130
|
+
|
|
131
|
+
# .vscode
|
|
132
|
+
.vscode/
|
|
133
|
+
temp*.py
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 ClericPy
|
|
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.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: morebuiltins
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Things which I thought should be set in builtins.
|
|
5
|
+
Author-email: ClericPy <clericpy@gmail.com>
|
|
6
|
+
Requires-Python: >=3.7
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Project-URL: Home, https://github.com/ClericPy/morebuiltins
|
|
10
|
+
|
|
11
|
+
# morebuiltins
|
|
12
|
+
|
|
13
|
+
> I need much more built-ins
|
|
14
|
+
|
|
15
|
+
## Purpose
|
|
16
|
+
|
|
17
|
+
1. Collect commonly used code snippets to make up for the lack of built-in functions
|
|
18
|
+
2. Provide some common ideas for beginners
|
|
19
|
+
3. Stay Hungry, Stay Foolish
|
|
20
|
+
|
|
21
|
+
## Doc
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Module Docs - https://github.com/ClericPy/morebuiltins/blob/master/doc.md
|
|
26
|
+
|
|
27
|
+
<!-- start -->
|
|
28
|
+
## 1. morebuiltins.utils
|
|
29
|
+
|
|
30
|
+
1.1 `ttime` - Converts a timestamp to a human-readable timestring formatted as %Y-%m-%d %H:%M:%S.
|
|
31
|
+
|
|
32
|
+
1.2 `ptime` - Converts a timestring formatted as %Y-%m-%d %H:%M:%S back into a timestamp.
|
|
33
|
+
|
|
34
|
+
1.3 `slice_into_pieces` - Divides a sequence into “n” segments, returning a generator that yields “n” pieces.
|
|
35
|
+
|
|
36
|
+
1.4 `slice_by_size` - Slices a sequence into chunks of a specified “size”, returning a generator that produces tuples of chunks.
|
|
37
|
+
|
|
38
|
+
1.5 `unique` - Removes duplicate elements from a sequence while preserving the original order efficiently.
|
|
39
|
+
|
|
40
|
+
1.6 `retry` - A decorator that retries the decorated function up to “tries” times if the specified exceptions are raised.
|
|
41
|
+
|
|
42
|
+
1.7 `guess_interval` - Analyzes a sequence of numbers and returns the median, calculating intervals only if they are greater than or equal to the specified accuracy.
|
|
43
|
+
|
|
44
|
+
1.8 `get_hash` - Generates an MD5 hash string from the given input string.
|
|
45
|
+
|
|
46
|
+
1.9 `find_jsons` - A generator that locates valid JSON strings, supporting only dictionaries and lists.
|
|
47
|
+
|
|
48
|
+
1.10 `code_inline` - Minifies Python source code into a single line.
|
|
49
|
+
|
|
50
|
+
1.11 `read_size` - Converts byte counts into a human-readable string. Setting shorten=True and precision=0.99 will trim unnecessary decimal places from the tail of floating-point numbers.
|
|
51
|
+
|
|
52
|
+
1.12 `read_time` - Converts seconds into a more readable time duration string.
|
|
53
|
+
|
|
54
|
+
1.13 `Validator` - Validator for dataclasses.
|
|
55
|
+
|
|
56
|
+
1.14 `stagger_sort` - Ensures that identical groups are ordered and evenly distributed, mitigating data skew. The function does not alter the original list and returns a generator.
|
|
57
|
+
|
|
58
|
+
1.15 `default_dict` - Initializes a dictionary with default zero values based on a subclass of TypedDict.
|
|
59
|
+
|
|
60
|
+
1.16 `always_return_value` - Got a function always return the given value.
|
|
61
|
+
|
|
62
|
+
1.17 `format_error` - Extracts frame information from an exception, with an option to filter out “site-packages” details by default.
|
|
63
|
+
|
|
64
|
+
1.18 `Trie` - Transforms a standard dictionary into a trie structure that supports prefix matching.
|
|
65
|
+
|
|
66
|
+
1.19 `GuessExt` - Determines whether the input bytes of a file prefix indicate a compressed file format.
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## 2. morebuiltins.functools
|
|
70
|
+
|
|
71
|
+
2.1 `lru_cache_ttl` - A Least Recently Used (LRU) cache with a Time To Live (TTL) feature.
|
|
72
|
+
|
|
73
|
+
2.2 `threads` - Quickly convert synchronous functions to be concurrency-able. (similar to madisonmay/Tomorrow)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
## 3. morebuiltins.ipc
|
|
77
|
+
|
|
78
|
+
3.1 `IPCEncoder` - An abstract base class for all encoders; implementing the necessary communication protocol requires only the definition of two abstract methods. Be mindful that varying header lengths will impact the maximum packaging size.
|
|
79
|
+
|
|
80
|
+
3.4 `SocketLogHandlerEncoder` - For a practical demonstration, refer to the test code: morebuiltins\ipc.py:_test_ipc_logging.
|
|
81
|
+
|
|
82
|
+
3.5 `SocketServer` - To see an example in action, view the test code: morebuiltins\ipc.py:_test_ipc.
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
## 4. morebuiltins.request
|
|
86
|
+
|
|
87
|
+
4.1 `req` - A basic mock for requests, performant albeit simplistic.
|
|
88
|
+
|
|
89
|
+
4.2 `DomainParser` - Extracts the Second-level domain (SLD) from a provided hostname or URL.
|
|
90
|
+
|
|
91
|
+
4.3 `unparse_qsl` - Provides the inverse operation of parse_qsl, converting query string lists back into a URL-encoded string.
|
|
92
|
+
|
|
93
|
+
4.4 `update_url` - Organizes the query arguments within a URL to standardize its format.
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
<!-- end -->
|
|
97
|
+
|
|
98
|
+
## On the way
|
|
99
|
+
|
|
100
|
+
1. TimeSizeRotatingHandler of logging.handlers
|
|
101
|
+
2. progress_bar
|
|
102
|
+
3. http.server (upload)
|
|
103
|
+
4. function parser (signature.parameters)
|
|
104
|
+
5. time reaches
|
|
105
|
+
6. quick tkinter
|
|
106
|
+
7. http parser (request/response)
|
|
107
|
+
8. asyncio free-flying tasks
|
|
108
|
+
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# morebuiltins
|
|
2
|
+
|
|
3
|
+
> I need much more built-ins
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
1. Collect commonly used code snippets to make up for the lack of built-in functions
|
|
8
|
+
2. Provide some common ideas for beginners
|
|
9
|
+
3. Stay Hungry, Stay Foolish
|
|
10
|
+
|
|
11
|
+
## Doc
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
Module Docs - https://github.com/ClericPy/morebuiltins/blob/master/doc.md
|
|
16
|
+
|
|
17
|
+
<!-- start -->
|
|
18
|
+
## 1. morebuiltins.utils
|
|
19
|
+
|
|
20
|
+
1.1 `ttime` - Converts a timestamp to a human-readable timestring formatted as %Y-%m-%d %H:%M:%S.
|
|
21
|
+
|
|
22
|
+
1.2 `ptime` - Converts a timestring formatted as %Y-%m-%d %H:%M:%S back into a timestamp.
|
|
23
|
+
|
|
24
|
+
1.3 `slice_into_pieces` - Divides a sequence into “n” segments, returning a generator that yields “n” pieces.
|
|
25
|
+
|
|
26
|
+
1.4 `slice_by_size` - Slices a sequence into chunks of a specified “size”, returning a generator that produces tuples of chunks.
|
|
27
|
+
|
|
28
|
+
1.5 `unique` - Removes duplicate elements from a sequence while preserving the original order efficiently.
|
|
29
|
+
|
|
30
|
+
1.6 `retry` - A decorator that retries the decorated function up to “tries” times if the specified exceptions are raised.
|
|
31
|
+
|
|
32
|
+
1.7 `guess_interval` - Analyzes a sequence of numbers and returns the median, calculating intervals only if they are greater than or equal to the specified accuracy.
|
|
33
|
+
|
|
34
|
+
1.8 `get_hash` - Generates an MD5 hash string from the given input string.
|
|
35
|
+
|
|
36
|
+
1.9 `find_jsons` - A generator that locates valid JSON strings, supporting only dictionaries and lists.
|
|
37
|
+
|
|
38
|
+
1.10 `code_inline` - Minifies Python source code into a single line.
|
|
39
|
+
|
|
40
|
+
1.11 `read_size` - Converts byte counts into a human-readable string. Setting shorten=True and precision=0.99 will trim unnecessary decimal places from the tail of floating-point numbers.
|
|
41
|
+
|
|
42
|
+
1.12 `read_time` - Converts seconds into a more readable time duration string.
|
|
43
|
+
|
|
44
|
+
1.13 `Validator` - Validator for dataclasses.
|
|
45
|
+
|
|
46
|
+
1.14 `stagger_sort` - Ensures that identical groups are ordered and evenly distributed, mitigating data skew. The function does not alter the original list and returns a generator.
|
|
47
|
+
|
|
48
|
+
1.15 `default_dict` - Initializes a dictionary with default zero values based on a subclass of TypedDict.
|
|
49
|
+
|
|
50
|
+
1.16 `always_return_value` - Got a function always return the given value.
|
|
51
|
+
|
|
52
|
+
1.17 `format_error` - Extracts frame information from an exception, with an option to filter out “site-packages” details by default.
|
|
53
|
+
|
|
54
|
+
1.18 `Trie` - Transforms a standard dictionary into a trie structure that supports prefix matching.
|
|
55
|
+
|
|
56
|
+
1.19 `GuessExt` - Determines whether the input bytes of a file prefix indicate a compressed file format.
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
## 2. morebuiltins.functools
|
|
60
|
+
|
|
61
|
+
2.1 `lru_cache_ttl` - A Least Recently Used (LRU) cache with a Time To Live (TTL) feature.
|
|
62
|
+
|
|
63
|
+
2.2 `threads` - Quickly convert synchronous functions to be concurrency-able. (similar to madisonmay/Tomorrow)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
## 3. morebuiltins.ipc
|
|
67
|
+
|
|
68
|
+
3.1 `IPCEncoder` - An abstract base class for all encoders; implementing the necessary communication protocol requires only the definition of two abstract methods. Be mindful that varying header lengths will impact the maximum packaging size.
|
|
69
|
+
|
|
70
|
+
3.4 `SocketLogHandlerEncoder` - For a practical demonstration, refer to the test code: morebuiltins\ipc.py:_test_ipc_logging.
|
|
71
|
+
|
|
72
|
+
3.5 `SocketServer` - To see an example in action, view the test code: morebuiltins\ipc.py:_test_ipc.
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
## 4. morebuiltins.request
|
|
76
|
+
|
|
77
|
+
4.1 `req` - A basic mock for requests, performant albeit simplistic.
|
|
78
|
+
|
|
79
|
+
4.2 `DomainParser` - Extracts the Second-level domain (SLD) from a provided hostname or URL.
|
|
80
|
+
|
|
81
|
+
4.3 `unparse_qsl` - Provides the inverse operation of parse_qsl, converting query string lists back into a URL-encoded string.
|
|
82
|
+
|
|
83
|
+
4.4 `update_url` - Organizes the query arguments within a URL to standardize its format.
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
<!-- end -->
|
|
87
|
+
|
|
88
|
+
## On the way
|
|
89
|
+
|
|
90
|
+
1. TimeSizeRotatingHandler of logging.handlers
|
|
91
|
+
2. progress_bar
|
|
92
|
+
3. http.server (upload)
|
|
93
|
+
4. function parser (signature.parameters)
|
|
94
|
+
5. time reaches
|
|
95
|
+
6. quick tkinter
|
|
96
|
+
7. http parser (request/response)
|
|
97
|
+
8. asyncio free-flying tasks
|