我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用django.utils.functional.empty()。
def __iter__(self): if self._wrapped is empty: self._setup() return iter(self._wrapped)
def __reversed__(self): if self._wrapped is empty: self._setup() return reversed(self._wrapped)
def __len__(self): if self._wrapped is empty: self._setup() return len(self._wrapped)
def __getitem__(self, idx): if self._wrapped is empty: self._setup() return self._wrapped[idx]
def __init__(self, *args, **kwargs): super(DefaultStorageFinder, self).__init__(*args, **kwargs) base_location = getattr(self.storage, 'base_location', empty) if not base_location: raise ImproperlyConfigured("The storage backend of the " "staticfiles finder %r doesn't have " "a valid location." % self.__class__)
def __repr__(self): # Hardcode the class name as otherwise it yields 'Settings'. if self._wrapped is empty: return '<LazySettings [Unevaluated]>' return '<LazySettings "%(settings_module)s">' % { 'settings_module': self._wrapped.SETTINGS_MODULE, }
def __getattr__(self, name): if self._wrapped is empty: self._setup(name) return getattr(self._wrapped, name)
def configure(self, default_settings=global_settings, **options): """ Called to manually configure the settings. The 'default_settings' parameter sets where to retrieve any unspecified values from (its argument must support attribute access (__getattr__)). """ if self._wrapped is not empty: raise RuntimeError('Settings already configured.') holder = UserSettingsHolder(default_settings) for name, value in options.items(): setattr(holder, name, value) self._wrapped = holder
def request(self, resource, data): if self._wrapped is empty: self._setup() default = { 'key': self._wrapped.google_apikey, } default.update(data) url = 'https://www.googleapis.com/youtube/v3/%s' % resource response = requests.get(url, params=default) if response.status_code == 200: return response.json() else: raise ValueError('API response: %s' % response.status_code)
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)) # store the settings module in case someone later cares self.SETTINGS_MODULE = settings_module mod = importlib.import_module(self.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.") 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()
def __getattr__(self, name): if self._wrapped is empty: self._setup() result = self._wrapped.get(name, None) if result is None: result = getattr(self._wrapped, name) return result
def __getattr__(self, name): if self._wrapped is empty: self._setup() val = getattr(self._manager, name, None) if val is None: val = getattr(self._wrapped, name) return val
def extract_lazy_object(lo): """ Unwrap a LazyObject and return the inner object. Whatever that may be. ProTip: This is relying on `django.utils.functional.empty`, which may or may not be removed in the future. It's 100% undocumented. """ if not hasattr(lo, '_wrapped'): return lo if lo._wrapped is empty: lo._setup() return lo._wrapped