Пример #1
0
  def to_json(self):
    """Returns a JSON representation of the HttpRequest."""
    d = copy.copy(self.__dict__)
    if d['resumable'] is not None:
      d['resumable'] = self.resumable.to_json()
    del d['http']
    del d['postproc']

    return simplejson.dumps(d)
Пример #2
0
  def to_json(self):
    """Create a JSON representation of a MediaInMemoryUpload.

    Returns:
       string, a JSON representation of this instance, suitable to pass to
       from_json().
    """
    t = type(self)
    d = copy.copy(self.__dict__)
    del d['_body']
    d['_class'] = t.__name__
    d['_module'] = t.__module__
    d['_b64body'] = base64.b64encode(self._body)
    return simplejson.dumps(d)
Пример #3
0
 def request(self, uri,
             method='GET',
             body=None,
             headers=None,
             redirections=1,
             connection_type=None):
   resp, content = self._iterable.pop(0)
   if content == 'echo_request_headers':
     content = headers
   elif content == 'echo_request_headers_as_json':
     content = simplejson.dumps(headers)
   elif content == 'echo_request_body':
     content = body
   elif content == 'echo_request_uri':
     content = uri
   return httplib2.Response(resp), content
Пример #4
0
  def _to_json(self, strip=None):
    """Utility function for creating a JSON representation of a MediaUpload.

    Args:
      strip: array, An array of names of members to not include in the JSON.

    Returns:
       string, a JSON representation of this instance, suitable to pass to
       from_json().
    """
    t = type(self)
    d = copy.copy(self.__dict__)
    if strip is not None:
      for member in strip:
        del d[member]
    d['_class'] = t.__name__
    d['_module'] = t.__module__
    return simplejson.dumps(d)
Пример #5
0
 def serialize(self, body_value):
   if (isinstance(body_value, dict) and 'data' not in body_value and
       self._data_wrapper):
     body_value = {'data': body_value}
   return simplejson.dumps(body_value)