本文整理汇总了Python中zope.annotation.interfaces.IAnnotations.iteritems方法的典型用法代码示例。如果您正苦于以下问题:Python IAnnotations.iteritems方法的具体用法?Python IAnnotations.iteritems怎么用?Python IAnnotations.iteritems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zope.annotation.interfaces.IAnnotations
的用法示例。
在下文中一共展示了IAnnotations.iteritems方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import iteritems [as 别名]
def __call__(self):
draftAnnotations = IAnnotations(self.draft)
targetAnnotations = IAnnotations(self.target)
for key, value in draftAnnotations.iteritems():
if key.startswith(ANNOTATIONS_KEY_PREFIX):
targetAnnotations[key] = value
annotationsDeleted = getattr(self.draft, '_proxyAnnotationsDeleted', set())
for key in annotationsDeleted:
if key.startswith(ANNOTATIONS_KEY_PREFIX) and key in targetAnnotations:
del targetAnnotations[key]
示例2: cellml_v0_2tov0_3
# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import iteritems [as 别名]
def cellml_v0_2tov0_3(context):
"""Migration script specific to models.cellml.org."""
import traceback
from zope.annotation.interfaces import IAnnotations
from pmr2.app.annotation.interfaces import IExposureFileNote
try:
from pmr2.app.exposure.browser.browser import \
ExposureFileTypeAnnotatorForm
except ImportError:
from pmr2.app.browser.exposure import ExposureFileTypeAnnotatorForm
try:
from pmr2.app.adapter import ExposureSourceAdapter
except ImportError:
from pmr2.app.exposure.adapter import ExposureSourceAdapter
logger = getLogger('pmr2.app')
catalog = getToolByName(context, 'portal_catalog')
props = getToolByName(context, 'portal_properties')
# This is the path to the ExposureFileType object defined for the
# CellML type. It needs to be set using the portal_properties tool.
cellml_type = props.site_properties.getProperty('cellml_type_path')
cellml_force = props.site_properties.getProperty('cellml_force_all')
cellml_notes = set(['cmeta', 'basic_mathml', 'basic_ccode'])
cellml_type_obj = cellml_type and catalog(path=cellml_type)[0].getObject()
cellml_type_notes = cellml_type_obj and cellml_type_obj.views
cellml_type_tags = cellml_type_obj and cellml_type_obj.tags or ()
def migrate(context, annotations, oldnotes):
# construct a set of old notes to verify whether or not to use
# the CellML profile.
oldnote_set = set(oldnotes)
session_file = None
if 'opencellsession' in oldnote_set:
# It can die here because something wrong with getting the
# vocabulary from the manifest.
session_file = annotations['opencellsession'].filename
# discard this.
oldnote_set.remove('opencellsession')
groups = {}
groups['opencellsession'] = [('filename', session_file),]
if cellml_force or (cellml_type_notes and oldnote_set == cellml_notes):
context.file_type = cellml_type
# update views
context.views = cellml_type_notes
context.setSubject(cellml_type_tags)
groups['license_citation'] = [('format', u'cellml_rdf_metadata')]
groups['source_text'] = [('langtype', u'xml')]
else:
# reuse the existing views, and unknown profile.
pass
# annotate using the form.
form = ExposureFileTypeAnnotatorForm(context, None)
# It can die here too because of various reasons (workspace
# missing, malformed input data, incompatibilities of existing
# data with new formatting scheme, stray electrons, etc.).
form._annotate(groups)
files = catalog(portal_type='ExposureFile')
for file in files:
context = file.getObject()
annotations = IAnnotations(context)
oldnotes = []
for k, v in annotations.iteritems():
if not IExposureFileNote.providedBy(v):
continue
# we only want annotations created in v0.2, which is
# identified by the usage of non-prefixed keys.
if k in context.views:
oldnotes.append(k)
if not oldnotes:
# not doing anything since old notes are not found.
logger.info('`%s` has no pmr2.app v0.2 styled notes to migrate.' %
context.absolute_url_path())
continue
try:
migrate(context, annotations, oldnotes)
except:
logger.error('Failed to migrate `%s` - it may be left in an '
'inconsistent state!' % context.absolute_url_path())
logger.warning(traceback.format_exc())
# naturally don't remove the old notes if we blew up.
continue
# remove old notes
for k in oldnotes:
del annotations[k]
logger.info('`%s` had its notes migrated successfully.' %
context.absolute_url_path())