http.Request

Here are the examples of the python api http.Request taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

Example 1

Project: yos-social-python Source File: request.py
Function: make_http_request
  def make_http_request(self, url_base, query_params=None):
    """Generates a http.Request object for the UrlFetch interface.
    
    Args:
      url_base: str The base REST URL.
    
    Returns: The http.Request object.

    """
    # Ensure that there is a path separator.
    if url_base[-1] is not '/' and self.path[0] is not '/':
      url_base = url_base + '/'
    url = url_base + self.path
    if query_params:
      self.params.update(query_params)
    return http.Request(url, method=self.method, signed_params=self.params)

Example 2

Project: yos-social-python Source File: __init__.py
  def _send_rpc_requests(self, batch):
    rpcs = []
    id_to_key_map = {}
    query_params = {}
    """Build up a list of RPC calls. Also, create a mapping of RPC request id's
    to batch keys in order to populate the batch object with the responses.
    """
    for key, request in batch.requests.iteritems():
      query_params.update(request.get_query_params())
      rpc_body = request.get_rpc_body()
      rpc_id = rpc_body.get('id')
      id_to_key_map[rpc_id] = key
      rpcs.append(rpc_body)

    http_request = http.Request(self.config.server_rpc_base,
                                method='POST',
                                signed_params=query_params,
                                post_body=rpcs)
    
    http_response = self._send_http_request(http_request)
    json = self._handle_response(http_response)
    
    """Pull out all of the results and insert them into the batch object."""
    for response in json:
      id = response.get('id')
      key = id_to_key_map[id]
      if 'error' in response:
        code = response.get('error').get('code')
        message = response.get('error').get('message')
        error = BadResponseError(code, message)
        batch._set_data(key, error)
      else:
        json = response.get('data')
        request = batch.requests[key]
        batch._set_data(key, request.process_json(json))