module.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # -*- coding: utf-8 -*-
  2. """
  3. flask.module
  4. ~~~~~~~~~~~~
  5. Implements a class that represents module blueprints.
  6. :copyright: (c) 2011 by Armin Ronacher.
  7. :license: BSD, see LICENSE for more details.
  8. """
  9. import os
  10. from .blueprints import Blueprint
  11. def blueprint_is_module(bp):
  12. """Used to figure out if something is actually a module"""
  13. return isinstance(bp, Module)
  14. class Module(Blueprint):
  15. """Deprecated module support. Until Flask 0.6 modules were a different
  16. name of the concept now available as blueprints in Flask. They are
  17. essentially doing the same but have some bad semantics for templates and
  18. static files that were fixed with blueprints.
  19. .. versionchanged:: 0.7
  20. Modules were deprecated in favor for blueprints.
  21. """
  22. def __init__(self, import_name, name=None, url_prefix=None,
  23. static_path=None, subdomain=None):
  24. if name is None:
  25. assert '.' in import_name, 'name required if package name ' \
  26. 'does not point to a submodule'
  27. name = import_name.rsplit('.', 1)[1]
  28. Blueprint.__init__(self, name, import_name, url_prefix=url_prefix,
  29. subdomain=subdomain, template_folder='templates')
  30. if os.path.isdir(os.path.join(self.root_path, 'static')):
  31. self._static_folder = 'static'