本文整理汇总了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))