Path: blob/develop/build/sage_bootstrap/uncompress/zip_file.py
4055 views
"""1Zip file support2"""34#*****************************************************************************5# Copyright (C) 2016 Volker Braun <[email protected]>6#7# This program is free software: you can redistribute it and/or modify8# it under the terms of the GNU General Public License as published by9# the Free Software Foundation, either version 2 of the License, or10# (at your option) any later version.11# http://www.gnu.org/licenses/12#*****************************************************************************1314from __future__ import print_function1516import zipfile17from sage_bootstrap.uncompress.filter_os_files import filter_os_files181920class SageZipFile(zipfile.ZipFile):21"""22Wrapper for zipfile.ZipFile to provide better API fidelity with23SageTarFile insofar as it's used by this script.24"""2526@classmethod27def can_read(cls, filename):28"""29Given an archive filename, returns True if this class can read and30process the archive format of that file.31"""3233return zipfile.is_zipfile(filename)3435@property36def names(self):37"""38List of filenames in the archive.3940Filters out names of OS-related files that shouldn't be in the41archive (.DS_Store, etc.)42"""4344return filter_os_files(self.namelist())4546def extractbytes(self, member):47"""48Return the contents of the specified archive member as bytes.4950If the member does not exist, returns None.51"""5253if member in self.namelist():54return self.read(member)5556575859