当前位置: 首页>>代码示例>>Python>>正文


Python importlib.import_module方法代码示例

本文整理汇总了Python中django.utils.importlib.import_module方法的典型用法代码示例。如果您正苦于以下问题:Python importlib.import_module方法的具体用法?Python importlib.import_module怎么用?Python importlib.import_module使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.importlib的用法示例。


在下文中一共展示了importlib.import_module方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: resolve_default_fixture

# 需要导入模块: from django.utils import importlib [as 别名]
# 或者: from django.utils.importlib import import_module [as 别名]
def resolve_default_fixture(module, module_fragment, fixture_class, schema=None, *args, **kwargs):
    """
        Return the default fixture_class version of the given module. The default_fixture is the fixture matching
        the module [module].default_[module_fragment]. This is the top of the food-chain. All client fixtures
        should incorporate the default fixtures into their own. The default also is used if a certain client
        fixture is not defined.
    :param module: module under footprint.client.configuration.default
    :param module_fragment: the * fragment of the module default_* (e.g. 'built_form' for default_built_form)
    :param fixture_class: The class to lookup in the module. Any subclass will match as well
    :return:
    """
    default_module_string = '%s.%s_%s' % (module, 'default', module_fragment) if module else \
        '%s_%s' % ('default', module_fragment)
    client_module = importlib.import_module(
         "footprint.client.configuration.default.%s" % default_module_string)
    class_members = inspect.getmembers(sys.modules[client_module.__name__], inspect.isclass)
    for name, cls in class_members:
        if issubclass(cls, fixture_class) and cls != fixture_class:
            return cls(schema or 'global', *args, **kwargs) 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:21,代码来源:utils.py

示例2: parse_backend_conf

# 需要导入模块: from django.utils import importlib [as 别名]
# 或者: from django.utils.importlib import import_module [as 别名]
def parse_backend_conf(backend, **kwargs):
    """
    Helper function to parse the backend configuration
    that doesn't use the URI notation.
    """
    # Try to get the CACHES entry for the given backend name first
    conf = settings.CACHES.get(backend, None)
    if conf is not None:
        args = conf.copy()
        args.update(kwargs)
        backend = args.pop('BACKEND')
        location = args.pop('LOCATION', '')
        return backend, location, args
    else:
        try:
            # Trying to import the given backend, in case it's a dotted path
            mod_path, cls_name = backend.rsplit('.', 1)
            mod = importlib.import_module(mod_path)
            backend_cls = getattr(mod, cls_name)
        except (AttributeError, ImportError, ValueError):
            raise InvalidCacheBackendError("Could not find backend '%s'" % backend)
        location = kwargs.pop('LOCATION', '')
        return backend, location, kwargs 
开发者ID:blackye,项目名称:luscan-devel,代码行数:25,代码来源:__init__.py

示例3: register_serializer

# 需要导入模块: from django.utils import importlib [as 别名]
# 或者: from django.utils.importlib import import_module [as 别名]
def register_serializer(format, serializer_module, serializers=None):
    """Register a new serializer.

    ``serializer_module`` should be the fully qualified module name
    for the serializer.

    If ``serializers`` is provided, the registration will be added
    to the provided dictionary.

    If ``serializers`` is not provided, the registration will be made
    directly into the global register of serializers. Adding serializers
    directly is not a thread-safe operation.
    """
    if serializers is None and not _serializers:
        _load_serializers()
    module = importlib.import_module(serializer_module)
    if serializers is None:
        _serializers[format] = module
    else:
        serializers[format] = module 
开发者ID:blackye,项目名称:luscan-devel,代码行数:22,代码来源:__init__.py

示例4: load_handler

