filer.server.backends.base: 23 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/server/backends/base.py

Stats: 0 executed, 20 missed, 3 excluded, 21 ignored

  1. #-*- coding: utf-8 -*-
  2. from django.utils.encoding import smart_str
  3. import mimetypes
  4. import os
  5. class ServerBase(object):
  6. """
  7. Server classes define a way to serve a Django File object.
  8. Warning: this API is EXPERIMENTAL and may change at any time.
  9. """
  10. def get_mimetype(self, path):
  11. return mimetypes.guess_type(path)[0] or 'application/octet-stream'
  12. def default_headers(self, **kwargs):
  13. self.save_as_header(**kwargs)
  14. self.size_header(**kwargs)
  15. def save_as_header(self, response, **kwargs):
  16. """
  17. * if save_as is False the header will not be added
  18. * if save_as is a filename, it will be used in the header
  19. * if save_as is None the filename will be determined from the file path
  20. """
  21. save_as = kwargs.get('save_as', None)
  22. if save_as == False:
  23. return
  24. file_obj = kwargs.get('file_obj', None)
  25. filename = None
  26. if save_as:
  27. filename = save_as
  28. else:
  29. filename = os.path.basename(file_obj.path)
  30. response['Content-Disposition'] = smart_str(u'attachment; filename=%s' % filename)
  31. def size_header(self, response, **kwargs):
  32. size = kwargs.get('size', None)
  33. #file = kwargs.get('file', None)
  34. if size:
  35. response['Content-Length'] = size
  36. # we should not do this, because it accesses the file. and that might be an expensive operation.
  37. # elif file and file.size is not None:
  38. # response['Content-Length'] = file.size