本文整理匯總了Python中django.utils.functional.LazyObject方法的典型用法代碼示例。如果您正苦於以下問題:Python functional.LazyObject方法的具體用法?Python functional.LazyObject怎麽用?Python functional.LazyObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.utils.functional
的用法示例。
在下文中一共展示了functional.LazyObject方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: storage_factory
# 需要導入模塊: from django.utils import functional [as 別名]
# 或者: from django.utils.functional import LazyObject [as 別名]
def storage_factory(collector):
class DebugConfiguredStorage(LazyObject):
def _setup(self):
configured_storage_cls = get_storage_class(settings.STATICFILES_STORAGE)
class DebugStaticFilesStorage(configured_storage_cls):
def __init__(self, collector, *args, **kwargs):
super(DebugStaticFilesStorage, self).__init__(*args, **kwargs)
self.collector = collector
def url(self, path):
self.collector.collect(path)
return super(DebugStaticFilesStorage, self).url(path)
self._wrapped = DebugStaticFilesStorage(collector)
return DebugConfiguredStorage
示例2: __init__
# 需要導入模塊: from django.utils import functional [as 別名]
# 或者: from django.utils.functional import LazyObject [as 別名]
def __init__(self, storage=None, *args, **kwargs):
if storage is not None:
self.storage = storage
if self.storage is None:
raise ImproperlyConfigured("The staticfiles storage finder %r "
"doesn't have a storage class "
"assigned." % self.__class__)
# Make sure we have an storage instance here.
if not isinstance(self.storage, (Storage, LazyObject)):
self.storage = self.storage()
super(BaseStorageFinder, self).__init__(*args, **kwargs)
示例3: __init__
# 需要導入模塊: from django.utils import functional [as 別名]
# 或者: from django.utils.functional import LazyObject [as 別名]
def __init__(self, storage=None, *args, **kwargs):
if storage is not None:
self.storage = storage
if self.storage is None:
raise ImproperlyConfigured("The staticfiles storage finder %r "
"doesn't have a storage class "
"assigned." % self.__class__)
# Make sure we have a storage instance here.
if not isinstance(self.storage, (Storage, LazyObject)):
self.storage = self.storage()
super().__init__(*args, **kwargs)
示例4: lazy_wrap
# 需要導入模塊: from django.utils import functional [as 別名]
# 或者: from django.utils.functional import LazyObject [as 別名]
def lazy_wrap(self, wrapped_object):
"""
Wrap the given object into a LazyObject
"""
class AdHocLazyObject(LazyObject):
def _setup(self):
self._wrapped = wrapped_object
return AdHocLazyObject()
示例5: test_contains
# 需要導入模塊: from django.utils import functional [as 別名]
# 或者: from django.utils.functional import LazyObject [as 別名]
def test_contains(self):
test_data = [
('c', 'abcde'),
(2, [1, 2, 3]),
('a', {'a': 1, 'b': 2, 'c': 3}),
(2, {1, 2, 3}),
]
for needle, haystack in test_data:
self.assertIn(needle, self.lazy_wrap(haystack))
# __contains__ doesn't work when the haystack is a string and the needle a LazyObject
for needle_haystack in test_data[1:]:
self.assertIn(self.lazy_wrap(needle), haystack)
self.assertIn(self.lazy_wrap(needle), self.lazy_wrap(haystack))