晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。   林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。   见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝)   既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。   南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。 sh-3ll

HOME


sh-3ll 1.0
DIR:/opt/cloudlinux/venv/lib/python3.11/site-packages/pyfakefs/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/pyfakefs/fake_legacy_modules.py
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import warnings


from pyfakefs.fake_pathlib import FakePathlibModule
from pyfakefs.fake_scandir import scandir, walk


def legacy_warning(module_name):
    msg = (
        f"You are using the legacy package '{module_name}' instead of the "
        f"built-in module."
        "Patching this package will no longer be supported in pyfakefs >= 6"
    )
    warnings.warn(msg, category=DeprecationWarning)


class FakePathlib2Module(FakePathlibModule):
    """Uses FakeFilesystem to provide a fake pathlib module replacement.
    for the `pathlib2` package available on PyPi.
    The usage of `pathlib2` is deprecated and will no longer be supported
    in future pyfakefs versions.
    """

    has_warned = False

    def __getattribute__(self, name):
        attr = object.__getattribute__(self, name)
        if hasattr(attr, "__call__") and not FakePathlib2Module.has_warned:
            FakePathlib2Module.has_warned = True
            legacy_warning("pathlib2")
        return attr


class FakeScanDirModule:
    """Uses FakeFilesystem to provide a fake module replacement
    for the `scandir` package available on PyPi.

    The usage of the `scandir` package is deprecated and will no longer be supported
    in future pyfakefs versions.

    You need a fake_filesystem to use this:
    `filesystem = fake_filesystem.FakeFilesystem()`
    `fake_scandir_module = fake_filesystem.FakeScanDirModule(filesystem)`
    """

    @staticmethod
    def dir():
        """Return the list of patched function names. Used for patching
        functions imported from the module.
        """
        return "scandir", "walk"

    def __init__(self, filesystem):
        self.filesystem = filesystem

    has_warned = False

    def scandir(self, path="."):
        """Return an iterator of DirEntry objects corresponding to the entries
        in the directory given by path.

        Args:
            path: Path to the target directory within the fake filesystem.

        Returns:
            an iterator to an unsorted list of os.DirEntry objects for
            each entry in path.

        Raises:
            OSError: if the target is not a directory.
        """
        if not self.has_warned:
            self.__class__.has_warned = True
            legacy_warning("scandir")
        return scandir(self.filesystem, path)

    def walk(self, top, topdown=True, onerror=None, followlinks=False):
        """Perform a walk operation over the fake filesystem.

        Args:
            top: The root directory from which to begin walk.
            topdown: Determines whether to return the tuples with the root as
                the first entry (`True`) or as the last, after all the child
                directory tuples (`False`).
            onerror: If not `None`, function which will be called to handle the
                `os.error` instance provided when `os.listdir()` fails.
            followlinks: If `True`, symbolic links are followed.

        Yields:
            (path, directories, nondirectories) for top and each of its
            subdirectories.  See the documentation for the builtin os module
            for further details.
        """
        if not self.has_warned:
            self.__class__.has_warned = True
            legacy_warning("scandir")

        return walk(self.filesystem, top, topdown, onerror, followlinks)