def build_request(path, body='', http_headers=None):
 (unused_scheme, unused_netloc, path, query, unused_fragment) = urlparse.urlsplit(path)
 env = {'SERVER_PORT': 42, 'REQUEST_METHOD': 'GET', 'SERVER_NAME': 'localhost', 'HTTP_CONTENT_TYPE': 'application/json', 'PATH_INFO': path, 'wsgi.input': cStringIO.StringIO(body)}
 if query:
  env['QUERY_STRING'] = query
 if http_headers:
  for (header, value) in http_headers:
   header = ('HTTP_%s' % header.upper().replace('-', '_'))
   env[header] = value
 cgi_request = api_request.ApiRequest(env)
 return cgi_request

def build_request ( path , body = '' , http_headers = None ) : ( unused_scheme , unused_netloc , path , query , unused_fragment ) = urlparse . urlsplit ( path ) env = { 'SERVER_PORT' : 42 , 'REQUEST_METHOD' : 'GET' , 'SERVER_NAME' : 'localhost' , 'HTTP_CONTENT_TYPE' : 'application/json' , 'PATH_INFO' : path , 'wsgi.input' : cStringIO . StringIO ( body ) } if query : env [ 'QUERY_STRING' ] = query if http_headers : for ( header , value ) in http_headers : header = ( 'HTTP_%s' % header . upper ( ) . replace ( '-' , '_' ) ) env [ header ] = value cgi_request = api_request . ApiRequest ( env ) return cgi_request
build a urllib2 request object this function automatically adds a user-agent header to all requests .