# 需要导入模块: from django.utils import importlib [as 别名]
# 或者: from django.utils.importlib import import_module [as 别名]
def load_handler(path, *args, **kwargs):
    """
    Given a path to a handler, return an instance of that handler.

    E.g.::
        >>> load_handler('django.core.files.uploadhandler.TemporaryFileUploadHandler', request)
        <TemporaryFileUploadHandler object at 0x...>

    """
    i = path.rfind('.')
    module, attr = path[:i], path[i+1:]
    try:
        mod = importlib.import_module(module)
    except ImportError as e:
        raise ImproperlyConfigured('Error importing upload handler module %s: "%s"' % (module, e))
    except ValueError:
        raise ImproperlyConfigured('Error importing upload handler module.'
            'Is FILE_UPLOAD_HANDLERS a correctly defined list or tuple?')
    try:
        cls = getattr(mod, attr)
    except AttributeError:
        raise ImproperlyConfigured('Module "%s" does not define a "%s" upload handler backend' % (module, attr))
    return cls(*args, **kwargs) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:25,代码来源:uploadhandler.py

示例5: load

# 需要导入模块: from django.utils import importlib [as 别名]
# 或者: from django.utils.importlib import import_module [as 别名]
def load(self):
        if not self.loaded:
            for app in settings.INSTALLED_APPS:
                if protocol_module_re.match(app):
                    try:
                        importlib.import_module(app+'.protocol')
                    except ImportError:
                        logger.exception()
        self.loaded = True 
开发者ID:dissemin,项目名称:dissemin,代码行数:11,代码来源:registry.py

示例6: discover_providers

# 需要导入模块: from django.utils import importlib [as 别名]
# 或者: from django.utils.importlib import import_module [as 别名]
def discover_providers(self):
        if not self.discovered:
            for app in settings.INSTALLED_APPS:
                provider_module = app + '.provider'
                try:
                    importlib.import_module(provider_module)
                except ImportError:
                    pass
            self.discovered = True 
开发者ID:mishbahr,项目名称:django-connected,代码行数:11,代码来源:provider_pool.py

示例7: resolve_client_module

# 需要导入模块: from django.utils import importlib [as 别名]
# 或者: from django.utils.importlib import import_module [as 别名]
def resolve_client_module(module, module_fragment, schema=settings.CLIENT):
    """
        Resolve the client module under footprint.client.configuration.[client], which client is the
        specified or default client
    :param module: The base module. This can be set to none to fetch a module directly under [client]
    :param module_fragment: The sub module under base module (if base is not None) minus the client name.
        So 'land_use_definition' resolves to '[client]_land_use_definition'
    :param schema: Optional schema string. Defaults to settings.CLIENT
    :return:
    """
    module_string = form_module_name(module, module_fragment, schema)

    return importlib.import_module("footprint.client.configuration.%s" % module_string) 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:15,代码来源:utils.py

示例8: _configure_logging

# 需要导入模块: from django.utils import importlib [as 别名]
# 或者: from django.utils.importlib import import_module [as 别名]
def _configure_logging(self):
        """
        Setup logging from LOGGING_CONFIG and LOGGING settings.
        """
        if not sys.warnoptions:
            try:
                # Route warnings through python logging
                logging.captureWarnings(True)
                # Allow DeprecationWarnings through the warnings filters
                warnings.simplefilter("default", DeprecationWarning)
            except AttributeError:
                # No captureWarnings on Python 2.6, DeprecationWarnings are on anyway
                pass

        if self.LOGGING_CONFIG:
            from django.utils.log import DEFAULT_LOGGING
            # First find the logging configuration function ...
            logging_config_path, logging_config_func_name = self.LOGGING_CONFIG.rsplit('.', 1)
            logging_config_module = importlib.import_module(logging_config_path)
            logging_config_func = getattr(logging_config_module, logging_config_func_name)

            logging_config_func(DEFAULT_LOGGING)

            if self.LOGGING:
                # Backwards-compatibility shim for #16288 fix
                compat_patch_logging_config(self.LOGGING)

                # ... then invoke it with the logging settings
                logging_config_func(self.LOGGING) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:31,代码来源:__init__.py

示例9: import_attribute

