Exemplo n.º 1
0
  def request(self, headers, path_params, query_params, body_value):
    """Updates outgoing requests with JSON bodies.

    Args:
      headers: dict, request headers
      path_params: dict, parameters that appear in the request path
      query_params: dict, parameters that appear in the query
      body_value: object, the request body as a Python object, which must be
                  serializable by simplejson.
    Returns:
      A tuple of (headers, path_params, query, body)

      headers: dict, request headers
      path_params: dict, parameters that appear in the request path
      query: string, query part of the request URI
      body: string, the body serialized as JSON
    """
    query = self._build_query(query_params)
    headers['accept'] = 'application/json'
    if 'user-agent' in headers:
      headers['user-agent'] += ' '
    else:
      headers['user-agent'] = ''
    headers['user-agent'] += 'google-api-python-client/1.0'
    if body_value is None:
      return (headers, path_params, query, None)
    else:
      headers['content-type'] = 'application/json'
      return (headers, path_params, query, simplejson.dumps(body_value))
Exemplo n.º 2
0
  def request(self, headers, path_params, query_params, body_value):
    """Updates outgoing requests with JSON bodies.

    Args:
      headers: dict, request headers
      path_params: dict, parameters that appear in the request path
      query_params: dict, parameters that appear in the query
      body_value: object, the request body as a Python object, which must be
                  serializable by simplejson.
    Returns:
      A tuple of (headers, path_params, query, body)

      headers: dict, request headers
      path_params: dict, parameters that appear in the request path
      query: string, query part of the request URI
      body: string, the body serialized as JSON
    """
    query = self._build_query(query_params)
    headers['accept'] = 'application/json'
    headers['accept-encoding'] = 'gzip, deflate'
    if 'user-agent' in headers:
      headers['user-agent'] += ' '
    else:
      headers['user-agent'] = ''
    headers['user-agent'] += 'google-api-python-client/1.0'

    if (isinstance(body_value, dict) and 'data' not in body_value and
        self._data_wrapper):
      body_value = {'data': body_value}
    if body_value is not None:
      headers['content-type'] = 'application/json'
      body_value = simplejson.dumps(body_value)
    return (headers, path_params, query, body_value)
Exemplo n.º 3
0
    def request(self, headers, path_params, query_params, body_value):
        """Updates outgoing requests with JSON bodies.

    Args:
      headers: dict, request headers
      path_params: dict, parameters that appear in the request path
      query_params: dict, parameters that appear in the query
      body_value: object, the request body as a Python object, which must be
                  serializable by simplejson.
    Returns:
      A tuple of (headers, path_params, query, body)

      headers: dict, request headers
      path_params: dict, parameters that appear in the request path
      query: string, query part of the request URI
      body: string, the body serialized as JSON
    """
        query = self._build_query(query_params)
        headers['accept'] = 'application/json'
        headers['accept-encoding'] = 'gzip, deflate'
        if 'user-agent' in headers:
            headers['user-agent'] += ' '
        else:
            headers['user-agent'] = ''
        headers['user-agent'] += 'google-api-python-client/1.0'

        if (isinstance(body_value, dict) and 'data' not in body_value
                and self._data_wrapper):
            body_value = {'data': body_value}
        if body_value is not None:
            headers['content-type'] = 'application/json'
            body_value = simplejson.dumps(body_value)
        return (headers, path_params, query, body_value)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
0
 def getJson(self):
   """Generate a json feed, for loading from the map."""
   ZVAL = 1 # static z value for stacking.
   quests = db.GqlQuery(
       "SELECT * FROM Quest WHERE owner = :1", users.get_current_user())
   qlist = []
   for q in quests:
     if not q.location:
       continue
     qlist.append([q.title, q.location.lat, q.location.lon, ZVAL, self.getInfoWindowHtml(q)])
   self.response.write("var locations = " + simplejson.dumps(qlist))
Exemplo n.º 7
0
    def _generate_assertion(self):
        header = {"typ": "JWT", "alg": "RS256"}

        now = int(time.time())
        claims = {"aud": self.audience, "scope": self.scope, "iat": now, "exp": now + 3600, "iss": self.app_name}

        jwt_components = [base64.b64encode(simplejson.dumps(seg)) for seg in [header, claims]]

        base_str = ".".join(jwt_components)
        key_name, signature = app_identity.sign_blob(base_str)
        jwt_components.append(base64.b64encode(signature))
        return ".".join(jwt_components)
Exemplo n.º 8
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
   return httplib2.Response(resp), content
