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


Python persistent_dict.PersistentDict类代码示例

本文整理汇总了Python中durus.persistent_dict.PersistentDict的典型用法代码示例。如果您正苦于以下问题:Python PersistentDict类的具体用法?Python PersistentDict怎么用?Python PersistentDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_delete

 def test_delete(self):
     connection = Connection(MemoryStorage())
     pd = PersistentDict((x, True) for x in range(10))
     connection.root['x'] = pd
     connection.commit()
     del pd[1]
     assert pd._p_is_unsaved()
开发者ID:ctismer,项目名称:durus,代码行数:7,代码来源:test_persistent_dict.py

示例2: test_copy

 def test_copy(self):
     connection = Connection(MemoryStorage())
     pd = PersistentDict((x, True) for x in range(10))
     pd2 = pd.copy()
     assert pd == pd2
     pd[1] = 34
     assert pd != pd2
开发者ID:ctismer,项目名称:durus,代码行数:7,代码来源:test_persistent_dict.py

示例3: test_iter

 def test_iter(self):
     pd = PersistentDict((x, True) for x in range(10))
     if hasattr({}, 'iteritems'):
         assert list(pd.iteritems()) == list(zip(pd.iterkeys(), pd.itervalues()))
     else:
         assert list(pd.items()) == list(zip(pd.keys(), pd.values()))
     assert list(pd.items()) == list(zip(pd.keys(), pd.values()))
开发者ID:ctismer,项目名称:durus,代码行数:7,代码来源:test_persistent_dict.py

示例4: __init__

	def __init__(self, name):
		super(NetworkDevice, self).__init__()
		self.name = self.hostname = str(name)
		self.INTERFACEMAP = PersistentDict()
		self._interfaces = PersistentDict()
		self.data_interfaces = PersistentList()
		self.admin_interface = None
		self.initialize() # subclass interface
开发者ID:pruan,项目名称:TestDepot,代码行数:8,代码来源:netobjects.py

示例5: CUser

class CUser(Persistent):
    def __init__(self, jid):
        self.jid = jid
        self.items_pending = PersistentList() # [CItem, ...]
        self.config = PersistentDict()
        self.feeds = PersistentDict() # {CFeed: send first notification?}
        
        
    def __len__(self):
        return len(self.feeds)
            
        
    def subs_feed(self, feeditem, sendFirstNoti=False):
        """Add a feed item in 'feeds' dict."""
        if not self.has_feed(feeditem):
            self.feeds[feeditem] = sendFirstNoti
            return True
        return False
        
        
    def unsubs_feed(self, feeditem):
        """Delete a feed item from 'feeds' dict."""
        if self.has_feed(feeditem):
            del self.feeds[feeditem]
            return True
        return False
            
            
    def has_feed(self, feeditem):
        """Search the url feed in 'feeds' dict"""
        for x in self.feeds.keys():
            if x.url == feeditem.url:
                return True
        return False
        
        
    def enableNotifications(self, feeditem):
        self.feeds[feeditem] = True
        
        
    def getNotification(self, feeditem):
        return self.feeds[feeditem]
        
    
    def clear_items(self):
        self.items_pending = PersistentList()
        
        
    def setup(self, action, mode):
        self.config[action] = mode
        return True
        
        
    def getConfig(self, key):
        return self.config.get(key)
开发者ID:BackupTheBerlios,项目名称:jfn-svn,代码行数:55,代码来源:users.py

示例6: categoricalIndex

class categoricalIndex(Persistent):
    def __init__(self, name, low, high, legalValues):
        self.name = name
        self.data = PersistentDict()
        for l in legalValues:
            self.data[l] = PersistentSet()
    
    def __getitem__(self, keys):
        if isinstance(keys,slice):
            raise Exception('A categorical index cannot be sliced.')
        elif isinstance(keys,set):
            keys = list(keys)
        elif not isinstance(keys,list):
            keys = [keys]
        
        # start with the smallest set
        smallestSize=sys.maxint
        smallestKey=None
        for k in keys:
            if len(self.data[k]) < smallestSize:
                smallestSize = len(self.data[k])
            smallestKey = k
        if smallestKey == None:
            return set()
        
        results = set(self.data[smallestKey])
        for k in keys:
            if k == smallestKey:
                continue
            results.intersection_update(self.data[k])
        return results
    
    def __setitem__(self, key, value):
        if not self.data.has_key(key):
            raise Exception('Unknown categorical key: %s' % key)
        else:
            self.data[key].add(value)
    
    def count(self, keys):
        if isinstance(keys,slice):
            raise Exception('A categorical index cannot be sliced.')
        elif isinstance(keys,set):
            keys = list(keys)
        elif not isinstance(keys,list):
            keys = [keys]
        
        count = 0
        for k in keys:
            count += len(self.data[k])
        return count
    
    def has_key(self, key):
        return self.data.has_key(key)
开发者ID:alex-r-bigelow,项目名称:compreheNGSive,代码行数:53,代码来源:structures.py

示例7: Note

