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


Python rarfile.BadRarFile方法代码示例

本文整理汇总了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 
开发者ID:WhaleShark-Team,项目名称:cobra,代码行数:18,代码来源:pickup.py

示例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",
        ) 
开发者ID:gyh1621,项目名称:GetSubtitles,代码行数:11,代码来源:test_process_archive.py

示例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 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:56,代码来源:core.py


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