當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。