本文整理汇总了Python中zope.app.annotation.interfaces.IAnnotations类的典型用法代码示例。如果您正苦于以下问题:Python IAnnotations类的具体用法?Python IAnnotations怎么用?Python IAnnotations使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IAnnotations类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: registerPersistentConfig
def registerPersistentConfig(site, type_):
""" Try to get persistent pipeline configuration of given type (export or import)
and register it for use with transmogrifier.
"""
global CONFIGFILE
anno = IAnnotations(site)
key = '%s.%s' % (ANNOKEY, type_)
config = anno.has_key(key) and anno[key] or None
# unregister old config
name = 'persitent-%s' % type_
if name in configuration_registry._config_ids:
configuration_registry._config_ids.remove(name)
del configuration_registry._config_info[name]
# register new
if config is not None:
title = description = u'Persistent %s pipeline'
tf = tempfile.NamedTemporaryFile('w+t', suffix='.cfg')
tf.write(config)
tf.seek(0)
CONFIGFILE = tf
configuration_registry.registerConfiguration(name, title, description, tf.name)
return name
else:
return None
示例2: migrate
def migrate(self):
if self.is_updated():
return 'already migrated'
# set the appropriate list type based on the previous settings
# this may need to mark the appropriate interface on the mailing
# list as well
if self.context.moderated:
self.context.list_type = PostModeratedListTypeDefinition
elif self.context.closed:
self.context.list_type = MembershipModeratedListTypeDefinition
else:
self.context.list_type = PublicListTypeDefinition
# copy over the membership stuff
annot = IAnnotations(self.context)
listen_annot = annot.get('listen', {})
old_subscribers = listen_annot.get('subscribers', [])
# create the new annotations by using current adapters
mem_list = IWriteMembershipList(self.context)
for subscriber in old_subscribers:
mem_list.subscribe(subscriber)
# unsubscribe (but leave as allowed senders) those who don't
# receive mail
nomail = listen_annot.get('norecvmail', [])
for allowed_sender in nomail:
mem_list.unsubscribe(allowed_sender)
# copy over the moderation messages
self.mod_post_pending_list = getAdapter(self.context, IPostPendingList, 'pending_pmod_post')
for i in self.context.mqueue.objectIds():
(header, body) = splitMail(self.context.mqueue[i])
post = {'header':header, 'body':body}
(user_name, user_email) = parseaddr(header.get('from', ''))
self.mod_post_pending_list.add(user_email, user_name=user_name, post=post)
# creates list managers from moderators and list owner
managers = []
managers.append(self.context.list_owner)
for moderator in self.context.moderators:
managers.append(moderator)
self.context.managers = tuple(managers)
convert_manager_emails_to_memberids(self.context)
# translate archived vocabulary
if self.context.archived == 'not archived':
self.context.archived = 2
elif self.context.archived == 'plain text':
self.context.archived = 1
elif self.context.archived == 'with attachments':
self.context.archived = 0
else:
return 'error translating archive option'
# annotate the list to say the migration completed
self.migration_annot.append('policy_migration')
return 'successfully migrated'
示例3: __init__
def __init__(self, context):
self.context = context
annot = IAnnotations(context)
req_annot = annot.get(annot_key, None)
if req_annot is None:
req_annot = set()
annot[annot_key] = req_annot
self._req_store = req_annot
示例4: __init__
def __init__(self, context):
self.context = context
annot = IAnnotations(context)
wiki_annot = annot.get(annot_key, None)
if wiki_annot is None:
wiki_annot = IOBTree()
annot[annot_key] = wiki_annot
self.annot = wiki_annot
示例5: __init__
def __init__(self, context):
self.context = context
annot = IAnnotations(context)
homepage_annot = annot.get(self.KEY, None)
if homepage_annot is None:
homepage_annot = OOBTree()
annot['opencore.project.browser.home_page'] = homepage_annot
self.annot = homepage_annot
示例6: __init__
def __init__(self, context):
self.context = context
key = str(context)
annotations = IAnnotations(context)
storage = annotations.setdefault(ANNOT_KEY,
PersistentMapping())
storage.setdefault('hmac_key', key)
self.storage = storage
示例7: clearMemoCache
def clearMemoCache(self):
# from the request
req = self.portal.REQUEST
annotations = IAnnotations(req)
cache = annotations.get(ViewMemo.key, None)
if cache is not None:
annotations[ViewMemo.key] = dict()
# from the timestamp cache
opencore.utils.timestamp_cache.clear()
示例8: __init__
def __init__(self, context):
_ATCTFileAudio.__init__(self, context)
annotations = IAnnotations(context)
self.encoding_data = annotations.get(self.ENCODING_KEY, None)
if self.encoding_data == None:
self.encoding_data = PersistentDict()
annotations[self.ENCODING_KEY] = self.encoding_data
self.encoding_data['encoding'] = ""
self.encoding_data['original_encoding'] = ""
示例9: addPath
def addPath(self, path):
path = self._make_relative(path)
annotations = IAnnotations(self.context)
old = annotations.get(self.key, ())
fixed = map(self._make_relative, old)
if path not in fixed:
fixed.append(path)
new = tuple(fixed)
if new != old:
annotations[self.key] = new
示例10: __init__
def __init__(self, context, request):
self.context = context
self.request = request
annotations = IAnnotations(context.getCanonical())
mapping = annotations.get(KEY)
if mapping is None:
mapping = annotations[KEY] = PersistentDict({
'page_background': None,
})
self.mapping = mapping
示例11: LoggerSection
class LoggerSection(object):
classProvides(ISectionBlueprint)
implements(ISection)
def __init__(self, transmogrifier, name, options, previous):
self.transmogrifier = transmogrifier
keys = options.get('keys') or ''
self.pathkey = options.get('path-key', '_path').strip()
self.keys = Matcher(*keys.splitlines())
self.previous = previous
self.logger = name
self.storage = IAnnotations(transmogrifier).setdefault(VALIDATIONKEY, [])
def __iter__(self):
start_time = time()
count = 0
problematic = 0
for item in self.previous:
# source sections add store path of current generated item in annotation
# it gives posibility to monitor what items go through all pipeline
# sections between source section and this section and what don't
if self.pathkey in item and item[self.pathkey] in self.storage:
self.storage.remove(item[self.pathkey])
count += 1
# print item data stored on keys given as option
items = []
for key in item.keys():
if self.keys(key)[0] is not None:
items.append("%s=%s" % (key, item[key]))
if items:
msg = ", ".join(items)
logging.getLogger(self.logger).info(msg)
yield item
working_time = int(round(time() - start_time))
# log items that maybe have some problems
if self.storage:
problematic = len(self.storage)
logging.getLogger(self.logger).warning('\nNext objects didn\'t go through full pipeline:\n%s' % \
'\n'.join(['\t'+i for i in self.storage]))
# delete validation data from annotations
anno = IAnnotations(self.transmogrifier)
if VALIDATIONKEY in anno:
del anno[VALIDATIONKEY]
seconds = working_time % 60
minutes = working_time / 60 % 60
hours = working_time / 3600
stats = "\nPipeline processing time: %02d:%02d:%02d\n" % (hours, minutes, seconds)
stats += "\t%4d items were generated in source sections\n" % (count + problematic)
stats += "\t%4d went through full pipeline\n" % count
stats += "\t%4d were discarded in some section" % problematic
logging.getLogger(self.logger).info(stats)
示例12: capture
def capture(self, order, amount):
annotations = IAnnotations(order)
trans_id = annotations[interfaces.keys.processor_txn_id]
if annotations.has_key(APPROVAL_KEY):
annotation = IAnnotations( order )
if annotation.get( interfaces.keys.capture_amount ) is None:
annotation[ interfaces.keys.capture_amount ] = amount
else:
annotation[ interfaces.keys.capture_amount ] += amount
return interfaces.keys.results_success
return result.response_reason
示例13: testExportNodeWithAnnotation
def testExportNodeWithAnnotation(self):
"""
when membrane tool is annotated, hash-type node should get exported
attribute 'name' on the node should contain the hash-type
"""
# initially add the annotation on to the membrane_tool
annot = IAnnotations(self.portal.membrane_tool)
annot.setdefault(ANNOT_KEY, {})['hash_type'] = 'bcrypt'
node = self.adapter._exportNode()
self.failUnless('<hash-type name="bcrypt"/>' in node.toxml())
# clear the bogus annotation
del annot[ANNOT_KEY]
示例14: save_import_history
def save_import_history(self):
annot = IAnnotations(self.context)
listen_annot = annot.get(PROJECTNAME)
if listen_annot is None:
annot[PROJECTNAME] = listen_annot = OOBTree()
import_annot = listen_annot.get('import')
if import_annot is None:
listen_annot['import'] = import_annot = OOBTree()
now = str(time.time())
data = dict(msgids=self.msgids,
filename=self.filename)
import_annot[now] = OOBTree(data)
示例15: removePath
def removePath(self, path):
path = self._make_relative(path)
annotations = IAnnotations(self.context)
old = annotations.get(self.key, ())
if old:
fixed = map(self._make_relative, old)
fixed = [loc for loc in fixed if loc != path]
new = tuple(fixed)
if new != old:
if new:
annotations[self.key] = new
else:
del annotations[self.key]