本文整理汇总了Python中BTrees.OIBTree.OIBTree.pop方法的典型用法代码示例。如果您正苦于以下问题:Python OIBTree.pop方法的具体用法?Python OIBTree.pop怎么用?Python OIBTree.pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BTrees.OIBTree.OIBTree
的用法示例。
在下文中一共展示了OIBTree.pop方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ContentTypeScopeManager
# 需要导入模块: from BTrees.OIBTree import OIBTree [as 别名]
# 或者: from BTrees.OIBTree.OIBTree import pop [as 别名]
class ContentTypeScopeManager(BTreeScopeManager):
"""
A scope manager based on content types.
This scope manager validates the request using the content type of
the accessed object and the subpath of the request against a content
type mapping. The content type mapping to be used will be one of
specified by the resource access key, the client key or default, and
is resolved in this order.
One more restriction imposed by this scope manager: mappings are
enforced absolutely for access keys. This allows clients to request
new default scopes for themselves at will and/or have site-wide
default scope changes without compromising the scopes already
granted by the resource owner referenced by the access key.
This however does not address the case where additional global
restrictions that may be placed by the site owner as the focus is
ultimately on the access keys. Workaround is to revoke those keys
and have the content owners issue new ones regardless of changes.
Pruning of unused scope is not implemented.
"""
zope.interface.implements(IContentTypeScopeManager)
default_mapping_id = fieldproperty.FieldProperty(
IContentTypeScopeManager['default_mapping_id'])
def __init__(self):
super(ContentTypeScopeManager, self).__init__()
self._mappings = IOBTree()
# Methods permitted to access this mapping with. Originally
# I wanted to provide alternative sets of mapping on a per
# mapping_id basis, however this proved to be complex and
# complicated due to extra relationships involved.
self._methods = IOBTree()
# For metadata related to the above.
self._mappings_metadata = IOBTree()
# To ease the usage of scopes, the mappings are referenced by
# names and are called profiles which add a few useful fields to
# allow slightly easier usage. This separates the name from the
# already active tokens such that once a token is instantiated
# with a scope, the mapping is stuck until the token is revoked.
self._named_mappings = OIBTree() # name to id.
# To not overburden the named mappings with work-in-progress
# profiles, instantiate one here also.
self._edit_mappings = OOBTree()
self.default_mapping_id = self.addMapping({})
# Main mapping related management methods.
def addMapping(self, mapping, methods='GET HEAD OPTIONS', metadata=None):
key = 0 # default?
if len(self._mappings) > 0:
# Can calculate the next key.
key = self._mappings.maxKey() + 1
self._mappings[key] = mapping
self._methods[key] = methods.split()
if metadata is not None:
self._mappings_metadata[key] = metadata
return key
def getMapping(self, mapping_id, default=_marker):
result = self._mappings.get(mapping_id, default)
if result is _marker:
raise KeyError()
return result
def getMappingMetadata(self, mapping_id, default=None):
result = self._mappings_metadata.get(mapping_id, default)
return result
def getMappingId(self, name):
# Returned ID could potentially not exist, what do?
return self._named_mappings[name]
def getMappingMethods(self, mapping_id, default=_marker):
result = self._methods.get(mapping_id, default)
if result is _marker:
raise KeyError()
return result
def checkMethodPermission(self, mapping_id, method):
methods = self.getMappingMethods(mapping_id, ())
return method in methods
def setMappingNameToId(self, name, mapping_id):
self._named_mappings[name] = mapping_id
def delMappingName(self, name):
saved = self._named_mappings.pop(name, None)
edits = self._edit_mappings.pop(name, None)
return (saved, edits)
#.........这里部分代码省略.........