class Note(Persistent, MutableMapping):
    interface.implements(INote)

    def __init__(self, doc, id, props={}):
        self.document = doc
        self.id = id
        self._props = PersistentDict(props)
        self._children = PersistentList()

    def __setitem__(self, key, value):
        if value is None:
            del self._props[key]
        else:
            self._props[key] = value
        for subscriber in self.document.subscribers:
            if hasattr(subscriber, 'prop_change'):
                subscriber.prop_change(self, key, value)

    def __getitem__(self, key):
        return self._props[key]

    def __delitem__(self, key):
        raise NotImplementedError

    def keys(self):
        return self._props.keys()

    def children_ids(self):
        for child_id in self._children:
            yield child_id

    def children(self):
        for child_id in self._children:
            yield self.document.get_note(child_id)
开发者ID:mgax,项目名称:notespace,代码行数:34,代码来源:document.py

示例8: PersistentOrderedDict

class PersistentOrderedDict(Persistent):
    '''
    This class implements the same interface as the `collections.OrderedDict`
    class from the standard library, but uses `persistent` data types for Durus
    support.
    '''
    def __init__(self, items=None):
        self.key_index = PersistentList()
        self.data = PersistentDict()
        if items:
            for k, v in items:
                self[k] = v

    def keys(self):
        return self.key_index[:]

    def __setitem__(self, k, v):
        if k not in self.data:
            self.key_index.append(k)
        self.data[k] = v

    def items(self):
        return [(k, v) for k, v in self.iteritems()]

    def iteritems(self):
        for k in self.key_index:
            yield k, self.data[k]

    def values(self):
        return [v for k, v in self.iteritems()]

    def get(self, key):
        return self.data.get(key)

    def __delitem__(self, key):
        del self.data[key]
        i = self.key_index.index(key)
        del self.key_index[i]

    def __getitem__(self, key):
        return self.data[key]

    def move_to_end(self, key, last=True):
        assert(key in self)
        items = []
        for k, v in self.items():
            if k != key:
                items.append((k, v))
                del self[k]
        if last:
            items.append((key, self[key]))
            del self[key]
        for k, v in items:
            self[k] = v

    def __contains__(self, key):
        return key in self.data

    def __len__(self):
        return len(self.key_index)
开发者ID:cfobel,项目名称:python___persistent_helpers,代码行数:60,代码来源:durus_types.py

示例9: setdefault

 def setdefault(self):
     pd = PersistentDict()
     assert pd.setdefault("1", []) == []
     assert pd["1"] == []
     pd.setdefault("1", 1).append(1)
     assert pd["1"] == [1]
     pd.setdefault("1", [])
     assert pd["1"] == [1]
     pd.setdefault("1", 1).append(2)
     assert pd["1"] == [1, 2]
开发者ID:pfw,项目名称:Durus,代码行数:10,代码来源:utest_persistent_dict.py

示例10: test_setdefault

 def test_setdefault(self):
     pd = PersistentDict()
     assert pd.setdefault('1', []) == []
     assert pd['1'] == []
     pd.setdefault('1', 1).append(1)
     assert pd['1'] == [1]
     pd.setdefault('1', [])
     assert pd['1'] == [1]
     pd.setdefault('1', 1).append(2)
     assert pd['1'] == [1, 2]
开发者ID:ctismer,项目名称:durus,代码行数:10,代码来源:test_persistent_dict.py

示例11: CFeeds

class CFeeds(Persistent):
    def __init__(self):
        self.data = PersistentDict() # {url feed: CFeed}
        
        
    def __getitem__(self, key):
        return self.data[key]

    def __setitem__(self, key, item):
        self.data[key] = item

    def __delitem__(self, key):
        self._p_note_change()
        del self.data[key]

    def get(self, key):
        return self.data.get(key)

    def keys(self):
        return self.data.keys()

    def values(self):
        return self.data.values()
开发者ID:BackupTheBerlios,项目名称:jfn-svn,代码行数:23,代码来源:feeds.py

示例12: test_fromkeys

 def test_fromkeys(self):
     x = PersistentDict.fromkeys(dict(a=2), value=4)
     assert isinstance(x, PersistentDict)
     assert dict(x) == dict(a=4)
开发者ID:ctismer,项目名称:durus,代码行数:4,代码来源:test_persistent_dict.py

示例13: test_pops

 def test_pops(self):
     pd = PersistentDict((x, True) for x in range(10))
     pd.pop(3)
     assert 3 not in pd
     assert type(pd.popitem()) is tuple
开发者ID:ctismer,项目名称:durus,代码行数:5,代码来源:test_persistent_dict.py

示例14: __init__

 def __init__(self):
     self.data = PersistentDict() # {url feed: CFeed}
开发者ID:BackupTheBerlios,项目名称:jfn-svn,代码行数:2,代码来源:feeds.py

示例15: __init__

 def __init__(self, items=None):
     self.key_index = PersistentList()
     self.data = PersistentDict()
     if items:
         for k, v in items:
             self[k] = v
开发者ID:cfobel,项目名称:python___persistent_helpers,代码行数:6,代码来源:durus_types.py


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