當前位置: 首頁>>代碼示例>>Python>>正文


Python zipimport.zipimporter方法代碼示例

本文整理匯總了Python中zipimport.zipimporter方法的典型用法代碼示例。如果您正苦於以下問題:Python zipimport.zipimporter方法的具體用法?Python zipimport.zipimporter怎麽用?Python zipimport.zipimporter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在zipimport的用法示例。


在下文中一共展示了zipimport.zipimporter方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: zip_import_data

# 需要導入模塊: import zipimport [as 別名]
# 或者: from zipimport import zipimporter [as 別名]
def zip_import_data(self, filepath):
        if zipimport is None:
            return None
        from astroid.builder import AstroidBuilder
        builder = AstroidBuilder(self)
        for ext in ('.zip', '.egg'):
            try:
                eggpath, resource = filepath.rsplit(ext + os.path.sep, 1)
            except ValueError:
                continue
            try:
                importer = zipimport.zipimporter(eggpath + ext)
                zmodname = resource.replace(os.path.sep, '.')
                if importer.is_package(resource):
                    zmodname = zmodname + '.__init__'
                module = builder.string_build(importer.get_source(resource),
                                              zmodname, filepath)
                return module
            except Exception: # pylint: disable=broad-except
                continue
        return None 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:23,代碼來源:manager.py

示例2: _precache_zipimporters

# 需要導入模塊: import zipimport [as 別名]
# 或者: from zipimport import zipimporter [as 別名]
def _precache_zipimporters(path=None):
    pic = sys.path_importer_cache

    # When measured, despite having the same complexity (O(n)),
    # converting to tuples and then caching the conversion to sets
    # and the set difference is faster than converting to sets
    # and then only caching the set difference.

    req_paths = tuple(path or sys.path)
    cached_paths = tuple(pic)
    new_paths = _cached_set_diff(req_paths, cached_paths)
    for entry_path in new_paths:
        try:
            pic[entry_path] = zipimport.zipimporter(entry_path)
        except zipimport.ZipImportError:
            continue
    return pic 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:19,代碼來源:spec.py

示例3: find_eggs_in_zip

# 需要導入模塊: import zipimport [as 別名]
# 或者: from zipimport import zipimporter [as 別名]
def find_eggs_in_zip(importer, path_item, only=False):
    """
    Find eggs in zip files; possibly multiple nested eggs.
    """
    if importer.archive.endswith('.whl'):
        # wheels are not supported with this finder
        # they don't have PKG-INFO metadata, and won't ever contain eggs
        return
    metadata = EggMetadata(importer)
    if metadata.has_metadata('PKG-INFO'):
        yield Distribution.from_filename(path_item, metadata=metadata)
    if only:
        # don't yield nested distros
        return
    for subitem in metadata.resource_listdir('/'):
        if _is_unpacked_egg(subitem):
            subpath = os.path.join(path_item, subitem)
            for dist in find_eggs_in_zip(zipimport.zipimporter(subpath), subpath):
                yield dist 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:21,代碼來源:__init__.py

示例4: _collect_zipimporter_cache_entries

# 需要導入模塊: import zipimport [as 別名]
# 或者: from zipimport import zipimporter [as 別名]
def _collect_zipimporter_cache_entries(normalized_path, cache):
    """
    Return zipimporter cache entry keys related to a given normalized path.

    Alternative path spellings (e.g. those using different character case or
    those using alternative path separators) related to the same path are
    included. Any sub-path entries are included as well, i.e. those
    corresponding to zip archives embedded in other zip archives.

    """
    result = []
    prefix_len = len(normalized_path)
    for p in cache:
        np = normalize_path(p)
        if (np.startswith(normalized_path) and
                np[prefix_len:prefix_len + 1] in (os.sep, '')):
            result.append(p)
    return result 
開發者ID:jpush,項目名稱:jbox,代碼行數:20,代碼來源:easy_install.py

示例5: _remove_and_clear_zip_directory_cache_data

# 需要導入模塊: import zipimport [as 別名]
# 或者: from zipimport import zipimporter [as 別名]
def _remove_and_clear_zip_directory_cache_data(normalized_path):
    def clear_and_remove_cached_zip_archive_directory_data(path, old_entry):
        old_entry.clear()

    _update_zipimporter_cache(
        normalized_path, zipimport._zip_directory_cache,
        updater=clear_and_remove_cached_zip_archive_directory_data)

