Back to index

plone3  3.1.7
SequenceWrapper.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00004 # 
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE
00011 # 
00012 ##############################################################################
00013 
00014 from Globals import InitializeClass, Persistent
00015 from AccessControl import ClassSecurityInfo
00016 
00017 
00018 class SequenceWrapper:
00019     """A helper that manages lazy acquisition wrapping."""
00020     def __init__(self, parent, items, pairs=None):
00021         if pairs is not None:
00022             self.pairs = 1
00023         self.parent = parent
00024         self.items = items
00025 
00026     pairs = None
00027 
00028     def __getitem__(self, key):
00029         item = self.items[key]
00030         if self.pairs is not None:
00031             return (item[0], item[1].__of__(self.parent))
00032         return item.__of__(self.parent)
00033 
00034     def __len__(self):
00035         return len(self.items)
00036 
00037     def __nonzero__(self):
00038         return len(self.items) > 0
00039