當前位置: 首頁>>代碼示例>>Python>>正文


Python persistent.Persistent方法代碼示例

本文整理匯總了Python中persistent.Persistent方法的典型用法代碼示例。如果您正苦於以下問題:Python persistent.Persistent方法的具體用法?Python persistent.Persistent怎麽用?Python persistent.Persistent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在persistent的用法示例。


在下文中一共展示了persistent.Persistent方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __getattribute__

# 需要導入模塊: import persistent [as 別名]
# 或者: from persistent import Persistent [as 別名]
def __getattribute__(self, attr):
        ga = persistent.Persistent.__getattribute__
        if attr.startswith(('_p_', '_v_')):
            return ga(self, attr)
        self._p_activate()
        return ga(self, attr) 
開發者ID:enkore,項目名稱:borgcube,代碼行數:8,代碼來源:models.py

示例2: _set_changed

# 需要導入模塊: import persistent [as 別名]
# 或者: from persistent import Persistent [as 別名]
def _set_changed(self, value):
        ghost = self._p_jar is not None and self._p_changed is None
        if ghost:
            self._evolve()
        persistent.Persistent._p_changed.__set__(self, value) 
開發者ID:enkore,項目名稱:borgcube,代碼行數:7,代碼來源:models.py

示例3: _p_mtime

# 需要導入模塊: import persistent [as 別名]
# 或者: from persistent import Persistent [as 別名]
def _p_mtime(self):
        ghost = self._p_jar is not None and self._p_changed is None
        if ghost:
            self._evolve()
        return persistent.Persistent._p_mtime.__get__(self) 
開發者ID:enkore,項目名稱:borgcube,代碼行數:7,代碼來源:models.py

示例4: kw_function_key_generator

# 需要導入模塊: import persistent [as 別名]
# 或者: from persistent import Persistent [as 別名]
def kw_function_key_generator(namespace, fn, to_str=compat.string_type):
    """Return a function that generates a string
    key, based on a given function as well as
    arguments to the returned function itself.

    This is used by :meth:`.CacheRegion.cache_on_arguments`
    to generate a cache key from a decorated function.

    It can be replaced using the ``function_key_generator``
    argument passed to :func:`.make_region`.

    """

    if namespace is None:
        namespace = '%s:%s' % (fn.__module__, fn.__name__)
    else:
        namespace = '%s:%s|%s' % (fn.__module__, fn.__name__, namespace)

    args = inspect.getargspec(fn)
    has_self = args[0] and args[0][0] in ('self', 'cls')
    def generate_key(*args, **kw):
        #if has_self:
        if has_self and args and isinstance(args[0], Persistent):
            # When the kw_function_key_generator is called via
            # the method, we get:
            # args = (<EDBAuthPlugin at /extranetPRIVR/acl_users/eap>, 'vincentfretin')
            # When called via method.invalidate we get:
            # args = ('vincentfretin',)
            args = args[1:]

        genkey = namespace + "|" + " ".join(
            [isinstance(arg, Persistent) and str(get_oid(arg, 'nooid')) or to_str(arg)
             for arg in args]
        )
        if kw:
            local_index = []
            for key, val in kw.items():
                local_index.append((to_str(key), to_str(val)))

            local_index.sort()
            for key, val in local_index:
                genkey += " %s:%s" % (key, val)

        return genkey
    return generate_key


#region_memcached = make_region(
#        function_key_generator=kw_function_key_generator,
#        key_mangler=sha1_mangle_key
#).configure(
#'dogpile.cache.memcached',
#expiration_time=3600,
#arguments={
#    'url': ["127.0.0.1:11211"],
#    'min_compress_len': 1000,
#    'distributed_lock': True,
#},
#) 
開發者ID:ecreall,項目名稱:lagendacommun,代碼行數:61,代碼來源:cache.py

示例5: discriminate

# 需要導入模塊: import persistent [as 別名]
# 或者: from persistent import Persistent [as 別名]
def discriminate(self, obj, default):
        """ See interface IIndexInjection """
        if callable(self.discriminator):
            value = self.discriminator(obj, _marker)
        else:
            value = getattr(obj, self.discriminator, _marker)

        if value is _marker:
            return default

        if isinstance(value, Persistent):
            raise ValueError('Catalog cannot index persistent object %s' %
                             value)

        if isinstance(value, Broken):
            raise ValueError('Catalog cannot index broken object %s' %
                             value)

        if not isinstance(value, dict):
            raise ValueError('Catalog can only index dict with '
                'attr and date keys, or date and recurdef keys, given %s' %
                             value)
        # examples:
        # {'attr': 'dates',
        #  'date': datetime.datetime.now()}
        # will get dates_recurrence attribute on the obj to get iCal string
        # for recurrence definition
        # or
        # {'date': datetime.datetime.now(),
        #  'recurdef': ICALSTRING}
        # no access to obj attributes at all

        date = value.get('date')
        default_recurdef = value.get('recurdef', _marker)
        if default_recurdef is not _marker:
            recurdef = default_recurdef
        else:
            attr_recurdef = value.get('attr') + '_recurrence'
            recurdef = getattr(obj, attr_recurdef, None)

        if callable(recurdef):
            recurdef = recurdef()

        if not recurdef:
            dates = [date]
        else:
            dates = recurrence_sequence_ical(date, recrule=recurdef)

        # dates is a generator
        return tuple(dates) 
開發者ID:ecreall,項目名稱:lagendacommun,代碼行數:52,代碼來源:dateindex.py


注:本文中的persistent.Persistent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。