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


Python conf.LazySettings类代码示例

本文整理汇总了Python中django.conf.LazySettings的典型用法代码示例。如果您正苦于以下问题:Python LazySettings类的具体用法?Python LazySettings怎么用?Python LazySettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_dict_setting_clear_defaults

    def test_dict_setting_clear_defaults(self):
        """
        Test the ability to deactivate the merge feature of dictionary settings.
        """
        s = LazySettings()
        s.configure(CACHES={
            '_clear_defaults': True,
            'temp': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}
        })
        self.assertDictEqual(s.CACHES, {
            '_clear_defaults': True,
            'temp': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}
        })

        # Also work on a subkey
        s = LazySettings()
        s.configure(CACHES={
            'default': {
                '_clear_defaults': True,
                'LOCATION': 'unique-snowflake',
            }
        })
        self.assertDictEqual(s.CACHES, {
            'default': {
                '_clear_defaults': True,
                'LOCATION': 'unique-snowflake',
            }
        })
开发者ID:2roy999,项目名称:django,代码行数:28,代码来源:tests.py

示例2: test_dict_setting

    def test_dict_setting(self):
        """
        Test that dictionary-type settings can be "complemented", that is existing
        setting keys/values are not overriden by user settings, but merged into the
        existing dict.
        """
        s = LazySettings()  # Start with fresh settings from global_settings.py
        # Simply overwriting the key
        s.configure(CACHES={'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}})
        self.assertEqual(s.CACHES['default']['BACKEND'],
                         'django.core.cache.backends.dummy.DummyCache')

        s = LazySettings()
        # More complex overwriting
        s.configure(CACHES={
            'default': {'LOCATION': 'unique-snowflake'},
            'temp': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}
        })
        self.assertDictEqual(s.CACHES, {
            'default': {
                'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
                'LOCATION': 'unique-snowflake'
            },
            'temp': {
                'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
            }
        })
开发者ID:2roy999,项目名称:django,代码行数:27,代码来源:tests.py

示例3: test_configure_initializes_logging

 def test_configure_initializes_logging(self):
     settings = LazySettings()
     settings.configure(
         LOGGING_CONFIG='regressiontests.logging_tests.tests.dictConfig')
     self.assertTrue(dictConfig.called)
开发者ID:Stunning,项目名称:django,代码行数:5,代码来源:tests.py

示例4: test_configure

    def test_configure(self):
        s = LazySettings()
        s.configure(SECRET_KEY='foo')

        self.assertTrue(s.is_overridden('SECRET_KEY'))
开发者ID:ricardoffv,项目名称:django-pizza,代码行数:5,代码来源:tests.py

示例5: test_usersettingsholder_repr

 def test_usersettingsholder_repr(self):
     lazy_settings = LazySettings()
     lazy_settings.configure(APPEND_SLASH=False)
     expected = '<UserSettingsHolder>'
     self.assertEqual(repr(lazy_settings._wrapped), expected)
开发者ID:DAWZayas-Projects,项目名称:TEJEDOR-RETUERTO-ALEJANDRO,代码行数:5,代码来源:tests.py

示例6: handle_django_settings

def handle_django_settings(filename):
    '''Attempts to load a Django project and get package dependencies from
    settings.

    Tested using Django 1.4 and 1.8. Not sure if some nuances are missed in
    the other versions.
    '''
    old_sys_path = sys.path[:]
    dirpath = os.path.dirname(filename)
    project = os.path.basename(dirpath)
    cwd = os.getcwd()
    project_path = os.path.normpath(os.path.join(dirpath, '..'))
    if project_path not in sys.path:
        sys.path.insert(0, project_path)
    os.chdir(project_path)

    project_settings = '{}.settings'.format(project)
    os.environ['DJANGO_SETTINGS_MODULE'] = project_settings

    try:
        import django
        # Sanity
        django.setup = lambda: False
    except ImportError:
        log.error('Found Django settings, but Django is not installed.')
        return

    log.warn('Loading Django Settings (Using {}): {}'
                    .format(django.get_version(), filename))

    from django.conf import LazySettings

    installed_apps = set()
    settings_imports = set()

    try:
        settings = LazySettings()
        settings._setup()
        for k, v in vars(settings._wrapped).items():
            if k not in _excluded_settings and re.match(r'^[A-Z_]+$', k):
                # log.debug('Scanning Django setting: %s', k)
                scan_django_settings(v, settings_imports)

        # Manually scan INSTALLED_APPS since the broad scan won't include
        # strings without a period in it .
        for app in getattr(settings, 'INSTALLED_APPS', []):
            if hasattr(app, '__file__') and getattr(app, '__file__'):
                imp, _ = utils.import_path_from_file(getattr(app, '__file__'))
                installed_apps.add(imp)
            else:
                installed_apps.add(app)
    except Exception as e:
        log.error('Could not load Django settings: %s', e)
        log.debug('', exc_info=True)
        return

    if not installed_apps or not settings_imports:
        log.error('Got empty settings values from Django settings.')

    try:
        from django.apps.registry import apps, Apps, AppRegistryNotReady
        # Django doesn't like it when the initial instance of `apps` is reused,
        # but it has to be populated before other instances can be created.
        if not apps.apps_ready:
            apps.populate(installed_apps)
        else:
            apps = Apps(installed_apps)

        start = time.time()
        while True:
            try:
                for app in apps.get_app_configs():
                    installed_apps.add(app.name)
            except AppRegistryNotReady:
                if time.time() - start > 10:
                    raise Exception('Bail out of waiting for Django')
                log.debug('Waiting for apps to load...')
                continue
            break
    except Exception as e:
        log.debug('Could not use AppConfig: {}'.format(e))

    # Restore before sub scans can occur
    sys.path[:] = old_sys_path
    os.chdir(cwd)

    for item in settings_imports:
        need_scan = item.startswith(_filescan_modules)
        yield ('django', item, project_path if need_scan else None)

    for app in installed_apps:
        need_scan = app.startswith(project)
        yield ('django', app, project_path if need_scan else None)
开发者ID:tweekmonster,项目名称:moult,代码行数:93,代码来源:django.py

示例7: test_nonupper_settings_ignored_in_default_settings

 def test_nonupper_settings_ignored_in_default_settings(self):
     s = LazySettings()
     s.configure(SimpleNamespace(foo='bar'))
     with self.assertRaises(AttributeError):
         getattr(s, 'foo')
开发者ID:EmadMokhtar,项目名称:django,代码行数:5,代码来源:tests.py

示例8: test_nonupper_settings_prohibited_in_configure

 def test_nonupper_settings_prohibited_in_configure(self):
     s = LazySettings()
     with self.assertRaisesMessage(TypeError, "Setting 'foo' must be uppercase."):
         s.configure(foo='bar')
开发者ID:EmadMokhtar,项目名称:django,代码行数:4,代码来源:tests.py

示例9: getattr

# -*- coding: utf-8 -*-

DJANGO_REQUEST_ENABLE_SETTING = 'DJANGO_REQUEST_ENABLE'
DJANGO_REQUEST_LOGFILE_SETTING = 'DJANGO_REQUEST_LOGFILE'
REQUEST_ID_HEADER_SETTING = 'DJANGO_REQUEST_LOG_REQUEST_ID_HEADER'
REQUEST_ID_RESPONSE_HEADER_SETTING = 'DJANGO_REQUEST_SET_REQUEST_ID_HEADER'
NO_REQUEST_ID = '-'

from django.conf import settings, LazySettings
from django_request_logger.log import LOGGING
import threading

__version__ = "0.1"

# ThreadLocal - dirty but does the job
local = threading.local()

if getattr(settings, DJANGO_REQUEST_ENABLE_SETTING, True):
    # override any existing logging configuration
    settings.LOGGING = LOGGING

    # create a new Settings object and pass in our settings,
    # we don't need/use the new Settings object, it is just to
    # get the private _configure_logging() method called
    unused_settings = LazySettings()
    unused_settings.configure(default_settings=settings)
开发者ID:eht16,项目名称:django-request-logger,代码行数:26,代码来源:__init__.py


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