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


Python WeakValueDictionary.__delitem__方法代码示例

本文整理汇总了Python中weakref.WeakValueDictionary.__delitem__方法的典型用法代码示例。如果您正苦于以下问题:Python WeakValueDictionary.__delitem__方法的具体用法?Python WeakValueDictionary.__delitem__怎么用?Python WeakValueDictionary.__delitem__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weakref.WeakValueDictionary的用法示例。


在下文中一共展示了WeakValueDictionary.__delitem__方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __delitem__

# 需要导入模块: from weakref import WeakValueDictionary [as 别名]
# 或者: from weakref.WeakValueDictionary import __delitem__ [as 别名]
    def __delitem__(self, key):
        # can't efficiently find item in queue to delete, check
        # boundaries. otherwise just wait till next cache purge
        while len(self.queue) and self.queue[0][0] == key:
            # item at left end of queue pop it since it'll be appended
            # to right
            self.queue.popleft()

        while len(self.queue) and self.queue[-1][0] == key:
            # item at right end of queue pop it since it'll be
            # appended again
            self.queue.pop()

        return WeakValueDictionary.__delitem__(self, key)
开发者ID:Veterini,项目名称:translate,代码行数:16,代码来源:lru.py

示例2: SilkArray

# 需要导入模块: from weakref import WeakValueDictionary [as 别名]
# 或者: from weakref.WeakValueDictionary import __delitem__ [as 别名]

#.........这里部分代码省略.........

    def _set_prop(self, item, value, prop_setter=_prop_setter_any):
        if self._elementary:
            if self.storage == "numpy":
                _set_numpy_ele_prop(self, item, value)
            else:
                if item < 0:
                    item = self._len - item
                elif item >= self._len:
                    raise IndexError(item)
                self._data[item] = self._element(value)
        else:
            child = self._get_child(item)
            child.set(value,prop_setter=prop_setter)

    def __setitem__(self, item, value):
        if isinstance(item, slice):
            start, stop, stride = item.indices(self._len)
            indices = list(range(start, stop, stride))
            if len(indices) != len(value):
                msg = "Cannot assign to a slice of length %d using \
a sequence of length %d"
                raise IndexError(msg % (len(indices), len(value)))
            for n in indices:
                self._set_prop(n, value[n])
            return
        elif isinstance(item, int):
            self._set_prop(item, value)
        else:
            msg = "{0} indices must be integers or slices, not {1}"
            raise TypeError(msg.format(self.__class__.__name__,
                                       item.__class__.__name__))

    def __delitem__(self, item):
        if isinstance(item, slice):
            start, stop, stride = item.indices(self._len)
            indices = list(range(start, stop, stride))
            for n in reversed(indices):
                self.pop(n)
            return
        if not isinstance(item, int):
            msg = "{0} indices must be integers or slices, not {1}"
            raise TypeError(msg.format(self.__class__.__name__,
                                       item.__class__.__name__))
        self.pop(item)

    def pop(self, index=-1):
        if not isinstance(index, int):
            msg = "{0} indices must be integers, not {1}"
            raise TypeError(msg.format(self.__class__.__name__,
                                       index.__class__.__name__))
        if index < 0:
            index += self._len
        if index < 0:
            raise IndexError
        if self.storage == "numpy":
            ret_data = datacopy(self._data[index])
            ret_lengths = None
            if self._arity > 1:
                ret_lengths = _get_lenarray_empty(ret_data.shape)
            ret = self._element(
                    _mode="from_numpy",
                    data_store=ret_data,
                    len_data_store=ret_lengths,
                )
            self._data[index:self._len-1] = self._data[index+1:self._len]
开发者ID:agoose77,项目名称:seamless,代码行数:70,代码来源:silkarray.py

示例3: thread_container

# 需要导入模块: from weakref import WeakValueDictionary [as 别名]
# 或者: from weakref.WeakValueDictionary import __delitem__ [as 别名]
class thread_container(blist):
    '''
    Base class for thread containers. This container requires "hints" in
    order to work. Okay, it requires more than hints. It needs every
    conversation container to list its conversaton id.

    To be clear, thread_containers are used to merge related conversations
    into the same object, and are used to contain all emails/conversations
    in a folder or those found in a query.

    The thread_container holds the conversations inside itself (it is a list)
    and holds metadata that is used to instantly find related conversations
    in self._map when adding new messages to the container.

    While Jamie Zawinski makes some excellent arguments against storing
    which message belongs to which conversation, doing threading his way
    requires either loading every message into ram in order to find every
    message that goes in a conversation, or doing dozens of searches until
    everything we find everything. This eats up lots of ram unfortunately. :(
    '''
    __slots__ = ('_map')
    #__metaclass__ = MetaSuper
    def __init__(self):
        #self._map = lazy_refmap(self, 'nique_terms')
        #self._map = {}
        self._map = WeakValueDictionary()


    def datesort(self):
        '''
        Sort conversations so newest are at the top.
        '''
        self.sort(key=attrgetter('last_update'), reverse=True)

    def __getitem__(self, idx):
        '''
        If the key we're given is an integer, what's being asked for is a
        message at index idx. Otherwise we've been given a string and are being
        asked to look up something in the lookup table instead.
        '''
        try: idx.__int__
        except AttributeError: return self._map[idx]
        else: return super(thread_container, self).__getitem__(idx)
        #else: return self.__super.__getitem__(idx)
    def __setitem__(self, idx, value):
        try: idx.__int__
        except AttributeError: return self._map.__setitem__(idx, value)
        else: return super(thread_container, self).__setitem__(idx, value)
        #else: return self.__super.__setitem__(idx, value)
    def __delitem__(self, idx):
        try: idx.__int__
        except AttributeError: return self._map.__delitem__(idx)
        else: return super(thread_container, self).__delitem__(idx)
        #else: return self.__super.__delitem__(idx)

        #def append(self, item):
            #    if type(item) is not conv_container:
                #        raise TypeError('Wrong type of container. Use a conv_container instead of %s' % type(item))
                #    return list.append(self, item)

    def join(self, item):
        '''
        To keep things lite and simple (translation: use the least amount of
        of ram possible while still keeping things fast), look conversations
        up only based upon their threadid.
        '''
        if type(item) is conv_container:
            try: return self[item.thread].merge(item)
            except KeyError:
                self.append(item)
                self[item.thread] = item
        elif type(item) is msg_container:
            raise TypeError('Unable to thread that.')
            #return self.join(conv_container(item))

    _thread = join

    def thread(self, msgs):
        #map(self._thread, threadmap.map(conv_factory, msgs) )
        map(self._thread, (conv_factory(x) for x in msgs) )
        self.datesort()
        return
开发者ID:dlobue,项目名称:nara,代码行数:84,代码来源:databasics.py


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