增加环绕侦察场景适配

This commit is contained in:
2026-01-08 15:44:38 +08:00
parent 3eba1f962b
commit 10c5bb5a8a
5441 changed files with 40219 additions and 379695 deletions

View File

@@ -35,7 +35,7 @@ from ._compat import (
NullFinder,
install,
)
from ._functools import method_cache, pass_none
from ._functools import method_cache, noop, pass_none, passthrough
from ._itertools import always_iterable, bucket, unique_everseen
from ._meta import PackageMetadata, SimplePath
from ._typing import md_none
@@ -636,7 +636,8 @@ class Distribution(metaclass=abc.ABCMeta):
return
paths = (
py311.relative_fix((subdir / name).resolve())
py311
.relative_fix((subdir / name).resolve())
.relative_to(self.locate_file('').resolve(), walk_up=True)
.as_posix()
for name in text.splitlines()
@@ -786,6 +787,20 @@ class DistributionFinder(MetaPathFinder):
"""
@passthrough
def _clear_after_fork(cached):
"""Ensure ``func`` clears cached state after ``fork`` when supported.
``FastPath`` caches zip-backed ``pathlib.Path`` objects that retain a
reference to the parent's open ``ZipFile`` handle. Re-using a cached
instance in a forked child can therefore resurrect invalid file pointers
and trigger ``BadZipFile``/``OSError`` failures (python/importlib_metadata#520).
Registering ``cache_clear`` with ``os.register_at_fork`` keeps each process
on its own cache.
"""
getattr(os, 'register_at_fork', noop)(after_in_child=cached.cache_clear)
class FastPath:
"""
Micro-optimized class for searching a root for children.
@@ -802,7 +817,8 @@ class FastPath:
True
"""
@functools.lru_cache() # type: ignore[misc]
@_clear_after_fork # type: ignore[misc]
@functools.lru_cache()
def __new__(cls, root):
return super().__new__(cls)

View File

@@ -9,7 +9,8 @@ from ._text import FoldedCase
class RawPolicy(email.policy.EmailPolicy):
def fold(self, name, value):
folded = self.linesep.join(
textwrap.indent(value, prefix=' ' * 8, predicate=lambda line: True)
textwrap
.indent(value, prefix=' ' * 8, predicate=lambda line: True)
.lstrip()
.splitlines()
)

View File

@@ -1,5 +1,6 @@
import functools
import types
from typing import Callable, TypeVar
# from jaraco.functools 3.3
@@ -102,3 +103,33 @@ def pass_none(func):
return func(param, *args, **kwargs)
return wrapper
# From jaraco.functools 4.4
def noop(*args, **kwargs):
"""
A no-operation function that does nothing.
>>> noop(1, 2, three=3)
"""
_T = TypeVar('_T')
# From jaraco.functools 4.4
def passthrough(func: Callable[..., object]) -> Callable[[_T], _T]:
"""
Wrap the function to always return the first parameter.
>>> passthrough(print)('3')
3
'3'
"""
@functools.wraps(func)
def wrapper(first: _T, *args, **kwargs) -> _T:
func(first, *args, **kwargs)
return first
return wrapper # type: ignore[return-value]