# PyPy Python implementation does not allow directly writing to the
# zipimport._zip_directory_cache and so prevents us from attempting to correct
# its content. The best we can do there is clear the problematic cache content
# and have PyPy repopulate it as needed. The downside is that if there are any
# stale zipimport.zipimporter instances laying around, attempting to use them
# will fail due to not having its zip archive directory information available
# instead of being automatically corrected to use the new correct zip archive
# directory information. 
開發者ID:jpush,項目名稱:jbox,代碼行數:18,代碼來源:easy_install.py

示例6: _replace_zip_directory_cache_data

# 需要導入模塊: import zipimport [as 別名]
# 或者: from zipimport import zipimporter [as 別名]
def _replace_zip_directory_cache_data(normalized_path):
        def replace_cached_zip_archive_directory_data(path, old_entry):
            # N.B. In theory, we could load the zip directory information just
            # once for all updated path spellings, and then copy it locally and
            # update its contained path strings to contain the correct
            # spelling, but that seems like a way too invasive move (this cache
            # structure is not officially documented anywhere and could in
            # theory change with new Python releases) for no significant
            # benefit.
            old_entry.clear()
            zipimport.zipimporter(path)
            old_entry.update(zipimport._zip_directory_cache[path])
            return old_entry

        _update_zipimporter_cache(
            normalized_path, zipimport._zip_directory_cache,
            updater=replace_cached_zip_archive_directory_data) 
開發者ID:jpush,項目名稱:jbox,代碼行數:19,代碼來源:easy_install.py

示例7: zip_import_data

# 需要導入模塊: import zipimport [as 別名]
# 或者: from zipimport import zipimporter [as 別名]
def zip_import_data(self, filepath):
        if zipimport is None:
            return None
        from astroid.builder import AstroidBuilder

        builder = AstroidBuilder(self)
        for ext in (".zip", ".egg"):
            try:
                eggpath, resource = filepath.rsplit(ext + os.path.sep, 1)
            except ValueError:
                continue
            try:
                importer = zipimport.zipimporter(eggpath + ext)
                zmodname = resource.replace(os.path.sep, ".")
                if importer.is_package(resource):
                    zmodname = zmodname + ".__init__"
                module = builder.string_build(
                    importer.get_source(resource), zmodname, filepath
                )
                return module
            except Exception:  # pylint: disable=broad-except
                continue
        return None 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:25,代碼來源:manager.py

示例8: _remove_and_clear_zip_directory_cache_data

# 需要導入模塊: import zipimport [as 別名]
# 或者: from zipimport import zipimporter [as 別名]
def _remove_and_clear_zip_directory_cache_data(normalized_path):
    def clear_and_remove_cached_zip_archive_directory_data(path, old_entry):
        old_entry.clear()

    _update_zipimporter_cache(
        normalized_path, zipimport._zip_directory_cache,
        updater=clear_and_remove_cached_zip_archive_directory_data)


# PyPy Python implementation does not allow directly writing to the
# zipimport._zip_directory_cache and so prevents us from attempting to correct
# its content. The best we can do there is clear the problematic cache content
# and have PyPy repopulate it as needed. The downside is that if there are any
# stale zipimport.zipimporter instances laying around, attempting to use them
# will fail due to not having its zip archive directory information available
# instead of being automatically corrected to use the new correct zip archive
# directory information. 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:19,代碼來源:easy_install.py

示例9: uncache_zipdir

# 需要導入模塊: import zipimport [as 別名]
# 或者: from zipimport import zipimporter [as 別名]
def uncache_zipdir(path):
    """
    Remove any globally cached zip file related data for `path`

    Stale zipimport.zipimporter objects need to be removed when a zip file is
    replaced as they contain cached zip file directory information. If they are
    asked to get data from their zip file, they will use that cached
    information to calculate the data location in the zip file. This calculated
    location may be incorrect for the replaced zip file, which may in turn
    cause the read operation to either fail or return incorrect data.

    Note we have no way to clear any local caches from here. That is left up to
    whomever is in charge of maintaining that cache.

    """
    normalized_path = normalize_path(path)
    _uncache(normalized_path, zipimport._zip_directory_cache)
    _uncache(normalized_path, sys.path_importer_cache) 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:20,代碼來源:easy_install.py

示例10: find_eggs_in_zip

