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


Python functional.LazyObject方法代码示例

本文整理汇总了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 
开发者ID:skorokithakis,项目名称:django-cloudflare-push,代码行数:19,代码来源:middleware.py

示例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) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:finders.py

示例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) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:13,代码来源:finders.py

示例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() 
开发者ID:nesdis,项目名称:djongo,代码行数:11,代码来源:test_lazyobject.py

示例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)) 
开发者ID:nesdis,项目名称:djongo,代码行数:16,代码来源:test_lazyobject.py


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