#NEWLINE# def combine_repeated_headers( kvset ) : #NEWLINE# #INDENT# "\n    Given a list of key-value pairs (like for HTTP headers!), combines pairs\n    with the same key together, separating the values with NULL bytes. This\n    function maintains the order of input keys, because it's awesome.\n    " #NEWLINE# def set_pop( set , item ) : #NEWLINE# #INDENT# set . remove ( item ) #NEWLINE# return item #NEWLINE# #UNINDENT# headers = defaultdict ( list ) #NEWLINE# keys = set ( ) #NEWLINE# for ( key , value ) in kvset : #NEWLINE# #INDENT# headers [ key ] . append ( value ) #NEWLINE# keys . add ( key ) #NEWLINE# #UNINDENT# return [ ( set_pop ( keys , k ) , b'\x00' . join ( headers [ k ] ) ) for ( k , v ) in kvset if ( k in keys ) ]