Package CedarBackup2 :: Module util :: Class RestrictedContentList
[hide private]
[frames] | no frames]

Class RestrictedContentList

source code

object --+        
         |        
      list --+    
             |    
 UnorderedList --+
                 |
                RestrictedContentList

Class representing a list containing only object with certain values.

This is an unordered list.

We override the append, insert and extend methods to ensure that any item added to the list is among the valid values. We use a standard comparison, so pretty much anything can be in the list of valid values.

The valuesDescr value will be used in exceptions, i.e. "Item must be one of values in VALID_ACTIONS" if valuesDescr is "VALID_ACTIONS".


Note: This class doesn't make any attempt to trap for nonsensical arguments. All of the values in the values list should be of the same type (i.e. strings). Then, all list operations also need to be of that type (i.e. you should always insert or append just strings). If you mix types -- for instance lists and strings -- you will likely see AttributeError exceptions or other problems.

Instance Methods [hide private]
 
__init__(self, valuesList, valuesDescr, prefix=None)
Initializes a list restricted to containing certain values.
source code
 
append(self, item)
Overrides the standard append method.
source code
 
insert(self, index, item)
Overrides the standard insert method.
source code
 
extend(self, seq)
Overrides the standard insert method.
source code

Inherited from UnorderedList: __eq__, __ge__, __gt__, __le__, __lt__, __ne__

Inherited from list: __add__, __contains__, __delitem__, __delslice__, __getattribute__, __getitem__, __getslice__, __hash__, __iadd__, __imul__, __iter__, __len__, __mul__, __new__, __repr__, __reversed__, __rmul__, __setitem__, __setslice__, count, index, pop, remove, reverse, sort

Inherited from object: __delattr__, __reduce__, __reduce_ex__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, valuesList, valuesDescr, prefix=None)
(Constructor)

source code 
Initializes a list restricted to containing certain values.
Parameters:
  • valuesList - List of valid values.
  • valuesDescr - Short string describing list of values.
  • prefix - Prefix to use in error messages (None results in prefix "Item")
Returns:
new list

Overrides: list.__init__

append(self, item)

source code 
Overrides the standard append method.
Raises:
  • ValueError - If item is not in the values list.
Overrides: list.append

insert(self, index, item)

source code 
Overrides the standard insert method.
Raises:
  • ValueError - If item is not in the values list.
Overrides: list.insert

extend(self, seq)

source code 
Overrides the standard insert method.
Raises:
  • ValueError - If item is not in the values list.
Overrides: list.extend