How to use the werkzeug.utils.import_string function in Werkzeug

To help you get started, we’ve selected a few Werkzeug examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kamalgill / flask-appengine-template / src / lib / flask / testsuite / __init__.py View on Github external
def iter_suites():
    """Yields all testsuites."""
    for module in find_modules(__name__):
        mod = import_string(module)
        if hasattr(mod, 'suite'):
            yield mod.suite()
github ianlewis / kay / kay / utils / __init__.py View on Github external
def get_standard_processors():
  from kay.conf import settings
  processors = []
  for path in settings.CONTEXT_PROCESSORS:
    try:
      func = import_string(path)
    except (ImportError, AttributeError), e:
      raise ImproperlyConfigured('Error importing request processor module'
                                 ' %s: "%s"' % (path, e))
    processors.append(func)
  return tuple(processors)
github inveniosoftware / invenio / invenio / ext / session / interface.py View on Github external
def session_class(self):
        """Return session class."""
        session_class_string = current_app.config.get(
            'SESSION_CLASS', 'invenio.ext.session.legacy_session:Session')
        return import_string(session_class_string) \
            if isinstance(session_class_string, six.string_types) \
            else session_class_string
github klen / Flask-Collect / flask_collect / collect.py View on Github external
def __init__(self, app):
        """Build a new state object."""
        self.app = app
        self.static_root = app.config.get(
            'COLLECT_STATIC_ROOT',
            op.join(
                app.root_path,
                'static')).rstrip('/')
        self.static_url = app.static_url_path

        self.storage = app.config.get(
            'COLLECT_STORAGE', 'flask_collect.storage.file')

        filter_ = app.config.get('COLLECT_FILTER')
        if filter_ is not None and isinstance(filter_, string_types):
            filter_ = import_string(filter_)
        self.filter = filter_ if filter_ is not None else list

        # Save link on blueprints
        self.blueprints = app.blueprints
github inveniosoftware / invenio / invenio / ext / session / backends / cache.py View on Github external
def cache(self):
        """Return cache storage."""
        return import_string(current_app.config.get(
            'SESSION_BACKEND_CACHE', 'invenio.ext.cache:cache'))
github alphagov / backdrop / tools / create_seed.py View on Github external
def import_config(app, env):
    return import_string("backdrop.%s.config.%s" % (app, env))
github inveniosoftware / invenio / invenio / modules / jsonalchemy / jsonext / parsers / extension_model_parser.py View on Github external
def evaluate(cls, obj, args):
        """Extend the incoming object with all the new things from args"""
        if args is None:
            return
        extensions = []
        for ext in args:
            try:
                extensions.append(import_string(ext))
            except ImportError:
                extensions.append(try_to_eval(ext))
        extensions.append(obj.__class__)

        obj.__class__ = type(obj.__class__.__name__, tuple(extensions), {})
github ianlewis / kay / kay / auth / backends / datastore.py View on Github external
def test_login_or_logout(self, client, username=''):
    from cookielib import Cookie
    args = [None, None, '', None, None, '/', None, None, 86400, None, None,
            None, None]
    try:
      auth_model_class = import_string(settings.AUTH_USER_MODEL)
    except (ImportError, AttributeError), e:
      raise ImproperlyConfigured, \
          'Failed to import %s: "%s".' % (settings.AUTH_USER_MODEL, e)
    user = auth_model_class.get_by_user_name(username)
    session_store = import_string(settings.SESSION_STORE)()
    data = None
    for cookie in client.cookie_jar:
      if cookie.name == settings.COOKIE_NAME:
        data = cookie.value
    if data is None:
      session = session_store.new()
    else:
      session = session_store.get(data)
    if user:
      session['_user'] = user.key()
    elif session.has_key('_user'):
      del session['_user']
    session_store.save(session)
    data = "\"%s\"" % session_store.get_data(session)
    client.cookie_jar.set_cookie(Cookie(1, settings.COOKIE_NAME,
                                        data,
github sh4nks / flask-plugins / flask_plugins / __init__.py View on Github external
def load_plugins(self):
        """Loads all plugins. They are still disabled.
        Returns a list with all loaded plugins. They should now be accessible
        via self.plugins.
        """
        self._plugins = {}
        self._all_plugins = {}
        for plugin_name, plugin_package in iteritems(self.find_plugins()):

            try:
                plugin_class = import_string(
                    "{}.{}".format(plugin_package, plugin_name)
                )
            except ImportError:
                raise PluginError(
                    "Couldn't import {} Plugin. Please check if the "
                    "__plugin__ variable is set correctly.".format(plugin_name)
                )

            plugin_path = os.path.join(
                self.plugin_folder,
                os.path.basename(plugin_package.replace(".", "/"))
            )

            plugin_instance = plugin_class(plugin_path)

            try:
github roman-kutlak / nlglib / nlglib / config.py View on Github external
pipeline.config.from_object('yourapplication.default_config')
            from yourapplication import default_config
            pipeline.config.from_object(default_config)

        You should not use this function to load the actual configuration but
        rather configuration defaults.  The actual config should be loaded
        with :meth:`from_pyfile` and ideally from a location not within the
        package because the package might be installed system wide.

        See :ref:`config-dev-prod` for an example of class-based configuration
        using :meth:`from_object`.

        :param obj: an import name or object
        """
        if isinstance(obj, str):
            obj = import_string(obj)
        for key in dir(obj):
            if key.isupper():
                self[key] = getattr(obj, key)