#! /usr/bin/python import re class NetMapObject: ''' This is the base class for all other object classes in this program. It defines basic functions for setting object attributes and defines an interface for other classes.''' def __init__( self ): # The attribute map stores all of the valid attribute names # and validation patterns self.attribute_map = {} self.attrs = {} def __getitem__( self, key ): try: return self.attrs[ key ] except: return '' def __setitem__( self, key, value ): # Raises AttributeError if the key isn't in the attribute_map. # Raises ValueError if the value doesn't match the validation regex. if not self.attribute_map.has_key( key ): raise AttributeError, \ '"%s" isn\'t a valid attribute for this object.' \ % cgi.escape( key ) if not re.compile( self.attribute_map[key] ).search( value ): raise ValueError, \ '"%s" isn\'t valid for %s' % (cgi.escape( value ), cgi.escape( key )) self.attrs[ key ] = value def __delitem__( self, key ): del( self.attrs[ key ] ) def commit( self ): return 'This object can\'t be commited to storage'