Exemplo n.º 9
0
  def _decode_credential_from_json(self, cred_entry):
    """Load a credential from our JSON serialization.

    Args:
      cred_entry: A dict entry from the data member of our format

    Returns:
      (key, cred) where the key is the key tuple and the cred is the
        OAuth2Credential object.
    """
    raw_key = cred_entry['key']
    key = util.dict_to_tuple_key(raw_key)
    credential = None
    credential = Credentials.new_from_json(simplejson.dumps(cred_entry['credential']))
    return (key, credential)
Exemplo n.º 10
0
    def _decode_credential_from_json(self, cred_entry):
        """Load a credential from our JSON serialization.

        Args:
          cred_entry: A dict entry from the data member of our format

        Returns:
          (key, cred) where the key is the key tuple and the cred is the
            OAuth2Credential object.
        """
        raw_key = cred_entry['key']
        key = util.dict_to_tuple_key(raw_key)
        credential = None
        credential = Credentials.new_from_json(simplejson.dumps(cred_entry['credential']))
        return (key, credential)
Exemplo n.º 11
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
     return httplib2.Response(resp), content
Exemplo n.º 12
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)
Exemplo n.º 13
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)
Exemplo n.º 14
0
  def _decode_credential_from_json(self, cred_entry):
    """Load a credential from our JSON serialization.

    Args:
      cred_entry: A dict entry from the data member of our format

    Returns:
      (key, cred) where the key is the key tuple and the cred is the
        OAuth2Credential object.
    """
    raw_key = cred_entry['key']
    client_id = raw_key['clientId']
    user_agent = raw_key['userAgent']
    scope = raw_key['scope']
    key = (client_id, user_agent, scope)
    credential = None
    credential = Credentials.new_from_json(simplejson.dumps(cred_entry['credential']))
    return (key, credential)
Exemplo n.º 15
0
  def _decode_credential_from_json(self, cred_entry):
    """Load a credential from our JSON serialization.

    Args:
      cred_entry: A dict entry from the data member of our format

    Returns:
      (key, cred) where the key is the key tuple and the cred is the
        OAuth2Credential object.
    """
    raw_key = cred_entry['key']
    client_id = raw_key['clientId']
    user_agent = raw_key['userAgent']
    scope = raw_key['scope']
    key = (client_id, user_agent, scope)
    credential = None
    credential = Credentials.new_from_json(simplejson.dumps(cred_entry['credential']))
    return (key, credential)
Exemplo n.º 16
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 Response(resp), content
Exemplo n.º 17
0
  def _to_json(self, strip):
    """Utility function for creating a JSON representation of an instance of Credentials.

    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:
      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)
Exemplo n.º 18
0
  def _to_json(self, strip):
    """Utility function for creating a JSON representation of an instance of Credentials.

    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:
      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)
Exemplo n.º 19
0
  def _generate_assertion(self):
    header = {
      'typ': 'JWT',
      'alg': 'RS256',
    }

    now = int(time.time())
    claims = {
      'aud': self.audience,
      'scope': self.scope,
      'iat': now,
      'exp': now + 3600,
      'iss': self.app_name,
    }

    jwt_components = [base64.b64encode(simplejson.dumps(seg))
        for seg in [header, claims]]

    base_str = ".".join(jwt_components)
    key_name, signature = app_identity.sign_blob(base_str)
    jwt_components.append(base64.b64encode(signature))
    return ".".join(jwt_components)
Exemplo n.º 20
0
  def _generate_assertion(self):
    header = {
      'typ': 'JWT',
      'alg': 'RS256',
    }

    now = int(time.time())
    claims = {
      'aud': self.audience,
      'scope': self.scope,
      'iat': now,
      'exp': now + 3600,
      'iss': self.app_name,
    }

    jwt_components = [base64.b64encode(simplejson.dumps(seg))
        for seg in [header, claims]]

    base_str = ".".join(jwt_components)
    key_name, signature = app_identity.sign_blob(base_str)
    jwt_components.append(base64.b64encode(signature))
    return ".".join(jwt_components)
Exemplo n.º 21
0
def _json_encode(data):
  return simplejson.dumps(data, separators = (',', ':'))
Exemplo n.º 22
0
def _json_encode(data):
    return simplejson.dumps(data, separators=(',', ':'))
Exemplo n.º 23
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)
Exemplo n.º 24
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)
Exemplo n.º 25
0
def _json_encode(data):
    return simplejson.dumps(data, separators=(",", ":"))