本文整理汇总了Python中persistent.mapping.PersistentMapping类的典型用法代码示例。如果您正苦于以下问题:Python PersistentMapping类的具体用法?Python PersistentMapping怎么用?Python PersistentMapping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PersistentMapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_root
def create_root(storage, oid=z64, check_new=True):
"""
Creates public or private root in storage.
Root has the type PersistentMapping.
:param storage: ZODB storage to create the root in
:param str oid: Object id to give to the root (z64 is global root)
:param bool check_new: If True, do nothing if the root exists
"""
if check_new:
try:
storage.load(oid, '')
return
except KeyError:
pass
# Create the database's root in the storage if it doesn't exist
from persistent.mapping import PersistentMapping
root = PersistentMapping()
# Manually create a pickle for the root to put in the storage.
# The pickle must be in the special ZODB format.
file = BytesIO()
p = Pickler(file, _protocol)
p.dump((root.__class__, None))
p.dump(root.__getstate__())
t = transaction.Transaction()
t.description = 'initial database creation'
storage.tpc_begin(t)
storage.store(oid, None, file.getvalue(), '', t)
storage.tpc_vote(t)
storage.tpc_finish(t)
示例2: __init__
def __init__(self):
PersistentMapping.__init__(self)
self.blogs = IOBTree()
self.categories = Categories()
self.tags = Tags()
示例3: checkPackKeepNewObjects
def checkPackKeepNewObjects(self):
# Packing should not remove objects created or modified after
# the pack time, even if they are unreferenced.
db = DB(self._storage)
try:
# add some data to be packed
c = db.open()
extra1 = PersistentMapping()
c.add(extra1)
extra2 = PersistentMapping()
c.add(extra2)
transaction.commit()
# Choose the pack time
now = packtime = time.time()
while packtime <= now:
time.sleep(0.1)
packtime = time.time()
while packtime == time.time():
time.sleep(0.1)
extra2.foo = "bar"
extra3 = PersistentMapping()
c.add(extra3)
transaction.commit()
self._storage.pack(packtime, referencesf)
# extra1 should have been garbage collected
self.assertRaises(KeyError, self._storage.load, extra1._p_oid, "")
# extra2 and extra3 should both still exist
self._storage.load(extra2._p_oid, "")
self._storage.load(extra3._p_oid, "")
finally:
db.close()
示例4: __init__
def __init__(self):
self.filename = None
self.package = None
self.start_time = None
self.end_time = None
self._entities = PersistentMapping()
"""contains all entities in the form of (simplified):
{
class_name: (
[entitiy, ...],
Binary tree of all entities (key: primary_identifier)
)
}
"""
self._events = OOBTree.TreeSet()
"""contains all entities
"""
self._event_index = PersistentMapping()
"""contains indices for events in the form of
{
class_name: {
key: Binary Tree {
attribute_value: set(event, ...)
}
}
}
"""
self.plugins = {}
self.hashes = {}
示例5: __init__
def __init__(self):
"""
"""
self.rankedNouns = PersistentMapping()
self.rankedNPs = PersistentMapping()
self.extractor = getUtility(ITermExtractor)
self.friendlyTypes = PersistentList()
示例6: test_set_acl_set_resource_dirty
def test_set_acl_set_resource_dirty():
"""Regression test."""
from persistent.mapping import PersistentMapping
from . import set_acl
resource = PersistentMapping()
resource._p_jar = Mock() # make _p_changed property work
set_acl(resource, [('Deny', 'role:creator', 'edit')])
assert resource._p_changed is True
示例7: __init__
def __init__(self, content_id, data=None, **kwargs):
if not data:
data = {}
PersistentMapping.__init__(self)
Base.__init__(self, content_id, data=data)
self._order = []
示例8: test_set_acl_set_resource_dirty
def test_set_acl_set_resource_dirty():
from . import set_acl
from pyramid.security import Deny
from persistent.mapping import PersistentMapping
resource = PersistentMapping()
resource._p_jar = Mock() # make _p_changed property work
set_acl(resource, [(Deny, 'role:creator', 'edit_comment')])
assert resource._p_changed is True
示例9: __init__
def __init__(self, crumb_name, owner, id):
PersistentMapping.__init__(self)
self.item_number = 0
self.timestamp = datetime.now()
self.id = id
self.owner = owner
# Name used in breadcrumps
self.crumb_name = crumb_name
示例10: __init__
def __init__(self, name, parent, uid, gid, mode, mtime_ns):
FileMeta.__init__(self, name, parent, uid, gid, mode, mtime_ns)
self.adds = PersistentMapping()
self.removes = PersistentMapping()
self.meta_changes = PersistentMapping() # name => ((to_uid, to_gid, to_mode), (from_uid, from_gid, from_mode))
self.subdirs = PersistentMapping()
self.state = PatchedDirectory.EXISTING
示例11: test_persistent_mapping
def test_persistent_mapping(self):
value = PersistentMapping({'foo': 'bar'})
self.assertEquals({u'foo': u'bar'}, json_compatible(value))
self.assertEquals('{"foo": "bar"}', json.dumps(json_compatible(value)))
self.assertIsInstance(json_compatible(value.keys()[0]),
unicode,
'Dict keys should be converted recursively.')
self.assertIsInstance(json_compatible(value.values()[0]),
unicode,
'Dict values should be converted recursively.')
示例12: _data
def _data(self):
"""Return dictionary to store data."""
sheets_data = getattr(self.context, '_sheets', None)
if sheets_data is None:
sheets_data = PersistentMapping()
setattr(self.context, '_sheets', sheets_data)
data = sheets_data.get(self._data_key, None)
if data is None:
data = PersistentMapping()
sheets_data[self._data_key] = data
return data
示例13: __init__
def __init__(self, log):
#self.start_time = log['start_time']
#self.players = log['players']
#self.units = log['units']
#self.grid = log['grid']
#self['init_locs'] = log['init_locs']
PersistentMapping.__init__(self, init_locs=log['init_locs'],
start_time=log['start_time'],
units=log['units'],
grid=log['grid'],
owners=log['owners'],)
示例14: __setitem__
def __setitem__(self, key, value):
if key in self.data:
raise TypeError("Can't update key in AppendOnlyDict!")
if isinstance(value, (dict, list)):
raise TypeError("Can't add non-persistent mutable subobjects!")
if not PY3:
from types import InstanceType
if type(value) is InstanceType:
if not isinstance(value, Persistent):
raise TypeError(
"Can't add non-persistent mutable subobjects!")
PersistentMapping.__setitem__(self, key, value)
示例15: record_change
def record_change(self, context, _userid):
if self.new:
key = self.make_key(context)
data = self.data
context['gallery'][key] = PersistentMapping(data)
context['gallery'][key].order = self.order
else:
key = self.key
if self.delete:
del context['gallery'][key]
else:
context['gallery'][key].order = self.order