def sort_q_values(header_val):
 if (not header_val):
  return []
 def item(x):
  (e, r) = x.partition(u';')[::2]
  (p, v) = r.partition(u'=')[::2]
  q = 1.0
  if ((p == u'q') and v):
   try:
    q = max(0.0, min(1.0, float(v.strip())))
   except Exception:
    pass
  return (e.strip(), q)
 return tuple(map(itemgetter(0), sorted(map(item, parse_http_list(header_val)), key=itemgetter(1), reverse=True)))

def sort_q_values ( header_val ) : if ( not header_val ) : return [ ] def item ( x ) : ( e , r ) = x . partition ( u';' ) [ : : 2 ] ( p , v ) = r . partition ( u'=' ) [ : : 2 ] q = 1.0 if ( ( p == u'q' ) and v ) : try : q = max ( 0.0 , min ( 1.0 , float ( v . strip ( ) ) ) ) except Exception : pass return ( e . strip ( ) , q ) return tuple ( map ( itemgetter ( 0 ) , sorted ( map ( item , parse_http_list ( header_val ) ) , key = itemgetter ( 1 ) , reverse = True ) ) )
get sorted items from an http header of type: a;q=0 .