Python rarfile.BadRarFile() Examples
The following are 3
code examples of rarfile.BadRarFile().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rarfile
, or try the search function
.
Example #1
Source File: pickup.py From cobra with MIT License | 6 votes |
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
Example #2
Source File: test_process_archive.py From GetSubtitles with MIT License | 5 votes |
def test_invalid_archive(self): process_archive = get_function() self.assertRaises( rarfile.BadRarFile, process_archive, TestProcessArchive.test_video, b"", ".7z", )
Example #3
Source File: core.py From bazarr with GNU General Public License v3.0 | 4 votes |
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