# 需要導入模塊: import zipimport [as 別名]
# 或者: from zipimport import zipimporter [as 別名]
def find_eggs_in_zip(importer, path_item, only=False):
    """
    Find eggs in zip files; possibly multiple nested eggs.
    """
    if importer.archive.endswith('.whl'):
        # wheels are not supported with this finder
        # they don't have PKG-INFO metadata, and won't ever contain eggs
        return
    metadata = EggMetadata(importer)
    if metadata.has_metadata('PKG-INFO'):
        yield Distribution.from_filename(path_item, metadata=metadata)
    if only:
        # don't yield nested distros
        return
    for subitem in metadata.resource_listdir('/'):
        if subitem.endswith('.egg'):
            subpath = os.path.join(path_item, subitem)
            for dist in find_eggs_in_zip(zipimport.zipimporter(subpath), subpath):
                yield dist 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:21,代碼來源:pkg_resources.py

示例11: find_eggs_in_zip

# 需要導入模塊: import zipimport [as 別名]
# 或者: from zipimport import zipimporter [as 別名]
def find_eggs_in_zip(importer, path_item, only=False):
    """
    Find eggs in zip files; possibly multiple nested eggs.
    """
    if importer.archive.endswith('.whl'):
        # wheels are not supported with this finder
        # they don't have PKG-INFO metadata, and won't ever contain eggs
        return
    metadata = EggMetadata(importer)
    if metadata.has_metadata('PKG-INFO'):
        yield Distribution.from_filename(path_item, metadata=metadata)
    if only:
        # don't yield nested distros
        return
    for subitem in metadata.resource_listdir('/'):
        if _is_egg_path(subitem):
            subpath = os.path.join(path_item, subitem)
            dists = find_eggs_in_zip(zipimport.zipimporter(subpath), subpath)
            for dist in dists:
                yield dist
        elif subitem.lower().endswith('.dist-info'):
            subpath = os.path.join(path_item, subitem)
            submeta = EggMetadata(zipimport.zipimporter(subpath))
            submeta.egg_info = subpath
            yield Distribution.from_location(path_item, subitem, submeta) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:27,代碼來源:__init__.py

示例12: find_eggs_in_zip

# 需要導入模塊: import zipimport [as 別名]
# 或者: from zipimport import zipimporter [as 別名]
def find_eggs_in_zip(importer, path_item, only=False):
    """
    Find eggs in zip files; possibly multiple nested eggs.
    """
    if importer.archive.endswith('.whl'):
        # wheels are not supported with this finder
        # they don't have PKG-INFO metadata, and won't ever contain eggs
        return
    metadata = EggMetadata(importer)
    if metadata.has_metadata('PKG-INFO'):
        yield Distribution.from_filename(path_item, metadata=metadata)
    if only:
        # don't yield nested distros
        return
    for subitem in metadata.resource_listdir('/'):
        if _is_unpacked_egg(subitem):
            subpath = os.path.join(path_item, subitem)
            for dist in find_eggs_in_zip(zipimport.zipimporter(subpath), subpath):
                yield dist
        elif subitem.lower().endswith('.dist-info'):
            subpath = os.path.join(path_item, subitem)
            submeta = EggMetadata(zipimport.zipimporter(subpath))
            submeta.egg_info = subpath
            yield Distribution.from_location(path_item, subitem, submeta) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:26,代碼來源:__init__.py

示例13: find_eggs_in_zip

# 需要導入模塊: import zipimport [as 別名]
# 或者: from zipimport import zipimporter [as 別名]
def find_eggs_in_zip(importer, path_item, only=False):
    """
    Find eggs in zip files; possibly multiple nested eggs.
    """
    if importer.archive.endswith('.whl'):
        # wheels are not supported with this finder
        # they don't have PKG-INFO metadata, and won't ever contain eggs
        return
    metadata = EggMetadata(importer)
    if metadata.has_metadata('PKG-INFO'):
        yield Distribution.from_filename(path_item, metadata=metadata)
    if only:
        # don't yield nested distros
        return
    for subitem in metadata.resource_listdir(''):
        if _is_egg_path(subitem):
            subpath = os.path.join(path_item, subitem)
            dists = find_eggs_in_zip(zipimport.zipimporter(subpath), subpath)
            for dist in dists:
                yield dist
        elif subitem.lower().endswith('.dist-info'):
            subpath = os.path.join(path_item, subitem)
            submeta = EggMetadata(zipimport.zipimporter(subpath))
            submeta.egg_info = subpath
            yield Distribution.from_location(path_item, subitem, submeta) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,代碼來源:__init__.py


注:本文中的zipimport.zipimporter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。