# 需要导入模块: from django.utils import importlib [as 别名]
# 或者: from django.utils.importlib import import_module [as 别名]
def import_attribute(path):
    assert isinstance(path, str)
    pkg, attr = path.rsplit('.', 1)
    ret = getattr(importlib.import_module(pkg), attr)
    return ret 
开发者ID:bee-keeper,项目名称:django-invitations,代码行数:7,代码来源:utils.py

示例10: ready

# 需要导入模块: from django.utils import importlib [as 别名]
# 或者: from django.utils.importlib import import_module [as 别名]
def ready(self):
        importlib.import_module("pinax.teams.receivers") 
开发者ID:pinax,项目名称:pinax-teams,代码行数:4,代码来源:apps.py

示例11: import_submodules

# 需要导入模块: from django.utils import importlib [as 别名]
# 或者: from django.utils.importlib import import_module [as 别名]
def import_submodules(module):
    """Import all submodules and make them available in a dict."""
    submodules = {}
    for loader, name, ispkg in pkgutil.iter_modules(module.__path__,
                                                    module.__name__ + '.'):
        try:
            submodule = importlib.import_module(name)
        except ImportError as e:
            # FIXME: Make the errors non-fatal (do we want that?).
            logging.warning("Error importing %s" % name)
            logging.exception(e)
        else:
            parent, child = name.rsplit('.', 1)
            submodules[child] = submodule
    return submodules 
开发者ID:CiscoSystems,项目名称:avos,代码行数:17,代码来源:settings.py

示例12: get_serializer

# 需要导入模块: from django.utils import importlib [as 别名]
# 或者: from django.utils.importlib import import_module [as 别名]
def get_serializer(self, **kwargs):
        serializer = self.model.Elasticsearch.serializer_class
        if isinstance(serializer, basestring):
            module, kls = self.model.Elasticsearch.serializer_class.rsplit(".", 1)
            mod = importlib.import_module(module)
            return getattr(mod, kls)(self.model, **kwargs)
        else:
            return serializer(self.model, **kwargs) 
开发者ID:liberation,项目名称:django-elasticsearch,代码行数:10,代码来源:managers.py

示例13: get_cache

# 需要导入模块: from django.utils import importlib [as 别名]
# 或者: from django.utils.importlib import import_module [as 别名]
def get_cache(backend, **kwargs):
    """
    Function to load a cache backend dynamically. This is flexible by design
    to allow different use cases:

    To load a backend with the old URI-based notation::

        cache = get_cache('locmem://')

    To load a backend that is pre-defined in the settings::

        cache = get_cache('default')

    To load a backend with its dotted import path,
    including arbitrary options::

        cache = get_cache('django.core.cache.backends.memcached.MemcachedCache', **{
            'LOCATION': '127.0.0.1:11211', 'TIMEOUT': 30,
        })

    """
    try:
        if '://' in backend:
            # for backwards compatibility
            backend, location, params = parse_backend_uri(backend)
            if backend in BACKENDS:
                backend = 'django.core.cache.backends.%s' % BACKENDS[backend]
            params.update(kwargs)
            mod = importlib.import_module(backend)
            backend_cls = mod.CacheClass
        else:
            backend, location, params = parse_backend_conf(backend, **kwargs)
            mod_path, cls_name = backend.rsplit('.', 1)
            mod = importlib.import_module(mod_path)
            backend_cls = getattr(mod, cls_name)
    except (AttributeError, ImportError) as e:
        raise InvalidCacheBackendError(
            "Could not find backend '%s': %s" % (backend, e))
    cache = backend_cls(location, params)
    # Some caches -- python-memcached in particular -- need to do a cleanup at the
    # end of a request cycle. If the cache provides a close() method, wire it up
    # here.
    if hasattr(cache, 'close'):
        signals.request_finished.connect(cache.close)
    return cache 
开发者ID:blackye,项目名称:luscan-devel,代码行数:47,代码来源:__init__.py


注:本文中的django.utils.importlib.import_module方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。