filer.utils.zip: 17 total statements, 0.0% covered

Generated: Wed 2013-03-13 10:33 CET

Source file: /media/Envs/Envs/filer-gallery/lib/python2.7/site-packages/filer/utils/zip.py

Stats: 0 executed, 14 missed, 3 excluded, 9 ignored

  1. #-*- coding: utf-8 -*-
  2. #import zipfile
  3. # zipfile.open() is only available in Python 2.6, so we use the future version
  4. from django.core.files.uploadedfile import SimpleUploadedFile
  5. from zipfile import ZipFile
  6. def unzip(file_obj):
  7. """
  8. Take a path to a zipfile and checks if it is a valid zip file
  9. and returns...
  10. """
  11. files = []
  12. # TODO: implement try-except here
  13. zip = ZipFile(file_obj)
  14. bad_file = zip.testzip()
  15. if bad_file:
  16. raise Exception('"%s" in the .zip archive is corrupt.' % bad_file)
  17. infolist = zip.infolist()
  18. for zipinfo in infolist:
  19. if zipinfo.filename.startswith('__'): # do not process meta files
  20. continue
  21. file_obj = SimpleUploadedFile(name=zipinfo.filename, content=zip.read(zipinfo))
  22. files.append((file_obj, zipinfo.filename))
  23. zip.close()
  24. return files