当前位置: 首页>>代码示例>>Python>>正文


Python pkg_resources.ResourceManager方法代码示例

本文整理汇总了Python中pkg_resources.ResourceManager方法的典型用法代码示例。如果您正苦于以下问题:Python pkg_resources.ResourceManager方法的具体用法?Python pkg_resources.ResourceManager怎么用?Python pkg_resources.ResourceManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pkg_resources的用法示例。


在下文中一共展示了pkg_resources.ResourceManager方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_resource_filename_rewrites_on_change

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import ResourceManager [as 别名]
def test_resource_filename_rewrites_on_change(self):
        """
        If a previous call to get_resource_filename has saved the file, but
        the file has been subsequently mutated with different file of the
        same size and modification time, it should not be overwritten on a
        subsequent call to get_resource_filename.
        """
        import mod
        manager = pkg_resources.ResourceManager()
        zp = pkg_resources.ZipProvider(mod)
        filename = zp.get_resource_filename(manager, 'data.dat')
        actual = datetime.datetime.fromtimestamp(os.stat(filename).st_mtime)
        assert actual == self.ref_time
        f = open(filename, 'w')
        f.write('hello, world?')
        f.close()
        ts = timestamp(self.ref_time)
        os.utime(filename, (ts, ts))
        filename = zp.get_resource_filename(manager, 'data.dat')
        with open(filename) as f:
            assert f.read() == 'hello, world!'
        manager.cleanup_resources() 
开发者ID:pypa,项目名称:pkg_resources,代码行数:24,代码来源:test_pkg_resources.py

示例2: test_resource_filename_rewrites_on_change

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import ResourceManager [as 别名]
def test_resource_filename_rewrites_on_change(self):
        """
        If a previous call to get_resource_filename has saved the file, but
        the file has been subsequently mutated with different file of the
        same size and modification time, it should not be overwritten on a
        subsequent call to get_resource_filename.
        """
        import mod
        manager = pkg_resources.ResourceManager()
        zp = pkg_resources.ZipProvider(mod)
        filename = zp.get_resource_filename(manager, 'data.dat')
        actual = datetime.datetime.fromtimestamp(os.stat(filename).st_mtime)
        assert actual == self.ref_time
        f = open(filename, 'w')
        f.write('hello, world?')
        f.close()
        ts = timestamp(self.ref_time)
        os.utime(filename, (ts, ts))
        filename = zp.get_resource_filename(manager, 'data.dat')
        f = open(filename)
        assert f.read() == 'hello, world!'
        manager.cleanup_resources() 
开发者ID:francelabs,项目名称:datafari,代码行数:24,代码来源:test_pkg_resources.py

示例3: get_package_loader

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import ResourceManager [as 别名]
def get_package_loader(self, package, package_path):
        from pkg_resources import DefaultProvider, ResourceManager, get_provider

        loadtime = datetime.utcnow()
        provider = get_provider(package)
        manager = ResourceManager()
        filesystem_bound = isinstance(provider, DefaultProvider)

        def loader(path):
            if path is None:
                return None, None

            path = posixpath.join(package_path, path)

            if not provider.has_resource(path):
                return None, None

            basename = posixpath.basename(path)

            if filesystem_bound:
                return (
                    basename,
                    self._opener(provider.get_resource_filename(manager, path)),
                )

            s = provider.get_resource_string(manager, path)
            return basename, lambda: (BytesIO(s), loadtime, len(s))

        return loader 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:31,代码来源:shared_data.py

示例4: __init__

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import ResourceManager [as 别名]
def __init__(self, egg_or_spec, resource_name, manager=None, root_resource=None):
        if pkg_resources is None:
            raise NotImplementedError("This class requires pkg_resources.")
        if isinstance(egg_or_spec, (str, unicode)):
            self.egg = pkg_resources.get_distribution(egg_or_spec)
        else:
            self.egg = egg_or_spec
        self.resource_name = resource_name
        if manager is None:
            manager = pkg_resources.ResourceManager()
        self.manager = manager
        if root_resource is None:
            root_resource = resource_name
        self.root_resource = os.path.normpath(root_resource) 
开发者ID:linuxscout,项目名称:mishkal,代码行数:16,代码来源:urlparser.py

示例5: test_get_cache_path

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import ResourceManager [as 别名]
def test_get_cache_path(self):
        mgr = pkg_resources.ResourceManager()
        path = mgr.get_cache_path('foo')
        type_ = str(type(path))
        message = "Unexpected type from get_cache_path: " + type_
        assert isinstance(path, (unicode, str)), message 
开发者ID:pypa,项目名称:pkg_resources,代码行数:8,代码来源:test_pkg_resources.py

示例6: __init__

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import ResourceManager [as 别名]
def __init__(self, package_name, package_path="templates", encoding="utf-8"):
        from pkg_resources import DefaultProvider
        from pkg_resources import get_provider
        from pkg_resources import ResourceManager

        provider = get_provider(package_name)
        self.encoding = encoding
        self.manager = ResourceManager()
        self.filesystem_bound = isinstance(provider, DefaultProvider)
        self.provider = provider
        self.package_path = package_path 
开发者ID:pypa,项目名称:pipenv,代码行数:13,代码来源:loaders.py

示例7: installed_location

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import ResourceManager [as 别名]
def installed_location(filename):
    """
    Returns the full path for the given installed file or None if not found.

    :param filename: The filename to search for.
    :returns: The absolute filepath for the file or None if not installed.
    """
    try:
        return ResourceManager().resource_filename(Requirement.parse("websnort"), filename)
    except DistributionNotFound:
        return None 
开发者ID:shendo,项目名称:websnort,代码行数:13,代码来源:config.py

示例8: test_get_cache_path

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import ResourceManager [as 别名]
def test_get_cache_path(self):
        mgr = pkg_resources.ResourceManager()
        path = mgr.get_cache_path('foo')
        type_ = str(type(path))
        message = "Unexpected type from get_cache_path: " + type_
        assert isinstance(path, string_types), message 
开发者ID:pypa,项目名称:setuptools,代码行数:8,代码来源:test_pkg_resources.py

示例9: test_get_cache_path_race

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import ResourceManager [as 别名]
def test_get_cache_path_race(self, tmpdir):
        # Patch to os.path.isdir to create a race condition
        def patched_isdir(dirname, unpatched_isdir=pkg_resources.isdir):
            patched_isdir.dirnames.append(dirname)

            was_dir = unpatched_isdir(dirname)
            if not was_dir:
                os.makedirs(dirname)
            return was_dir

        patched_isdir.dirnames = []

        # Get a cache path with a "race condition"
        mgr = pkg_resources.ResourceManager()
        mgr.set_extraction_path(str(tmpdir))

        archive_name = os.sep.join(('foo', 'bar', 'baz'))
        with mock.patch.object(pkg_resources, 'isdir', new=patched_isdir):
            mgr.get_cache_path(archive_name)

        # Because this test relies on the implementation details of this
        # function, these assertions are a sentinel to ensure that the
        # test suite will not fail silently if the implementation changes.
        called_dirnames = patched_isdir.dirnames
        assert len(called_dirnames) == 2
        assert called_dirnames[0].split(os.sep)[-2:] == ['foo', 'bar']
        assert called_dirnames[1].split(os.sep)[-1:] == ['foo'] 
开发者ID:pypa,项目名称:setuptools,代码行数:29,代码来源:test_pkg_resources.py


注:本文中的pkg_resources.ResourceManager方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。