#NEWLINE# def header_expand( headers ) : #NEWLINE# #INDENT# "Returns an HTTP Header value string from a dictionary.\n\n    Example expansion::\n\n        {'text/x-dvi': {'q': '.8', 'mxb': '100000', 'mxt': '5.0'}, 'text/x-c': {}}\n        # Accept: text/x-dvi; q=.8; mxb=100000; mxt=5.0, text/x-c\n\n        (('text/x-dvi', {'q': '.8', 'mxb': '100000', 'mxt': '5.0'}), ('text/x-c', {}))\n        # Accept: text/x-dvi; q=.8; mxb=100000; mxt=5.0, text/x-c\n    " #NEWLINE# collector = [ ] #NEWLINE# if isinstance ( headers , dict ) : #NEWLINE# #INDENT# headers = headers . items ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( headers , basestring ) : #NEWLINE# #INDENT# return headers #NEWLINE# #UNINDENT# #UNINDENT# for ( i , ( value , params ) ) in enumerate ( headers ) : #NEWLINE# #INDENT# _params = [ ] #NEWLINE# for ( p_k , p_v ) in params . items ( ) : #NEWLINE# #INDENT# _params . append ( ( '%s=%s' % ( value , p_v ) ) ) #NEWLINE# #UNINDENT# collector . append ( value ) #NEWLINE# collector . append ( '; ' ) #NEWLINE# if len ( params ) : #NEWLINE# #INDENT# collector . append ( '; ' . join ( _params ) ) #NEWLINE# if ( not ( len ( headers ) == ( i + 1 ) ) ) : #NEWLINE# #INDENT# collector . append ( ', ' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( collector [ ( - 1 ) ] in ( ', ' , '; ' ) ) : #NEWLINE# #INDENT# del collector [ ( - 1 ) ] #NEWLINE# #UNINDENT# return '' . join ( collector )