def _parse_header(fh):
 headerConverters = {'StartFontMetrics': _to_float, 'FontName': _to_str, 'FullName': _to_str, 'FamilyName': _to_str, 'Weight': _to_str, 'ItalicAngle': _to_float, 'IsFixedPitch': _to_bool, 'FontBBox': _to_list_of_ints, 'UnderlinePosition': _to_int, 'UnderlineThickness': _to_int, 'Version': _to_str, 'Notice': _to_str, 'EncodingScheme': _to_str, 'CapHeight': _to_float, 'Capheight': _to_float, 'XHeight': _to_float, 'Ascender': _to_float, 'Descender': _to_float, 'StdHW': _to_float, 'StdVW': _to_float, 'StartCharMetrics': _to_int, 'CharacterSet': _to_str, 'Characters': _to_int}
 d = {}
 while 1:
  line = fh.readline()
  if (not line):
   break
  line = line.rstrip()
  if line.startswith('Comment'):
   continue
  lst = line.split(' ', 1)
  key = lst[0]
  if (len(lst) == 2):
   val = lst[1]
  else:
   val = ''
  try:
   d[key] = headerConverters[key](val)
  except ValueError:
   print >>sys.stderr, 'Value error parsing header in AFM:', key, val
   continue
  except KeyError:
   print >>sys.stderr, ('Found an unknown keyword in AFM header (was %s)' % key)
   continue
  if (key == 'StartCharMetrics'):
   return d
 raise RuntimeError('Bad parse')

def _parse_header ( fh ) : headerConverters = { 'StartFontMetrics' : _to_float , 'FontName' : _to_str , 'FullName' : _to_str , 'FamilyName' : _to_str , 'Weight' : _to_str , 'ItalicAngle' : _to_float , 'IsFixedPitch' : _to_bool , 'FontBBox' : _to_list_of_ints , 'UnderlinePosition' : _to_int , 'UnderlineThickness' : _to_int , 'Version' : _to_str , 'Notice' : _to_str , 'EncodingScheme' : _to_str , 'CapHeight' : _to_float , 'Capheight' : _to_float , 'XHeight' : _to_float , 'Ascender' : _to_float , 'Descender' : _to_float , 'StdHW' : _to_float , 'StdVW' : _to_float , 'StartCharMetrics' : _to_int , 'CharacterSet' : _to_str , 'Characters' : _to_int } d = { } while 1 : line = fh . readline ( ) if ( not line ) : break line = line . rstrip ( ) if line . startswith ( 'Comment' ) : continue lst = line . split ( ' ' , 1 ) key = lst [ 0 ] if ( len ( lst ) == 2 ) : val = lst [ 1 ] else : val = '' try : d [ key ] = headerConverters [ key ] ( val ) except ValueError : print >> sys . stderr , 'Value error parsing header in AFM:' , key , val continue except KeyError : print >> sys . stderr , ( 'Found an unknown keyword in AFM header (was %s)' % key ) continue if ( key == 'StartCharMetrics' ) : return d raise RuntimeError ( 'Bad parse' )
parse a content-type like header .