code: def parse_midi_file_header(self, fp):
          
          # Check header
          try:
              if fp.read(4) != 'MThd':
                  raise HeaderError('Not a valid MIDI file header. Byte %d.'
                          % self.bytes_read)
              self.bytes_read += 4
          except:
              raise IOError("Couldn't read from file.")
  
          # Parse chunk size
          try:
              chunk_size = self.bytes_to_int(fp.read(4))
              self.bytes_read += 4
          except:
              raise IOError("Couldn't read chunk size from file. Byte %d."
                      % self.bytes_read)
  
          # Expect chunk size to be at least 6
          if chunk_size < 6:
              return False
          try:
              format_type = self.bytes_to_int(fp.read(2))
              self.bytes_read += 2
              if format_type not in [0, 1, 2]:
                  raise FormatError('%d is not a valid MIDI format.'
                          % format_type)
          except:
              raise IOError("Couldn't read format type from file.")
          try:
              number_of_tracks = self.bytes_to_int(fp.read(2))
              time_division = self.parse_time_division(fp.read(2))
              self.bytes_read += 4
          except:
              raise IOError("Couldn't read number of tracks "
                      "and/or time division from tracks.")
  
          chunk_size -= 6
          if chunk_size % 2 == 1:
              raise FormatError("Won't parse this.")
          fp.read(chunk_size / 2)
          self.bytes_read += chunk_size / 2
          return (format_type, number_of_tracks, time_division)
docs: Read the header of a MIDI file and return a tuple containing the
          format type, number of tracks and parsed time division information.