Python zipfile.error() Examples
The following are 13
code examples of zipfile.error().
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
zipfile
, or try the search function
.
Example #1
Source File: wordlist.py From NoobSec-Toolkit with GNU General Public License v2.0 | 6 votes |
def adjust(self): self.closeFP() if self.index > len(self.filenames): raise StopIteration elif self.index == len(self.filenames): self.iter = iter(self.custom) else: self.current = self.filenames[self.index] if os.path.splitext(self.current)[1].lower() == ".zip": try: _ = zipfile.ZipFile(self.current, 'r') except zipfile.error, ex: errMsg = "something seems to be wrong with " errMsg += "the file '%s' ('%s'). Please make " % (self.current, ex) errMsg += "sure that you haven't made any changes to it" raise SqlmapInstallationException, errMsg if len(_.namelist()) == 0: errMsg = "no file(s) inside '%s'" % self.current raise SqlmapDataException(errMsg) self.fp = _.open(_.namelist()[0]) else:
Example #2
Source File: wordlist.py From NoobSec-Toolkit with GNU General Public License v2.0 | 6 votes |
def adjust(self): self.closeFP() if self.index > len(self.filenames): raise StopIteration elif self.index == len(self.filenames): self.iter = iter(self.custom) else: self.current = self.filenames[self.index] if os.path.splitext(self.current)[1].lower() == ".zip": try: _ = zipfile.ZipFile(self.current, 'r') except zipfile.error, ex: errMsg = "something seems to be wrong with " errMsg += "the file '%s' ('%s'). Please make " % (self.current, ex) errMsg += "sure that you haven't made any changes to it" raise SqlmapInstallationException, errMsg if len(_.namelist()) == 0: errMsg = "no file(s) inside '%s'" % self.current raise SqlmapDataException(errMsg) self.fp = _.open(_.namelist()[0]) else:
Example #3
Source File: wordlist.py From POC-EXP with GNU General Public License v3.0 | 6 votes |
def adjust(self): self.closeFP() if self.index > len(self.filenames): raise StopIteration elif self.index == len(self.filenames): self.iter = iter(self.custom) else: self.current = self.filenames[self.index] if os.path.splitext(self.current)[1].lower() == ".zip": try: _ = zipfile.ZipFile(self.current, 'r') except zipfile.error, ex: errMsg = "something seems to be wrong with " errMsg += "the file '%s' ('%s'). Please make " % (self.current, ex) errMsg += "sure that you haven't made any changes to it" raise SqlmapInstallationException, errMsg if len(_.namelist()) == 0: errMsg = "no file(s) inside '%s'" % self.current raise SqlmapDataException(errMsg) self.fp = _.open(_.namelist()[0]) else:
Example #4
Source File: wordlist.py From EasY_HaCk with Apache License 2.0 | 6 votes |
def adjust(self): self.closeFP() if self.index > len(self.filenames): raise StopIteration elif self.index == len(self.filenames): self.iter = iter(self.custom) else: self.current = self.filenames[self.index] if os.path.splitext(self.current)[1].lower() == ".zip": try: _ = zipfile.ZipFile(self.current, 'r') except zipfile.error, ex: errMsg = "something appears to be wrong with " errMsg += "the file '%s' ('%s'). Please make " % (self.current, getSafeExString(ex)) errMsg += "sure that you haven't made any changes to it" raise SqlmapInstallationException(errMsg) if len(_.namelist()) == 0: errMsg = "no file(s) inside '%s'" % self.current raise SqlmapDataException(errMsg) self.fp = _.open(_.namelist()[0]) else:
Example #5
Source File: downloader.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
def _unzip_iter(filename, root, verbose=True): if verbose: sys.stdout.write('Unzipping %s' % os.path.split(filename)[1]) sys.stdout.flush() try: zf = zipfile.ZipFile(filename) except zipfile.error as e: yield ErrorMessage(filename, 'Error with downloaded zip file') return except Exception as e: yield ErrorMessage(filename, e) return zf.extractall(root) if verbose: print() ###################################################################### # Index Builder ###################################################################### # This may move to a different file sometime.
Example #6
Source File: download_sample_data.py From bokeh-dashboard-webinar with BSD 3-Clause "New" or "Revised" License | 5 votes |
def extract_zip(zip_name, exclude_term=None): """Extracts a zip file to its containing directory.""" zip_dir = os.path.dirname(os.path.abspath(zip_name)) try: with zipfile.ZipFile(zip_name) as z: # write each zipped file out if it isn't a directory files = [zip_file for zip_file in z.namelist() if not zip_file.endswith('/')] print('Extracting %i files from %r.' % (len(files), zip_name)) for zip_file in files: # remove any provided extra directory term from zip file if exclude_term: dest_file = zip_file.replace(exclude_term, '') else: dest_file = zip_file dest_file = os.path.normpath(os.path.join(zip_dir, dest_file)) dest_dir = os.path.dirname(dest_file) # make directory if it does not exist if not os.path.isdir(dest_dir): os.makedirs(dest_dir) # read file from zip, then write to new directory data = z.read(zip_file) with open(dest_file, 'wb') as f: f.write(encode_utf8(data)) except zipfile.error as e: print("Bad zipfile (%r): %s" % (zip_name, e)) raise e
Example #7
Source File: wordlist.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def next(self): retVal = None while True: self.counter += 1 try: retVal = self.iter.next().rstrip() except zipfile.error, ex: errMsg = "something seems to be wrong with " errMsg += "the file '%s' ('%s'). Please make " % (self.current, ex) errMsg += "sure that you haven't made any changes to it" raise SqlmapInstallationException, errMsg except StopIteration: self.adjust() retVal = self.iter.next().rstrip()
Example #8
Source File: wordlist.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def next(self): retVal = None while True: self.counter += 1 try: retVal = self.iter.next().rstrip() except zipfile.error, ex: errMsg = "something seems to be wrong with " errMsg += "the file '%s' ('%s'). Please make " % (self.current, ex) errMsg += "sure that you haven't made any changes to it" raise SqlmapInstallationException, errMsg except StopIteration: self.adjust() retVal = self.iter.next().rstrip()
Example #9
Source File: downloader.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def _unzip_iter(filename, root, verbose=True): if verbose: sys.stdout.write('Unzipping %s' % os.path.split(filename)[1]) sys.stdout.flush() try: zf = zipfile.ZipFile(filename) except zipfile.error, e: yield ErrorMessage(filename, 'Error with downloaded zip file') return
Example #10
Source File: wordlist.py From POC-EXP with GNU General Public License v3.0 | 5 votes |
def next(self): retVal = None while True: self.counter += 1 try: retVal = self.iter.next().rstrip() except zipfile.error, ex: errMsg = "something seems to be wrong with " errMsg += "the file '%s' ('%s'). Please make " % (self.current, ex) errMsg += "sure that you haven't made any changes to it" raise SqlmapInstallationException, errMsg except StopIteration: self.adjust() retVal = self.iter.next().rstrip()
Example #11
Source File: wordlist.py From EasY_HaCk with Apache License 2.0 | 5 votes |
def next(self): retVal = None while True: self.counter += 1 try: retVal = self.iter.next().rstrip() except zipfile.error, ex: errMsg = "something appears to be wrong with " errMsg += "the file '%s' ('%s'). Please make " % (self.current, getSafeExString(ex)) errMsg += "sure that you haven't made any changes to it" raise SqlmapInstallationException(errMsg) except StopIteration: self.adjust() retVal = self.iter.next().rstrip()
Example #12
Source File: downloader.py From razzy-spinner with GNU General Public License v3.0 | 4 votes |
def _unzip_iter(filename, root, verbose=True): if verbose: sys.stdout.write('Unzipping %s' % os.path.split(filename)[1]) sys.stdout.flush() try: zf = zipfile.ZipFile(filename) except zipfile.error as e: yield ErrorMessage(filename, 'Error with downloaded zip file') return except Exception as e: yield ErrorMessage(filename, e) return # Get lists of directories & files namelist = zf.namelist() dirlist = set() for x in namelist: if x.endswith('/'): dirlist.add(x) else: dirlist.add(x.rsplit('/',1)[0] + '/') filelist = [x for x in namelist if not x.endswith('/')] # Create the target directory if it doesn't exist if not os.path.exists(root): os.mkdir(root) # Create the directory structure for dirname in sorted(dirlist): pieces = dirname[:-1].split('/') for i in range(len(pieces)): dirpath = os.path.join(root, *pieces[:i+1]) if not os.path.exists(dirpath): os.mkdir(dirpath) # Extract files. for i, filename in enumerate(filelist): filepath = os.path.join(root, *filename.split('/')) with open(filepath, 'wb') as outfile: try: contents = zf.read(filename) except Exception as e: yield ErrorMessage(filename, e) return outfile.write(contents) if verbose and (i*10/len(filelist) > (i-1)*10/len(filelist)): sys.stdout.write('.') sys.stdout.flush() if verbose: print() ###################################################################### # Index Builder ###################################################################### # This may move to a different file sometime.
Example #13
Source File: downloader.py From polyglot with GNU General Public License v3.0 | 4 votes |
def _unzip_iter(filename, root, verbose=True): if verbose: sys.stdout.write('Unzipping %s' % os.path.split(filename)[1]) sys.stdout.flush() try: zf = zipfile.ZipFile(filename) except zipfile.error as e: yield ErrorMessage(filename, 'Error with downloaded zip file') return except Exception as e: yield ErrorMessage(filename, e) return # Get lists of directories & files namelist = zf.namelist() dirlist = set() for x in namelist: if x.endswith('/'): dirlist.add(x) else: dirlist.add(x.rsplit('/',1)[0] + '/') filelist = [x for x in namelist if not x.endswith('/')] # Create the target directory if it doesn't exist if not os.path.exists(root): os.mkdir(root) # Create the directory structure for dirname in sorted(dirlist): pieces = dirname[:-1].split('/') for i in range(len(pieces)): dirpath = os.path.join(root, *pieces[:i+1]) if not os.path.exists(dirpath): os.mkdir(dirpath) # Extract files. for i, filename in enumerate(filelist): filepath = os.path.join(root, *filename.split('/')) with open(filepath, 'wb') as outfile: try: contents = zf.read(filename) except Exception as e: yield ErrorMessage(filename, e) return outfile.write(contents) if verbose and (i*10/len(filelist) > (i-1)*10/len(filelist)): sys.stdout.write('.') sys.stdout.flush() if verbose: print() ###################################################################### # Index Builder ###################################################################### # This may move to a different file sometime.