本文整理汇总了Python中rarfile.BadRarFile方法的典型用法代码示例。如果您正苦于以下问题:Python rarfile.BadRarFile方法的具体用法?Python rarfile.BadRarFile怎么用?Python rarfile.BadRarFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rarfile
的用法示例。
在下文中一共展示了rarfile.BadRarFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __decompress_rar
# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import BadRarFile [as 别名]
def __decompress_rar(self):
"""extract a rar file."""
try:
rar_file = rarfile.RarFile(self.filepath)
# check if there is a filename directory
self.__check_filename_dir()
os.mkdir(os.path.join(self.package_path, self.dir_name))
rar_file.extractall(os.path.join(self.package_path, self.dir_name))
rar_file.close()
except (BadRarFile, NotRarFile):
logger.error('File is not a rar file or is bad rar file')
exit()
return True
示例2: test_invalid_archive
# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import BadRarFile [as 别名]
def test_invalid_archive(self):
process_archive = get_function()
self.assertRaises(
rarfile.BadRarFile,
process_archive,
TestProcessArchive.test_video,
b"",
".7z",
)
示例3: download_subtitle
# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import BadRarFile [as 别名]
def download_subtitle(self, subtitle):
"""Download `subtitle`'s :attr:`~subliminal.subtitle.Subtitle.content`.
:param subtitle: subtitle to download.
:type subtitle: :class:`~subliminal.subtitle.Subtitle`
:return: `True` if the subtitle has been successfully downloaded, `False` otherwise.
:rtype: bool
"""
# check discarded providers
if subtitle.provider_name in self.discarded_providers:
logger.warning('Provider %r is discarded', subtitle.provider_name)
return False
logger.info('Downloading subtitle %r', subtitle)
try:
self[subtitle.provider_name].download_subtitle(subtitle)
except (requests.Timeout, socket.timeout):
logger.error('Provider %r timed out, discarding it', subtitle.provider_name)
self.discarded_providers.add(subtitle.provider_name)
return False
except (ServiceUnavailable, ProtocolError): # OpenSubtitles raises xmlrpclib.ProtocolError when unavailable
logger.error('Provider %r unavailable, discarding it', subtitle.provider_name)
self.discarded_providers.add(subtitle.provider_name)
return False
except requests.exceptions.HTTPError as e:
if e.response.status_code in range(500, 600):
logger.error('Provider %r unavailable, discarding it', subtitle.provider_name)
else:
logger.exception('Provider %r http error %r, discarding it', subtitle.provider_name,
e.response.status_code)
self.discarded_providers.add(subtitle.provider_name)
return False
except SSLError as e:
if e.args[0] == 'The read operation timed out':
logger.error('Provider %r unavailable, discarding it', subtitle.provider_name)
else:
logger.exception('Provider %r SSL error %r, discarding it', subtitle.provider_name, e.args[0])
self.discarded_providers.add(subtitle.provider_name)
return False
except (BadRarFile, BadZipfile):
logger.error('Bad archive for %r', subtitle)
return False
except:
logger.exception('Unexpected error in provider %r, discarding it', subtitle.provider_name)
self.discarded_providers.add(subtitle.provider_name)
return False
# check subtitle validity
if not subtitle.is_valid():
logger.error('Invalid subtitle')
return False
return True