@formaggio-software/rhtop-windows-amd64 0.0.0-stage → 0.0.6
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.
- package/package.json +16 -4
- package/payload/LICENSE.txt +95 -0
- package/payload/NOTICE +14 -0
- package/payload/THIRD_PARTY_NOTICES/altgraph-0.17.5.dist-info/LICENSE +18 -0
- package/payload/THIRD_PARTY_NOTICES/altgraph-0.17.5.dist-info/METADATA +307 -0
- package/payload/THIRD_PARTY_NOTICES/annotated_types-0.8.0.dist-info/METADATA +295 -0
- package/payload/THIRD_PARTY_NOTICES/annotated_types-0.8.0.dist-info/licenses/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/anyio-4.16.0.dist-info/METADATA +108 -0
- package/payload/THIRD_PARTY_NOTICES/anyio-4.16.0.dist-info/licenses/LICENSE +20 -0
- package/payload/THIRD_PARTY_NOTICES/attrs-26.1.0.dist-info/METADATA +199 -0
- package/payload/THIRD_PARTY_NOTICES/attrs-26.1.0.dist-info/licenses/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/backports.tarfile-1.2.0.dist-info/LICENSE +17 -0
- package/payload/THIRD_PARTY_NOTICES/backports.tarfile-1.2.0.dist-info/METADATA +46 -0
- package/payload/THIRD_PARTY_NOTICES/build-1.6.1.dist-info/METADATA +142 -0
- package/payload/THIRD_PARTY_NOTICES/build-1.6.1.dist-info/licenses/LICENSE +20 -0
- package/payload/THIRD_PARTY_NOTICES/cffi-2.1.1.dist-info/METADATA +67 -0
- package/payload/THIRD_PARTY_NOTICES/cffi-2.1.1.dist-info/licenses/LICENSE +23 -0
- package/payload/THIRD_PARTY_NOTICES/click-8.5.1.dist-info/METADATA +83 -0
- package/payload/THIRD_PARTY_NOTICES/click-8.5.1.dist-info/licenses/LICENSE.txt +28 -0
- package/payload/THIRD_PARTY_NOTICES/colorama-0.4.6.dist-info/METADATA +441 -0
- package/payload/THIRD_PARTY_NOTICES/colorama-0.4.6.dist-info/licenses/LICENSE.txt +27 -0
- package/payload/THIRD_PARTY_NOTICES/cryptography-50.0.2.dist-info/METADATA +111 -0
- package/payload/THIRD_PARTY_NOTICES/cryptography-50.0.2.dist-info/licenses/LICENSE +3 -0
- package/payload/THIRD_PARTY_NOTICES/cryptography-50.0.2.dist-info/licenses/LICENSE.APACHE +202 -0
- package/payload/THIRD_PARTY_NOTICES/cryptography-50.0.2.dist-info/licenses/LICENSE.BSD +27 -0
- package/payload/THIRD_PARTY_NOTICES/h11-0.16.0.dist-info/METADATA +202 -0
- package/payload/THIRD_PARTY_NOTICES/h11-0.16.0.dist-info/licenses/LICENSE.txt +22 -0
- package/payload/THIRD_PARTY_NOTICES/hatchling-1.33.0.dist-info/METADATA +81 -0
- package/payload/THIRD_PARTY_NOTICES/hatchling-1.33.0.dist-info/licenses/LICENSE.txt +9 -0
- package/payload/THIRD_PARTY_NOTICES/httpcore2-2.16.2.dist-info/METADATA +798 -0
- package/payload/THIRD_PARTY_NOTICES/httpcore2-2.16.2.dist-info/licenses/LICENSE.md +28 -0
- package/payload/THIRD_PARTY_NOTICES/httpx2-2.16.2.dist-info/METADATA +227 -0
- package/payload/THIRD_PARTY_NOTICES/httpx2-2.16.2.dist-info/licenses/LICENSE.md +13 -0
- package/payload/THIRD_PARTY_NOTICES/idna-3.20.dist-info/METADATA +176 -0
- package/payload/THIRD_PARTY_NOTICES/idna-3.20.dist-info/licenses/LICENSE.md +31 -0
- package/payload/THIRD_PARTY_NOTICES/importlib_metadata-10.2.0.dist-info/METADATA +131 -0
- package/payload/THIRD_PARTY_NOTICES/importlib_metadata-10.2.0.dist-info/licenses/LICENSE +73 -0
- package/payload/THIRD_PARTY_NOTICES/iniconfig-2.3.1.dist-info/METADATA +84 -0
- package/payload/THIRD_PARTY_NOTICES/iniconfig-2.3.1.dist-info/licenses/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/jaraco.classes-3.4.0.dist-info/LICENSE +17 -0
- package/payload/THIRD_PARTY_NOTICES/jaraco.classes-3.4.0.dist-info/METADATA +60 -0
- package/payload/THIRD_PARTY_NOTICES/jaraco_context-6.1.2.dist-info/METADATA +81 -0
- package/payload/THIRD_PARTY_NOTICES/jaraco_context-6.1.2.dist-info/licenses/LICENSE +18 -0
- package/payload/THIRD_PARTY_NOTICES/jaraco_functools-4.6.0.dist-info/METADATA +68 -0
- package/payload/THIRD_PARTY_NOTICES/jaraco_functools-4.6.0.dist-info/licenses/LICENSE +18 -0
- package/payload/THIRD_PARTY_NOTICES/jsonschema-4.26.0.dist-info/METADATA +170 -0
- package/payload/THIRD_PARTY_NOTICES/jsonschema-4.26.0.dist-info/licenses/COPYING +19 -0
- package/payload/THIRD_PARTY_NOTICES/jsonschema_specifications-2025.9.1.dist-info/METADATA +54 -0
- package/payload/THIRD_PARTY_NOTICES/jsonschema_specifications-2025.9.1.dist-info/licenses/COPYING +19 -0
- package/payload/THIRD_PARTY_NOTICES/keyring-25.7.0.dist-info/METADATA +554 -0
- package/payload/THIRD_PARTY_NOTICES/keyring-25.7.0.dist-info/licenses/LICENSE +18 -0
- package/payload/THIRD_PARTY_NOTICES/lazy_importer-0.1.0.dist-info/METADATA +174 -0
- package/payload/THIRD_PARTY_NOTICES/lazy_importer-0.1.0.dist-info/licenses/LICENSE +202 -0
- package/payload/THIRD_PARTY_NOTICES/linkify_it_py-2.2.0.dist-info/METADATA +262 -0
- package/payload/THIRD_PARTY_NOTICES/linkify_it_py-2.2.0.dist-info/licenses/LICENSE +48 -0
- package/payload/THIRD_PARTY_NOTICES/markdown_it_py-4.3.0.dist-info/METADATA +237 -0
- package/payload/THIRD_PARTY_NOTICES/markdown_it_py-4.3.0.dist-info/licenses/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/markdown_it_py-4.3.0.dist-info/licenses/LICENSE.markdown-it +22 -0
- package/payload/THIRD_PARTY_NOTICES/mcp-2.3.0.dist-info/METADATA +172 -0
- package/payload/THIRD_PARTY_NOTICES/mcp-2.3.0.dist-info/licenses/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/mcp_types-2.3.0.dist-info/METADATA +43 -0
- package/payload/THIRD_PARTY_NOTICES/mcp_types-2.3.0.dist-info/licenses/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/mdit_py_plugins-0.7.0.dist-info/METADATA +60 -0
- package/payload/THIRD_PARTY_NOTICES/mdit_py_plugins-0.7.0.dist-info/licenses/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/mdurl-0.1.2.dist-info/LICENSE +46 -0
- package/payload/THIRD_PARTY_NOTICES/mdurl-0.1.2.dist-info/METADATA +32 -0
- package/payload/THIRD_PARTY_NOTICES/more_itertools-11.2.1.dist-info/METADATA +302 -0
- package/payload/THIRD_PARTY_NOTICES/more_itertools-11.2.1.dist-info/licenses/LICENSE +19 -0
- package/payload/THIRD_PARTY_NOTICES/opentelemetry_api-1.45.2.dist-info/METADATA +43 -0
- package/payload/THIRD_PARTY_NOTICES/opentelemetry_api-1.45.2.dist-info/licenses/LICENSE +201 -0
- package/payload/THIRD_PARTY_NOTICES/packaging-26.3.dist-info/METADATA +112 -0
- package/payload/THIRD_PARTY_NOTICES/packaging-26.3.dist-info/licenses/LICENSE +3 -0
- package/payload/THIRD_PARTY_NOTICES/packaging-26.3.dist-info/licenses/LICENSE.APACHE +177 -0
- package/payload/THIRD_PARTY_NOTICES/packaging-26.3.dist-info/licenses/LICENSE.BSD +23 -0
- package/payload/THIRD_PARTY_NOTICES/pathspec-1.1.1.dist-info/METADATA +392 -0
- package/payload/THIRD_PARTY_NOTICES/pathspec-1.1.1.dist-info/licenses/LICENSE +373 -0
- package/payload/THIRD_PARTY_NOTICES/pefile-2024.8.26.dist-info/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/pefile-2024.8.26.dist-info/METADATA +34 -0
- package/payload/THIRD_PARTY_NOTICES/pip-23.2.1.dist-info/LICENSE.txt +20 -0
- package/payload/THIRD_PARTY_NOTICES/pip-23.2.1.dist-info/METADATA +90 -0
- package/payload/THIRD_PARTY_NOTICES/platformdirs-4.14.7.dist-info/METADATA +114 -0
- package/payload/THIRD_PARTY_NOTICES/platformdirs-4.14.7.dist-info/licenses/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/pluggy-1.7.0.dist-info/METADATA +152 -0
- package/payload/THIRD_PARTY_NOTICES/pluggy-1.7.0.dist-info/licenses/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/pycparser-3.12.dist-info/METADATA +286 -0
- package/payload/THIRD_PARTY_NOTICES/pycparser-3.12.dist-info/licenses/LICENSE +27 -0
- package/payload/THIRD_PARTY_NOTICES/pydantic-2.14.3.dist-info/METADATA +1646 -0
- package/payload/THIRD_PARTY_NOTICES/pydantic-2.14.3.dist-info/licenses/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/pydantic_core-2.50.4.dist-info/METADATA +172 -0
- package/payload/THIRD_PARTY_NOTICES/pydantic_core-2.50.4.dist-info/licenses/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/pygments-2.21.0.dist-info/METADATA +58 -0
- package/payload/THIRD_PARTY_NOTICES/pygments-2.21.0.dist-info/licenses/AUTHORS +296 -0
- package/payload/THIRD_PARTY_NOTICES/pygments-2.21.0.dist-info/licenses/LICENSE +25 -0
- package/payload/THIRD_PARTY_NOTICES/pyinstaller-6.22.3.dist-info/METADATA +213 -0
- package/payload/THIRD_PARTY_NOTICES/pyinstaller-6.22.3.dist-info/licenses/COPYING.txt +648 -0
- package/payload/THIRD_PARTY_NOTICES/pyinstaller_hooks_contrib-2026.10.dist-info/METADATA +373 -0
- package/payload/THIRD_PARTY_NOTICES/pyinstaller_hooks_contrib-2026.10.dist-info/licenses/LICENSE +521 -0
- package/payload/THIRD_PARTY_NOTICES/pyjwt-2.15.1.dist-info/METADATA +94 -0
- package/payload/THIRD_PARTY_NOTICES/pyjwt-2.15.1.dist-info/licenses/AUTHORS.rst +7 -0
- package/payload/THIRD_PARTY_NOTICES/pyjwt-2.15.1.dist-info/licenses/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/pyproject_hooks-1.3.3.dist-info/METADATA +27 -0
- package/payload/THIRD_PARTY_NOTICES/pyproject_hooks-1.3.3.dist-info/licenses/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/pytest-9.2.0.dist-info/METADATA +217 -0
- package/payload/THIRD_PARTY_NOTICES/pytest-9.2.0.dist-info/licenses/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/pytest_asyncio-1.5.0.dist-info/METADATA +100 -0
- package/payload/THIRD_PARTY_NOTICES/pytest_asyncio-1.5.0.dist-info/licenses/LICENSE +201 -0
- package/payload/THIRD_PARTY_NOTICES/python_multipart-0.0.34.dist-info/METADATA +179 -0
- package/payload/THIRD_PARTY_NOTICES/python_multipart-0.0.34.dist-info/licenses/LICENSE.txt +202 -0
- package/payload/THIRD_PARTY_NOTICES/pywin32-312.dist-info/METADATA +261 -0
- package/payload/THIRD_PARTY_NOTICES/pywin32-312.dist-info/licenses/adodbapi/license.txt +505 -0
- package/payload/THIRD_PARTY_NOTICES/pywin32-312.dist-info/licenses/com/License.txt +30 -0
- package/payload/THIRD_PARTY_NOTICES/pywin32-312.dist-info/licenses/com/win32comext/mapi/src/MAPIStubLibrary/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/pywin32-312.dist-info/licenses/isapi/README.txt +7 -0
- package/payload/THIRD_PARTY_NOTICES/pywin32-312.dist-info/licenses/pythonwin/License.txt +30 -0
- package/payload/THIRD_PARTY_NOTICES/pywin32-312.dist-info/licenses/pythonwin/Scintilla/License.txt +20 -0
- package/payload/THIRD_PARTY_NOTICES/pywin32-312.dist-info/licenses/pythonwin/pywin/idle/LICENSE.txt +246 -0
- package/payload/THIRD_PARTY_NOTICES/pywin32-312.dist-info/licenses/win32/License.txt +30 -0
- package/payload/THIRD_PARTY_NOTICES/pywin32_ctypes-0.2.3.dist-info/LICENSE.txt +28 -0
- package/payload/THIRD_PARTY_NOTICES/pywin32_ctypes-0.2.3.dist-info/METADATA +134 -0
- package/payload/THIRD_PARTY_NOTICES/pywinpty-3.1.2.dist-info/METADATA +162 -0
- package/payload/THIRD_PARTY_NOTICES/pywinpty-3.1.2.dist-info/licenses/LICENSE.txt +21 -0
- package/payload/THIRD_PARTY_NOTICES/pyyaml-6.0.3.dist-info/METADATA +59 -0
- package/payload/THIRD_PARTY_NOTICES/pyyaml-6.0.3.dist-info/licenses/LICENSE +20 -0
- package/payload/THIRD_PARTY_NOTICES/referencing-0.37.0.dist-info/METADATA +64 -0
- package/payload/THIRD_PARTY_NOTICES/referencing-0.37.0.dist-info/licenses/COPYING +19 -0
- package/payload/THIRD_PARTY_NOTICES/rich-15.0.0.dist-info/METADATA +479 -0
- package/payload/THIRD_PARTY_NOTICES/rich-15.0.0.dist-info/licenses/LICENSE +19 -0
- package/payload/THIRD_PARTY_NOTICES/rpds_py-2026.9.1.dist-info/METADATA +99 -0
- package/payload/THIRD_PARTY_NOTICES/rpds_py-2026.9.1.dist-info/licenses/LICENSE +19 -0
- package/payload/THIRD_PARTY_NOTICES/ruff-0.17.5.dist-info/METADATA +484 -0
- package/payload/THIRD_PARTY_NOTICES/ruff-0.17.5.dist-info/licenses/LICENSE +430 -0
- package/payload/THIRD_PARTY_NOTICES/setuptools-65.5.0.dist-info/LICENSE +19 -0
- package/payload/THIRD_PARTY_NOTICES/setuptools-65.5.0.dist-info/METADATA +144 -0
- package/payload/THIRD_PARTY_NOTICES/sse_starlette-3.7.0.dist-info/METADATA +493 -0
- package/payload/THIRD_PARTY_NOTICES/sse_starlette-3.7.0.dist-info/licenses/AUTHORS +10 -0
- package/payload/THIRD_PARTY_NOTICES/sse_starlette-3.7.0.dist-info/licenses/LICENSE +27 -0
- package/payload/THIRD_PARTY_NOTICES/starlette-1.10.0.dist-info/METADATA +181 -0
- package/payload/THIRD_PARTY_NOTICES/starlette-1.10.0.dist-info/licenses/LICENSE.md +27 -0
- package/payload/THIRD_PARTY_NOTICES/textual-6.12.0.dist-info/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/textual-6.12.0.dist-info/METADATA +265 -0
- package/payload/THIRD_PARTY_NOTICES/tomlkit-0.15.2.dist-info/METADATA +93 -0
- package/payload/THIRD_PARTY_NOTICES/tomlkit-0.15.2.dist-info/licenses/LICENSE +20 -0
- package/payload/THIRD_PARTY_NOTICES/trove_classifiers-2026.9.21.13.dist-info/METADATA +82 -0
- package/payload/THIRD_PARTY_NOTICES/trove_classifiers-2026.9.21.13.dist-info/licenses/LICENSE +201 -0
- package/payload/THIRD_PARTY_NOTICES/truststore-0.10.5.dist-info/METADATA +110 -0
- package/payload/THIRD_PARTY_NOTICES/truststore-0.10.5.dist-info/licenses/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/typing_extensions-4.16.0.dist-info/METADATA +73 -0
- package/payload/THIRD_PARTY_NOTICES/typing_extensions-4.16.0.dist-info/licenses/LICENSE +279 -0
- package/payload/THIRD_PARTY_NOTICES/typing_inspection-0.4.5.dist-info/METADATA +49 -0
- package/payload/THIRD_PARTY_NOTICES/typing_inspection-0.4.5.dist-info/licenses/LICENSE +21 -0
- package/payload/THIRD_PARTY_NOTICES/uvicorn-0.54.0.dist-info/METADATA +189 -0
- package/payload/THIRD_PARTY_NOTICES/uvicorn-0.54.0.dist-info/licenses/LICENSE.md +27 -0
- package/payload/THIRD_PARTY_NOTICES/zipp-4.1.2.dist-info/METADATA +108 -0
- package/payload/THIRD_PARTY_NOTICES/zipp-4.1.2.dist-info/licenses/LICENSE +18 -0
- package/payload/rhtop.exe +0 -0
- package/README.md +0 -3
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lazy-importer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A context manager for portable, opt-in lazy imports
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
|
|
10
|
+
# lazy-importer
|
|
11
|
+
|
|
12
|
+
A backwards-compatibility shim allowing libraries to get lazy import semantics
|
|
13
|
+
similar to [PEP 810](https://peps.python.org/pep-0810/) automatically in Python
|
|
14
|
+
3.11+ without needing to set your minimum version to 3.15. In Python 3.15+,
|
|
15
|
+
this falls back to the standard lazy imports mechanism.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Install from a checkout with `python -m pip install .`:
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from lazy_importer import lazy_importer
|
|
23
|
+
|
|
24
|
+
__lazy_modules__ = {"json", "pathlib"}
|
|
25
|
+
|
|
26
|
+
with lazy_importer():
|
|
27
|
+
import json
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# Importing this module doesn't load json or pathlib for these statements.
|
|
32
|
+
def read_config(filename: str) -> object:
|
|
33
|
+
return json.loads(Path(filename).read_text(encoding="utf-8"))
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`__lazy_modules__` determines which imports are lazy. On Python 3.11–3.14, the
|
|
37
|
+
context enables the fallback, which checks the importing module's declaration
|
|
38
|
+
at each import. On Python 3.15+, Python reads the declaration directly and the
|
|
39
|
+
context is a no-op, leaving native controls and filtering in effect without
|
|
40
|
+
loading the fallback implementation. Without a declaration, imports remain
|
|
41
|
+
eager under the default interpreter settings.
|
|
42
|
+
|
|
43
|
+
`__lazy_modules__` contains the names of the modules whose imports should be
|
|
44
|
+
lazy. For a `from` import, the selected module is the one after `from`:
|
|
45
|
+
|
|
46
|
+
| Import statement | Entry in `__lazy_modules__` |
|
|
47
|
+
| --- | --- |
|
|
48
|
+
| `import example.child` | `"example.child"` |
|
|
49
|
+
| `from example import child` | `"example"` |
|
|
50
|
+
| `from example.child import value` | `"example.child"` |
|
|
51
|
+
| `from .child import value` (inside `example`) | `"example.child"` |
|
|
52
|
+
| `from . import child` (inside `example`) | `"example"` |
|
|
53
|
+
|
|
54
|
+
With a set of names, selecting `"example"` doesn't also select imports of
|
|
55
|
+
`"example.child"`. This is also how PEP 810's `__lazy_modules__` works.
|
|
56
|
+
|
|
57
|
+
Both paths check membership in `__lazy_modules__` at each import, so changes to
|
|
58
|
+
the declaration take effect within an active context. A custom container can
|
|
59
|
+
select names through `__contains__` without supporting iteration. An empty or
|
|
60
|
+
absent declaration selects no imports.
|
|
61
|
+
|
|
62
|
+
Each call to `lazy_importer()` creates a context. The fallback context can
|
|
63
|
+
only be entered once, so separate `with` blocks need separate calls even if they
|
|
64
|
+
use the same selection. This is why the example calls `lazy_importer` in the
|
|
65
|
+
`with` statement rather than storing the context for reuse.
|
|
66
|
+
|
|
67
|
+
## When imports run
|
|
68
|
+
|
|
69
|
+
In the example above, importing your module does not load `json` or `pathlib` on
|
|
70
|
+
behalf of those statements. Calling `read_config()` loads them when it reaches
|
|
71
|
+
the operations that need them. Any side effects of their initialization, such
|
|
72
|
+
as registering plugins or configuring logging, are delayed along with the
|
|
73
|
+
import. A module imported only for its side effects therefore needs an eager
|
|
74
|
+
import, or an explicit call to `resolve()` to trigger initialization.
|
|
75
|
+
|
|
76
|
+
Import failures are delayed too. If one of the selected modules is missing or
|
|
77
|
+
raises an exception during initialization, that exception reaches the code that
|
|
78
|
+
first uses it. A `try`/`except` around the import block is therefore not a
|
|
79
|
+
portable way to check whether an optional dependency is available. After a
|
|
80
|
+
failed import, another use can retry it.
|
|
81
|
+
|
|
82
|
+
Once loading starts, the module's own imports run normally unless it opts into
|
|
83
|
+
lazy imports itself. The package uses the import hooks and search path in effect
|
|
84
|
+
at first use, so changes to the import environment between declaration and use
|
|
85
|
+
can affect what gets loaded. With `from module import first, second`, loading
|
|
86
|
+
`first` does not resolve the binding for `second`; each imported name is resolved
|
|
87
|
+
when it is needed.
|
|
88
|
+
|
|
89
|
+
## Differences from PEP 810
|
|
90
|
+
|
|
91
|
+
On Python 3.15+, Python handles lazy imports directly. On older runtimes,
|
|
92
|
+
`lazy-importer` approximates that behavior with proxy objects, which can forward
|
|
93
|
+
operations to the imported object but cannot intercept ordinary variable reads.
|
|
94
|
+
This is the main source of differences between the two.
|
|
95
|
+
|
|
96
|
+
Native lazy imports resolve when you read the imported name. The fallback waits
|
|
97
|
+
for an operation such as attribute access or a call, so assigning the name to
|
|
98
|
+
another variable or putting it in a container can retain a proxy:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from lazy_importer import lazy_importer, resolve
|
|
102
|
+
|
|
103
|
+
__lazy_modules__ = {"decimal"}
|
|
104
|
+
with lazy_importer():
|
|
105
|
+
from decimal import Decimal
|
|
106
|
+
|
|
107
|
+
classes = [Decimal]
|
|
108
|
+
print(type(classes[0]) is type) # False on the fallback; True with native imports.
|
|
109
|
+
classes[0] = resolve(classes[0])
|
|
110
|
+
print(type(classes[0]) is type) # True on both.
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`resolve(value)` returns the real object, loading it if necessary, and returns
|
|
114
|
+
ordinary objects unchanged. This makes it useful at boundaries where identity
|
|
115
|
+
or type matters, including exception matching, serialization and extension
|
|
116
|
+
code that requires a concrete object. Resolving a fallback proxy updates the
|
|
117
|
+
module globals that still refer to it, but a container holding the proxy keeps
|
|
118
|
+
that reference until you replace it, as in the example.
|
|
119
|
+
|
|
120
|
+
Reading another module's attributes has the same limitation: if a module
|
|
121
|
+
imports `Decimal` lazily, `other_module.Decimal` can return a proxy on the
|
|
122
|
+
fallback, whereas native attribute access resolves the import. Protocol checks
|
|
123
|
+
can also see the proxy's methods rather than the real object's capabilities:
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from lazy_importer import lazy_importer, resolve
|
|
127
|
+
|
|
128
|
+
__lazy_modules__ = {"math"}
|
|
129
|
+
with lazy_importer():
|
|
130
|
+
from math import pi
|
|
131
|
+
|
|
132
|
+
print(callable(pi)) # True on the fallback; False with native imports.
|
|
133
|
+
print(callable(resolve(pi))) # False on both.
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
There is also a difference in the scope of the selection. The fallback acts on
|
|
137
|
+
imports made while the context is active on the current thread, including
|
|
138
|
+
imports in functions called from the block. Native `__lazy_modules__` does not
|
|
139
|
+
make function-local imports lazy:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from lazy_importer import lazy_importer
|
|
143
|
+
|
|
144
|
+
__lazy_modules__ = {"decimal"}
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def load_decimal():
|
|
148
|
+
import decimal
|
|
149
|
+
|
|
150
|
+
return decimal
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
with lazy_importer():
|
|
154
|
+
module = load_decimal() # A proxy on the fallback; a real module on 3.15+.
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
A module-level block containing only import statements avoids this difference.
|
|
158
|
+
The fallback also does not enforce the native restrictions on lazy imports in
|
|
159
|
+
class bodies or `try` blocks. If a context spans a `yield` or `await`, other code
|
|
160
|
+
running on that thread can have its imports deferred according to its own
|
|
161
|
+
module's declaration. Entering a context doesn't enable the fallback on other
|
|
162
|
+
threads. Nested contexts keep it active until the outermost context exits.
|
|
163
|
+
|
|
164
|
+
Native controls and filtering, `sys.lazy_modules`, and exception chaining back
|
|
165
|
+
to the import declaration are not provided on older runtimes.
|
|
166
|
+
|
|
167
|
+
While active, the fallback temporarily replaces `builtins.__import__` and
|
|
168
|
+
preserves any pre-existing hook. Code that replaces the same hook during a
|
|
169
|
+
context can interfere with lazy selection; if that happens, exiting the context
|
|
170
|
+
leaves the replacement in place. No proxy is inserted into `sys.modules`.
|
|
171
|
+
|
|
172
|
+
The package has no runtime dependencies. See [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
173
|
+
for testing and build instructions.
|
|
174
|
+
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: linkify-it-py
|
|
3
|
+
Version: 2.2.0
|
|
4
|
+
Summary: Links recognition library with FULL unicode support.
|
|
5
|
+
Author: tsutsu3
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/tsutsu3/linkify-it-py
|
|
8
|
+
Keywords: linkify,linkifier,autolink,autolinker
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Intended Audience :: Developers
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: pytest; extra == "test"
|
|
25
|
+
Requires-Dist: coverage; extra == "test"
|
|
26
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
27
|
+
Requires-Dist: pytest-timeout; extra == "test"
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
30
|
+
Requires-Dist: isort; extra == "dev"
|
|
31
|
+
Requires-Dist: flake8; extra == "dev"
|
|
32
|
+
Requires-Dist: black; extra == "dev"
|
|
33
|
+
Requires-Dist: pyproject-flake8; extra == "dev"
|
|
34
|
+
Provides-Extra: benchmark
|
|
35
|
+
Requires-Dist: pytest; extra == "benchmark"
|
|
36
|
+
Requires-Dist: pytest-benchmark; extra == "benchmark"
|
|
37
|
+
Provides-Extra: doc
|
|
38
|
+
Requires-Dist: sphinx; extra == "doc"
|
|
39
|
+
Requires-Dist: sphinx_book_theme; extra == "doc"
|
|
40
|
+
Requires-Dist: myst-parser; extra == "doc"
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
|
|
43
|
+
# linkify-it-py
|
|
44
|
+
|
|
45
|
+
[](https://github.com/tsutsu3/linkify-it-py/actions/workflows/github-ci.yml)
|
|
46
|
+
[](https://pypi.org/project/linkify-it-py/)
|
|
47
|
+
[](https://anaconda.org/conda-forge/linkify-it-py)
|
|
48
|
+
[](https://linkify-it-py.readthedocs.io/en/latest/?badge=latest)
|
|
49
|
+
[](https://codecov.io/gh/tsutsu3/linkify-it-py)
|
|
50
|
+
|
|
51
|
+
This is Python port of [linkify-it](https://github.com/markdown-it/linkify-it).
|
|
52
|
+
|
|
53
|
+
> Links recognition library with FULL unicode support.
|
|
54
|
+
> Focused on high quality link patterns detection in plain text.
|
|
55
|
+
|
|
56
|
+
__[Demo](https://linkify-it-py-demo.vercel.app/)__
|
|
57
|
+
|
|
58
|
+
__[Javascript Demo](http://markdown-it.github.io/linkify-it/)__
|
|
59
|
+
|
|
60
|
+
Why it's awesome:
|
|
61
|
+
|
|
62
|
+
- Full unicode support, _with astral characters_!
|
|
63
|
+
- International domains support.
|
|
64
|
+
- Allows rules extension & custom normalizers.
|
|
65
|
+
|
|
66
|
+
## Python Version Support
|
|
67
|
+
|
|
68
|
+
Tested on Python 3.10–3.14. The primary version for code coverage follows the latest
|
|
69
|
+
[security phase](https://devguide.python.org/versions/) release (currently __3.12__).
|
|
70
|
+
|
|
71
|
+
## Install
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install linkify-it-py
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
or
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
conda install -c conda-forge linkify-it-py
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Usage examples
|
|
84
|
+
|
|
85
|
+
### Example 1. Simple use
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from linkify_it import LinkifyIt
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
linkify = LinkifyIt()
|
|
92
|
+
|
|
93
|
+
print(linkify.test("Site github.com!"))
|
|
94
|
+
# => True
|
|
95
|
+
|
|
96
|
+
print(linkify.match("Site github.com!"))
|
|
97
|
+
# => [linkify_it.main.Match({
|
|
98
|
+
# 'schema': '',
|
|
99
|
+
# 'index': 5,
|
|
100
|
+
# 'last_index': 15,
|
|
101
|
+
# 'raw': 'github.com',
|
|
102
|
+
# 'text': 'github.com',
|
|
103
|
+
# 'url': 'http://github.com'
|
|
104
|
+
# }]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Example 2. With options
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from linkify_it import LinkifyIt
|
|
111
|
+
from linkify_it.tlds import TLDS
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
# Reload full tlds list & add unofficial `.onion` domain.
|
|
115
|
+
linkify = (
|
|
116
|
+
LinkifyIt()
|
|
117
|
+
.tlds(TLDS) # Reload with full tlds list
|
|
118
|
+
.tlds("onion", True) # Add unofficial `.onion` domain
|
|
119
|
+
.add("git:", "http:") # Add `git:` protocol as "alias"
|
|
120
|
+
.add("ftp:", None) # Disable `ftp:` protocol
|
|
121
|
+
.set({"fuzzy_ip": True}) # Enable IPs in fuzzy links (without schema)
|
|
122
|
+
)
|
|
123
|
+
print(linkify.test("Site tamanegi.onion!"))
|
|
124
|
+
# => True
|
|
125
|
+
|
|
126
|
+
print(linkify.match("Site tamanegi.onion!"))
|
|
127
|
+
# => [linkify_it.main.Match({
|
|
128
|
+
# 'schema': '',
|
|
129
|
+
# 'index': 5,
|
|
130
|
+
# 'last_index': 19,
|
|
131
|
+
# 'raw': 'tamanegi.onion',
|
|
132
|
+
# 'text': 'tamanegi.onion',
|
|
133
|
+
# 'url': 'http://tamanegi.onion'
|
|
134
|
+
# }]
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Example 3. Add twitter mentions handler
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from linkify_it import LinkifyIt
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
linkify = LinkifyIt()
|
|
144
|
+
|
|
145
|
+
def validate(obj, text, pos):
|
|
146
|
+
tail = text[pos:]
|
|
147
|
+
|
|
148
|
+
if not obj.re.get("twitter"):
|
|
149
|
+
obj.re["twitter"] = re.compile(
|
|
150
|
+
"^([a-zA-Z0-9_]){1,15}(?!_)(?=$|" + obj.re["src_ZPCc"] + ")"
|
|
151
|
+
)
|
|
152
|
+
if obj.re["twitter"].search(tail):
|
|
153
|
+
if pos > 2 and tail[pos - 2] == "@":
|
|
154
|
+
return False
|
|
155
|
+
return len(obj.re["twitter"].search(tail).group())
|
|
156
|
+
return 0
|
|
157
|
+
|
|
158
|
+
def normalize(obj, match):
|
|
159
|
+
match.url = "https://twitter.com/" + re.sub(r"^@", "", match.url)
|
|
160
|
+
|
|
161
|
+
linkify.add("@", {"validate": validate, "normalize": normalize})
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## API
|
|
165
|
+
|
|
166
|
+
[API documentation](https://linkify-it-py.readthedocs.io/en/latest/)
|
|
167
|
+
|
|
168
|
+
### LinkifyIt(schemas, options)
|
|
169
|
+
|
|
170
|
+
Creates new linkifier instance with optional additional schemas.
|
|
171
|
+
|
|
172
|
+
By default understands:
|
|
173
|
+
|
|
174
|
+
- `http(s)://...` , `ftp://...`, `mailto:...` & `//...` links
|
|
175
|
+
- "fuzzy" links and emails (google.com, foo@bar.com).
|
|
176
|
+
|
|
177
|
+
`schemas` is an dict, where each key/value describes protocol/rule:
|
|
178
|
+
|
|
179
|
+
- __key__ - link prefix (usually, protocol name with `:` at the end, `skype:`
|
|
180
|
+
for example). `linkify-it-py` makes sure that prefix is not preceded with
|
|
181
|
+
alphanumeric char.
|
|
182
|
+
- __value__ - rule to check tail after link prefix
|
|
183
|
+
- _str_
|
|
184
|
+
- just alias to existing rule
|
|
185
|
+
- _dict_
|
|
186
|
+
- _validate_ - either a `re.Pattern` (start with `^`, and don't include the
|
|
187
|
+
link prefix itself), or a validator `function` which, given arguments
|
|
188
|
+
_self_, _text_ and _pos_, returns the length of a match in _text_
|
|
189
|
+
starting at index _pos_. _pos_ is the index right after the link prefix.
|
|
190
|
+
_self_ can be used to access the linkify object to cache data.
|
|
191
|
+
- _normalize_ - optional function to normalize text & url of matched result
|
|
192
|
+
(for example, for twitter mentions).
|
|
193
|
+
|
|
194
|
+
`options`:
|
|
195
|
+
|
|
196
|
+
- __fuzzy_link__ - recognize URL-s without `http(s)://` head. Default `True`.
|
|
197
|
+
- __fuzzy_ip__ - allow IPs in fuzzy links above. Can conflict with some texts
|
|
198
|
+
like version numbers. Default `False`.
|
|
199
|
+
- __fuzzy_email__ - recognize emails without `mailto:` prefix. Default `True`.
|
|
200
|
+
- __---__ - set `True` to terminate link with `---` (if it's considered as long dash).
|
|
201
|
+
|
|
202
|
+
### .test(text)
|
|
203
|
+
|
|
204
|
+
Searches linkifiable pattern and returns `True` on success or `False` on fail.
|
|
205
|
+
|
|
206
|
+
### .pretest(text)
|
|
207
|
+
|
|
208
|
+
Quick check if link MAY BE can exist. Can be used to optimize more expensive
|
|
209
|
+
`.test()` calls. Return `False` if link can not be found, `True` - if `.test()`
|
|
210
|
+
call needed to know exactly.
|
|
211
|
+
|
|
212
|
+
### .test_schema_at(text, name, position)
|
|
213
|
+
|
|
214
|
+
Similar to `.test()` but checks only specific protocol tail exactly at given
|
|
215
|
+
position. Returns length of found pattern (0 on fail).
|
|
216
|
+
|
|
217
|
+
### .match(text)
|
|
218
|
+
|
|
219
|
+
Returns `list` of found link matches or null if nothing found.
|
|
220
|
+
|
|
221
|
+
Each match has:
|
|
222
|
+
|
|
223
|
+
- __schema__ - link schema, can be empty for fuzzy links, or `//` for
|
|
224
|
+
protocol-neutral links.
|
|
225
|
+
- __index__ - offset of matched text
|
|
226
|
+
- __last_index__ - index of next char after mathch end
|
|
227
|
+
- __raw__ - matched text
|
|
228
|
+
- __text__ - normalized text
|
|
229
|
+
- __url__ - link, generated from matched text
|
|
230
|
+
|
|
231
|
+
### .matchAtStart(text)
|
|
232
|
+
|
|
233
|
+
Checks if a match exists at the start of the string. Returns `Match`
|
|
234
|
+
(see docs for `match(text)`) or null if no URL is at the start.
|
|
235
|
+
Doesn't work with fuzzy links.
|
|
236
|
+
|
|
237
|
+
### .tlds(list_tlds, keep_old=False)
|
|
238
|
+
|
|
239
|
+
Load (or merge) new tlds list. Those are needed for fuzzy links (without schema)
|
|
240
|
+
to avoid false positives. By default:
|
|
241
|
+
|
|
242
|
+
- 2-letter root zones are ok.
|
|
243
|
+
- biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф are ok.
|
|
244
|
+
- encoded (`xn--...`) root zones are ok.
|
|
245
|
+
|
|
246
|
+
If that's not enough, you can reload defaults with more detailed zones list.
|
|
247
|
+
|
|
248
|
+
### .add(key, value)
|
|
249
|
+
|
|
250
|
+
Add a new schema to the schemas object. As described in the constructor
|
|
251
|
+
definition, `key` is a link prefix (`skype:`, for example), and `value`
|
|
252
|
+
is a `str` to alias to another schema, or an `dict` with `validate` and
|
|
253
|
+
optionally `normalize` definitions. To disable an existing rule, use
|
|
254
|
+
`.add(key, None)`.
|
|
255
|
+
|
|
256
|
+
### .set(options)
|
|
257
|
+
|
|
258
|
+
Override default options. Missed properties will not be changed.
|
|
259
|
+
|
|
260
|
+
## License
|
|
261
|
+
|
|
262
|
+
[MIT](https://github.com/tsutsu3/linkify-it-py/blob/master/LICENSE)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 tsutsu3
|
|
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.
|
|
22
|
+
|
|
23
|
+
===============================================================================
|
|
24
|
+
|
|
25
|
+
Original Javascript version:
|
|
26
|
+
|
|
27
|
+
Copyright (c) 2015 Vitaly Puzrin.
|
|
28
|
+
|
|
29
|
+
Permission is hereby granted, free of charge, to any person
|
|
30
|
+
obtaining a copy of this software and associated documentation
|
|
31
|
+
files (the "Software"), to deal in the Software without
|
|
32
|
+
restriction, including without limitation the rights to use,
|
|
33
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
34
|
+
copies of the Software, and to permit persons to whom the
|
|
35
|
+
Software is furnished to do so, subject to the following
|
|
36
|
+
conditions:
|
|
37
|
+
|
|
38
|
+
The above copyright notice and this permission notice shall be
|
|
39
|
+
included in all copies or substantial portions of the Software.
|
|
40
|
+
|
|
41
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
42
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
43
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
44
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
45
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
46
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
47
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
48
|
+
OTHER DEALINGS IN THE SOFTWARE.
|