當前位置: 首頁>>代碼示例>>Python>>正文


Python zipfile.error方法代碼示例

本文整理匯總了Python中zipfile.error方法的典型用法代碼示例。如果您正苦於以下問題:Python zipfile.error方法的具體用法?Python zipfile.error怎麽用?Python zipfile.error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在zipfile的用法示例。


在下文中一共展示了zipfile.error方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: adjust

# 需要導入模塊: import zipfile [as 別名]
# 或者: from zipfile import error [as 別名]
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: 
開發者ID:krintoxi,項目名稱:NoobSec-Toolkit,代碼行數:23,代碼來源:wordlist.py

示例2: adjust

# 需要導入模塊: import zipfile [as 別名]
# 或者: from zipfile import error [as 別名]
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: 
開發者ID:sabri-zaki,項目名稱:EasY_HaCk,代碼行數:23,代碼來源:wordlist.py

示例3: _unzip_iter

# 需要導入模塊: import zipfile [as 別名]
# 或者: from zipfile import error [as 別名]
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. 
開發者ID:V1EngineeringInc,項目名稱:V1EngineeringInc-Docs,代碼行數:26,代碼來源:downloader.py

示例4: extract_zip

# 需要導入模塊: import zipfile [as 別名]
# 或者: from zipfile import error [as 別名]
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 
開發者ID:pzwang,項目名稱:bokeh-dashboard-webinar,代碼行數:37,代碼來源:download_sample_data.py

示例5: next

# 需要導入模塊: import zipfile [as 別名]
# 或者: from zipfile import error [as 別名]
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() 
開發者ID:krintoxi,項目名稱:NoobSec-Toolkit,代碼行數:16,代碼來源:wordlist.py

示例6: _unzip_iter

# 需要導入模塊: import zipfile [as 別名]
# 或者: from zipfile import error [as 別名]
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 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:11,代碼來源:downloader.py

示例7: next

# 需要導入模塊: import zipfile [as 別名]
# 或者: from zipfile import error [as 別名]
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() 
開發者ID:sabri-zaki,項目名稱:EasY_HaCk,代碼行數:16,代碼來源:wordlist.py

示例8: _unzip_iter

# 需要導入模塊: import zipfile [as 別名]
# 或者: from zipfile import error [as 別名]
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. 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:59,代碼來源:downloader.py

示例9: _unzip_iter

# 需要導入模塊: import zipfile [as 別名]
# 或者: from zipfile import error [as 別名]
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. 
開發者ID:aboSamoor,項目名稱:polyglot,代碼行數:59,代碼來源:downloader.py


注:本文中的zipfile.error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。