filer.utils.loader: 13 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/loader.py

Stats: 0 executed, 11 missed, 2 excluded, 36 ignored

  1. #-*- coding: utf-8 -*-
  2. """
  3. This function is snatched from
  4. https://github.com/ojii/django-load/blob/3058ab9d9d4875589638cc45e84b59e7e1d7c9c3/django_load/core.py#L49
  5. local changes:
  6. * added check for basestring to allow values that are already an object
  7. or method.
  8. """
  9. from django.utils.importlib import import_module
  10. def load_object(import_path):
  11. """
  12. Loads an object from an 'import_path', like in MIDDLEWARE_CLASSES and the
  13. likes.
  14. Import paths should be: "mypackage.mymodule.MyObject". It then imports the
  15. module up until the last dot and tries to get the attribute after that dot
  16. from the imported module.
  17. If the import path does not contain any dots, a TypeError is raised.
  18. If the module cannot be imported, an ImportError is raised.
  19. If the attribute does not exist in the module, a AttributeError is raised.
  20. """
  21. if not isinstance(import_path, basestring):
  22. return import_path
  23. if '.' not in import_path:
  24. raise TypeError(
  25. "'import_path' argument to 'django_load.core.load_object' " +\
  26. "must contain at least one dot.")
  27. module_name, object_name = import_path.rsplit('.', 1)
  28. module = import_module(module_name)
  29. return getattr(module, object_name)
  30. def storage_factory(klass, location, base_url):
  31. """
  32. This factory returns an instance of the storage class provided.
  33. args:
  34. * klass: must be inherit from ``django.core.files.storage.Storage``
  35. * location: is a string representing the PATH similar to MEDIA_ROOT
  36. * base_url: is a string representing the URL similar to MEDIA_URL
  37. """
  38. return klass(location=location, base_url=base_url)