當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。