Пример #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, 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)
Пример #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':
     if hasattr(body, 'read'):
       content = body.read()
     else:
       content = body
   elif content == 'echo_request_uri':
     content = uri
   return httplib2.Response(resp), content
Пример #4
0
      def get(self):
        error = self.request.get('error')
        if error:
          errormsg = self.request.get('error_description', error)
          self.response.out.write(
              'The authorization request failed: %s' % _safe_html(errormsg))
        else:
          user = users.get_current_user()
          decorator._create_flow(self)
          credentials = decorator.flow.step2_exchange(self.request.params)
          StorageByKeyName(
              CredentialsModel, user.user_id(), 'credentials').put(credentials)
          redirect_uri = _parse_state_value(str(self.request.get('state')),
                                            user)

          if decorator._token_response_param and credentials.token_response:
            resp_json = simplejson.dumps(credentials.token_response)
            redirect_uri = util._add_query_parameter(
                redirect_uri, decorator._token_response_param, resp_json)

          self.redirect(redirect_uri)
Пример #5
0
  def _to_json(self, strip):
    """Utility function that creates JSON repr. of a Credentials object.

    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__)
    for member in strip:
      if member in d:
        del d[member]
    if 'token_expiry' in d and isinstance(d['token_expiry'], datetime.datetime):
      d['token_expiry'] = d['token_expiry'].strftime(EXPIRY_FORMAT)
    # Add in information we will need later to reconsistitue this instance.
    d['_class'] = t.__name__
    d['_module'] = t.__module__
    return simplejson.dumps(d)
Пример #6
0
    def _to_json(self, strip):
        """Utility function that creates JSON repr. of a Credentials object.

    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__)
        for member in strip:
            if member in d:
                del d[member]
        if 'token_expiry' in d and isinstance(d['token_expiry'],
                                              datetime.datetime):
            d['token_expiry'] = d['token_expiry'].strftime(EXPIRY_FORMAT)
        # Add in information we will need later to reconsistitue this instance.
        d['_class'] = t.__name__
        d['_module'] = t.__module__
        return simplejson.dumps(d)
Пример #7
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)
Пример #8
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)