def __init__(self, plist=[]): """ Initializer. Argument: - plist: Node or list of 'Property'.""" Dictionary.__init__(self) self.order = [] for p in plist: self.addProperty(p)
def __setitem__(self, key, x): """ On 'self[key]=x'. Allows assignment to existing items only. Raises 'DirectAccessError' on new item assignment.""" if self.has_key(key): self.order[self.order.index(self[key])] = x Dictionary.__setitem__(self, key, x) else: raise DirectAccessError( "Properties may not be added directly; use addProperty() instead.")
def __delitem__(self, key): """ On 'del self[key]'. Updates 'self.order' to maintain consistency.""" self.order.remove(self[key]) Dictionary.__delitem__(self, key)