def parse_header(line):
 plist = _parse_header_params((';' + line))
 key = plist.pop(0).lower().decode(u'ascii')
 pdict = {}
 for p in plist:
  i = p.find('=')
  if (i >= 0):
   name = p[:i].strip().lower().decode(u'ascii')
   value = p[(i + 1):].strip()
   if ((len(value) >= 2) and (value[:1] == value[(-1):] == '"')):
    value = value[1:(-1)]
    value = value.replace('\\\\', '\\').replace('\\"', '"')
   pdict[name] = value
 return (key, pdict)

def parse_header ( line ) : plist = _parse_header_params ( ( ';' + line ) ) key = plist . pop ( 0 ) . lower ( ) . decode ( u'ascii' ) pdict = { } for p in plist : i = p . find ( '=' ) if ( i >= 0 ) : name = p [ : i ] . strip ( ) . lower ( ) . decode ( u'ascii' ) value = p [ ( i + 1 ) : ] . strip ( ) if ( ( len ( value ) >= 2 ) and ( value [ : 1 ] == value [ ( - 1 ) : ] == '"' ) ) : value = value [ 1 : ( - 1 ) ] value = value . replace ( '\\\\' , '\\' ) . replace ( '\\"' , '"' ) pdict [ name ] = value return ( key , pdict )
parse a content-type like header .