def HttpRequestToString(req, include_data=True):
 headers = ''
 for header in req.header_items():
  headers += ('%s: %s\n' % (header[0], header[1]))
 template = '%(method)s %(selector)s %(type)s/1.1\nHost: %(host)s\n%(headers)s'
 if include_data:
  template = (template + '\n%(data)s')
 return (template % {'method': req.get_method(), 'selector': req.get_selector(), 'type': req.get_type().upper(), 'host': req.get_host(), 'headers': headers, 'data': req.get_data()})

def HttpRequestToString ( req , include_data = True ) : headers = '' for header in req . header_items ( ) : headers += ( '%s: %s\n' % ( header [ 0 ] , header [ 1 ] ) ) template = '%(method)s %(selector)s %(type)s/1.1\nHost: %(host)s\n%(headers)s' if include_data : template = ( template + '\n%(data)s' ) return ( template % { 'method' : req . get_method ( ) , 'selector' : req . get_selector ( ) , 'type' : req . get_type ( ) . upper ( ) , 'host' : req . get_host ( ) , 'headers' : headers , 'data' : req . get_data ( ) } )
converts a urllib2 .