本文整理汇总了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)
示例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
示例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)