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


Python rarfile.Error方法代码示例

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


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

示例1: unpack

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import Error [as 别名]
def unpack(self, file_path, temp_dir):
        # FIXME: need to figure out how to unpack multi-part files.
        try:
            with rarfile.RarFile(file_path) as rf:
                names = rf.namelist()
                encoding = self.detect_list_encoding(names)
                log.debug('Detected filename encoding: %s', encoding)

                for name in names:
                    try:
                        fh = rf.open(name)
                        self.extract_member(temp_dir, name, fh,
                                            encoding=encoding)
                    except Exception as ex:
                        # TODO: should this be a fatal error?
                        log.debug("Failed to unpack [%r]: %s", name, ex)
        except rarfile.NeedFirstVolume:
            raise ProcessingException('Cannot load splitted RAR files')
        except rarfile.Error as err:
            raise ProcessingException('Invalid RAR file: %s' % err) 
开发者ID:occrp-attic,项目名称:ingestors,代码行数:22,代码来源:rar.py

示例2: test

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import Error [as 别名]
def test(fn, psw):
    """Process one archive with error handling.
    """
    try:
        test_real(fn, psw)
    except rf.NeedFirstVolume:
        xprint(" --- %s is middle part of multi-vol archive ---", fn)
    except rf.Error:
        exc, msg, tb = sys.exc_info()
        xprint("\n *** %s: %s ***\n", exc.__name__, msg)
        del tb
    except IOError:
        exc, msg, tb = sys.exc_info()
        xprint("\n *** %s: %s ***\n", exc.__name__, msg)
        del tb 
开发者ID:BasioMeusPuga,项目名称:Lector,代码行数:17,代码来源:dumprar.py

示例3: process_rar_archive

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import Error [as 别名]
def process_rar_archive(parent, relatives, cache_path):
    filename = os.path.join(cache_path, parent.filename)

    results = list()
    try:
        with rarfile.RarFile(filename) as archive:
            for entry in archive.infolist():
                switcher = {
                    'application/x-3ds-archive': process_cia,
                    'application/x-3ds-homebrew': process_tdsx,
                    'application/x-3ds-iconfile': process_smdh,
                    'application/x-3ds-arm9bin': process_arm9,
                    'application/x-3ds-xml': process_xml
                }
                action = switcher.get(determine_mimetype(entry.filename), None)
                if action:
                    working_file = os.path.join(cache_path, 'archive_root', entry.filename)
                    working_path = '/'.join(working_file.split('/')[:-1])
                    if not os.path.isdir(working_path):
                        os.makedirs(working_path)
                    with open(working_file, 'wb') as f:
                        with archive.open(entry.filename, 'r') as a:
                            for block in iter((lambda:a.read(32768)),''):
                                if not block: break
                                f.write(block)
                    os.utime(working_file, (entry.date_time.timestamp(),entry.date_time.timestamp()))
                    results.append(action(parent, relatives, cache_path, entry.filename))
    except rarfile.Error as e:
        log.debug("Archive error: %s", e)

    if results:
         for result_item in results:
            # Match up any xml or smdh files in the same folder as our 3dsx.
            if result_item.__class__ in (XML, SMDH):
                matched = False
                for check_item in results:
                    if not matched:
                        matched = check_siblings(check_item, result_item)
                result_item.active = matched

    return(results) 
开发者ID:ksanislo,项目名称:TitleDB,代码行数:43,代码来源:magic.py


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