file handling class incidentsaxhandler(xml sax handler contenthandler)def __init__(selfincidents)super(__init__(self __data {self __text "self __incidents incidents self __incidents clear(custom sax handler classes must inherit the appropriate base class this ensures that for any methods we don' reimplement (because we are not interested in the parsing events they handle)the base class version will be called--and will safely do nothing we start by calling the base class' initializer this is generally good practice for all subclassesalthough it is not necessary (though harmlessfor direct object subclasses the self __data dictionary is used to keep one incident' datathe self __text string is used to keep the text of an airport name or of narrative depending on which we are readingand the self __incidents dictionary is an object reference to the incidentcollection dictionary which the handler updates directly (an alternative design would be to have an independent dictionary inside the handler and to copy it to the incidentcollection at the end using dict clear(and then dict update(def startelement(selfnameattributes)if name ="incident"self __data {for keyvalue in attributes items()if key ="date"self __data[keydatetime datetime strptimevalue"% -% -% "date(elif key ="pilot_percent_hours_on_type"self __data[keyfloat(valueelif key ="pilot_total_hours"self __data[keyint(valueelif key ="midair"self __data[keybool(int(value)elseself __data[keyvalue self __text "whenever start tag and its attributes are read the xml sax handler contenthandler startelement(method is called with the tag name and the tag' attributes in the case of an aircraft incidents xml filethe start tags are which we ignorewhose attributes we use to populate some of the self __data dictionaryand and both of