標籤:default cal only 異常 condition elf this oba prope
摘自如題檔案內容,如有侵權,請聯絡 QQ 929054468 刪除
class Settings:
def __init__(self, settings_module):
# update this dict from global settings (but only for ALL_CAPS settings)
for setting in dir(global_settings):
if setting.isupper():
setattr(self, setting, getattr(global_settings, setting))
將本地模組 global_settings 中的屬性值匯入到執行個體對象中
# store the settings module in case someone later cares
self.SETTINGS_MODULE = settings_module
mod = importlib.import_module(self.SETTINGS_MODULE)
利用 importlib模組匯入新增的模組 SETTINGS_MODULE
tuple_settings = (
"INSTALLED_APPS",
"TEMPLATE_DIRS",
"LOCALE_PATHS",
)
self._explicit_settings = set()
for setting in dir(mod):
if setting.isupper():
setting_value = getattr(mod, setting)
if (setting in tuple_settings and
not isinstance(setting_value, (list, tuple))):
raise ImproperlyConfigured("The %s setting must be a list or a tuple. " % setting)
setattr(self, setting, setting_value)
self._explicit_settings.add(setting)
將新增的模組屬性值匯入到執行個體對象中
if not self.SECRET_KEY:
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
檢測新匯入的屬性值中有沒有 SECRET_KEY 屬性值,且不為空白
if self.is_overridden(‘DEFAULT_CONTENT_TYPE‘):
warnings.warn(‘The DEFAULT_CONTENT_TYPE setting is deprecated.‘, RemovedInDjango30Warning)
檢查屬性名稱 DEFAULT_CONTENT_TYPE 是否在新匯入的模組屬性中,否則進行warn提醒
if hasattr(time, ‘tzset‘) and self.TIME_ZONE:
# When we can, attempt to validate the timezone. If we can‘t find
# this file, no check happens and it‘s harmless.
zoneinfo_root = ‘/usr/share/zoneinfo‘
if (os.path.exists(zoneinfo_root) and not
os.path.exists(os.path.join(zoneinfo_root, *(self.TIME_ZONE.split(‘/‘))))):
raise ValueError("Incorrect timezone setting: %s" % self.TIME_ZONE)
# Move the time zone info into os.environ. See ticket #2315 for why
# we don‘t do this unconditionally (breaks Windows).
os.environ[‘TZ‘] = self.TIME_ZONE
time.tzset()
設定時區,首先會檢查 time 模組是否有 tzset 方法,和對象匯入的模組是否有TIME_ZONE屬性,根據TIME_ZONE在linux伺服器的 /usr/share/zoneinfo 尋找對應的時區,如果對應的時區檔案不存在,則拋出異常,
然後重新設定時區
def is_overridden(self, setting):
return setting in self._explicit_settings
def __repr__(self):
return ‘<%(cls)s "%(settings_module)s">‘ % {
‘cls‘: self.__class__.__name__,
‘settings_module‘: self.SETTINGS_MODULE,
}
django/conf/__init__.py/class_Settings