defsubclass_exception(name,parents,module,attached_to=None):""" Create exception subclass. Used by ModelBase below. If 'attached_to' is supplied, the exception will be created in a way that allows it to be pickled, assuming the returned exception class will be added as an attribute to the 'attached_to' class. """ class_dict ={'__module__': module}if attached_to isnotNone:def__reduce__(self):# Exceptions are special - they've got state that isn't# in self.__dict__. We assume it is all in self.args.return (unpickle_inner_exception, (attached_to, name), self.args)def__setstate__(self,args): self.args = args class_dict['__reduce__']=__reduce__ class_dict['__setstate__']=__setstate__returntype(name, parents, class_dict)