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


Python zipfile.namelist方法代码示例

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


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

示例1: __init__

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import namelist [as 别名]
def __init__(self, zipfile, entry=''):
        """
        Create a new path pointer pointing at the specified entry
        in the given zipfile.

        :raise IOError: If the given zipfile does not exist, or if it
        does not contain the specified entry.
        """
        if isinstance(zipfile, string_types):
            zipfile = OpenOnDemandZipFile(os.path.abspath(zipfile))

        # Normalize the entry string, it should be relative:
        entry = normalize_resource_name(entry, True, '/').lstrip('/')

        # Check that the entry exists:
        if entry:
            try:
                zipfile.getinfo(entry)
            except Exception:
                # Sometimes directories aren't explicitly listed in
                # the zip file.  So if `entry` is a directory name,
                # then check if the zipfile contains any files that
                # are under the given directory.
                if (entry.endswith('/') and
                        [n for n in zipfile.namelist() if n.startswith(entry)]):
                    pass  # zipfile contains a file in that directory.
                else:
                    # Otherwise, complain.
                    raise IOError('Zipfile %r does not contain %r' %
                                  (zipfile.filename, entry))
        self._zipfile = zipfile
        self._entry = entry 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:34,代码来源:data.py

示例2: get_original_crash_test_case_of_zipfile

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import namelist [as 别名]
def get_original_crash_test_case_of_zipfile(crash_test_case, original_test_case):
    import zipfile
    zipfile = zipfile.ZipFile(io.BytesIO(original_test_case))
    max_similarity = 0
    for name in zipfile.namelist():
        possible_original_test_case = zipfile.read(name)
        similarity = SequenceMatcher(None, base64.b64encode(possible_original_test_case),
                                     base64.b64encode(crash_test_case)).ratio()
        if similarity > max_similarity:
            max_similarity = similarity
            original_test_case = possible_original_test_case
    return original_test_case 
开发者ID:fkie-cad,项目名称:LuckyCAT,代码行数:14,代码来源:Crashes.py

示例3: test_build

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import namelist [as 别名]
def test_build(self):
        builder = Builder('test.zip')
        builder._runtime = RUNTIME_NODE_JS
        ok_(hasattr(builder.build(), 'read'))
        with PyZipFile(builder._zippath, 'r', compression=ZIP_DEFLATED) as zipfile:
            ok_('lambda_function.pyc' in zipfile.namelist())
            ok_('.lamvery_secret.json' in zipfile.namelist()) 
开发者ID:marcy-terui,项目名称:lamvery,代码行数:9,代码来源:build_test.py

示例4: test_build_with_single_file

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import namelist [as 别名]
def test_build_with_single_file(self):
        builder = Builder('test.zip', function_filename='lambda_function.py', single_file=True)
        builder.build()
        with PyZipFile(builder._zippath, 'r', compression=ZIP_DEFLATED) as zipfile:
            ok_('lambda_function.py' in zipfile.namelist())
            ok_(not ('.lamvery_secret.json' in zipfile.namelist())) 
开发者ID:marcy-terui,项目名称:lamvery,代码行数:8,代码来源:build_test.py

示例5: __init__

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import namelist [as 别名]
def __init__(self, zipfile, entry=''):
        """
        Create a new path pointer pointing at the specified entry
        in the given zipfile.

        :raise IOError: If the given zipfile does not exist, or if it
        does not contain the specified entry.
        """
        if isinstance(zipfile, basestring):
            zipfile = OpenOnDemandZipFile(os.path.abspath(zipfile))

        # Normalize the entry string:
        entry = re.sub('(^|/)/+', r'\1', entry)

        # Check that the entry exists:
        if entry:
            try: zipfile.getinfo(entry)
            except:
                # Sometimes directories aren't explicitly listed in
                # the zip file.  So if `entry` is a directory name,
                # then check if the zipfile contains any files that
                # are under the given directory.
                if (entry.endswith('/') and
                    [n for n in zipfile.namelist() if n.startswith(entry)]):
                    pass # zipfile contains a file in that directory.
                else:
                    # Otherwise, complain.
                    raise IOError('Zipfile %r does not contain %r' %
                                  (zipfile.filename, entry))
        self._zipfile = zipfile
        self._entry = entry 
开发者ID:blackye,项目名称:luscan-devel,代码行数:33,代码来源:data.py

示例6: __init__

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import namelist [as 别名]
def __init__(self, zipfile, entry=''):
        """
        Create a new path pointer pointing at the specified entry
        in the given zipfile.

        :raise IOError: If the given zipfile does not exist, or if it
        does not contain the specified entry.
        """
        if isinstance(zipfile, string_types):
            zipfile = OpenOnDemandZipFile(os.path.abspath(zipfile))

        # Check that the entry exists:
        if entry:

            # Normalize the entry string, it should be relative:
            entry = normalize_resource_name(entry, True, '/').lstrip('/')

            try:
                zipfile.getinfo(entry)
            except Exception:
                # Sometimes directories aren't explicitly listed in
                # the zip file.  So if `entry` is a directory name,
                # then check if the zipfile contains any files that
                # are under the given directory.
                if entry.endswith('/') and [
                    n for n in zipfile.namelist() if n.startswith(entry)
                ]:
                    pass  # zipfile contains a file in that directory.
                else:
                    # Otherwise, complain.
                    raise IOError(
                        'Zipfile %r does not contain %r' % (zipfile.filename, entry)
                    )
        self._zipfile = zipfile
        self._entry = entry 
开发者ID:V1EngineeringInc,项目名称:V1EngineeringInc-Docs,代码行数:37,代码来源:data.py

示例7: _analyze_zipfile_for_import

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import namelist [as 别名]
def _analyze_zipfile_for_import(zipfile, project, schema):
    names = zipfile.namelist()

    def read_sp_manifest_file(path):
        # Must use forward slashes, not os.path.sep.
        fn_manifest = path + '/' + project.Job.FN_MANIFEST
        if fn_manifest in names:
            return json.loads(zipfile.read(fn_manifest).decode())

    if schema is None:
        schema_function = read_sp_manifest_file
    elif callable(schema):
        schema_function = _with_consistency_check(schema, read_sp_manifest_file)
    elif isinstance(schema, str):
        schema_function = _with_consistency_check(
            _make_path_based_schema_function(schema), read_sp_manifest_file)
    else:
        raise TypeError("The schema variable must be None, callable, or a string.")

    mappings = dict()
    skip_subdirs = set()

    dirs = {os.path.dirname(name) for name in names}
    for name in sorted(dirs):
        cont = False
        for skip in skip_subdirs:
            if name.startswith(skip):
                cont = True
                break
        if cont:
            continue

        sp = schema_function(name)
        if sp is not None:
            job = project.open_job(sp)
            if os.path.exists(job.workspace()):
                raise DestinationExistsError(job)
            mappings[name] = job
            skip_subdirs.add(name)

    # Check uniqueness
    if len(set(mappings.values())) != len(mappings):
        raise RuntimeError("The jobs identified with the given schema function are not unique!")

    for path, job in mappings.items():
        _names = [name for name in names if name.startswith(path)]
        yield path, _CopyFromZipFileExecutor(zipfile, path, job, _names) 
开发者ID:glotzerlab,项目名称:signac,代码行数:49,代码来源:import_export.py


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