def parseAcceptHeader(value):
 chunks = [chunk.strip() for chunk in value.split(',')]
 accept = []
 for chunk in chunks:
  parts = [s.strip() for s in chunk.split(';')]
  mtype = parts.pop(0)
  if ('/' not in mtype):
   continue
  (main, sub) = mtype.split('/', 1)
  for ext in parts:
   if ('=' in ext):
    (k, v) = ext.split('=', 1)
    if (k == 'q'):
     try:
      q = float(v)
      break
     except ValueError:
      pass
  else:
   q = 1.0
  accept.append((q, main, sub))
 accept.sort()
 accept.reverse()
 return [(main, sub, q) for (q, main, sub) in accept]

def parseAcceptHeader ( value ) : chunks = [ chunk . strip ( ) for chunk in value . split ( ',' ) ] accept = [ ] for chunk in chunks : parts = [ s . strip ( ) for s in chunk . split ( ';' ) ] mtype = parts . pop ( 0 ) if ( '/' not in mtype ) : continue ( main , sub ) = mtype . split ( '/' , 1 ) for ext in parts : if ( '=' in ext ) : ( k , v ) = ext . split ( '=' , 1 ) if ( k == 'q' ) : try : q = float ( v ) break except ValueError : pass else : q = 1.0 accept . append ( ( q , main , sub ) ) accept . sort ( ) accept . reverse ( ) return [ ( main , sub , q ) for ( q , main , sub ) in accept ]
parse an accept header .