def header_expand(headers):
 collector = []
 if isinstance(headers, dict):
  headers = list(headers.items())
 elif isinstance(headers, basestring):
  return headers
 elif isinstance(headers, str):
  return headers.encode('latin-1')
 elif (headers is None):
  return headers
 for (i, (value, params)) in enumerate(headers):
  _params = []
  for (p_k, p_v) in list(params.items()):
   _params.append(('%s=%s' % (p_k, p_v)))
  collector.append(value)
  collector.append('; ')
  if len(params):
   collector.append('; '.join(_params))
   if (not (len(headers) == (i + 1))):
    collector.append(', ')
 if (collector[(-1)] in (', ', '; ')):
  del collector[(-1)]
 return ''.join(collector)

def header_expand ( headers ) : collector = [ ] if isinstance ( headers , dict ) : headers = list ( headers . items ( ) ) elif isinstance ( headers , basestring ) : return headers elif isinstance ( headers , str ) : return headers . encode ( 'latin-1' ) elif ( headers is None ) : return headers for ( i , ( value , params ) ) in enumerate ( headers ) : _params = [ ] for ( p_k , p_v ) in list ( params . items ( ) ) : _params . append ( ( '%s=%s' % ( p_k , p_v ) ) ) collector . append ( value ) collector . append ( '; ' ) if len ( params ) : collector . append ( '; ' . join ( _params ) ) if ( not ( len ( headers ) == ( i + 1 ) ) ) : collector . append ( ', ' ) if ( collector [ ( - 1 ) ] in ( ', ' , '; ' ) ) : del collector [ ( - 1 ) ] return '' . join ( collector )
returns an http header value string from a dictionary .