def wrap(self):
   """Returns a JSON-encodable version of this instance."""
   try:
     self_json = {'id':chatter.wrap(self.key())}
   except db.NotSavedError:
     self_json = {}
   # try:
   #   self_json = {'id':chatter.wrap(self.key())}
   # except Exception, e:
   #   logging.error("%s" % e)
   #   logging.error("%s" % dir(e))
   #   raise 
   self_json.update((name, chatter.wrap(getattr(self, name)))
     for name in type(self).properties_to_wrap)
   return self_json
      def post(self, key=None):
        """Decodes the arguments, calls the underlying method, then
        encodes the result to send back."""
        try:
          if remote.admin and not users.is_current_user_admin():
            raise RemoteException(403, 'Must be admin.')

          # get the request and respons objects
          request = chatter.unwrap(json.loads(self.request.body))
          response = {}

          # simple case for static method calls
          if remote.static:
            xx = model
          elif request['sync_before']:
            request['self'].put()
            xx = request['self']
          else:
            xx = model.get(key)
          response['return_val'] = remote.method(xx, **request['args'])
          if (not remote.static) and request['sync_after']:
            response['self'] = xx

          # write it all out
          self.response.headers['Content-Type'] = 'text/json'
          self.response.out.write(json.dumps(chatter.wrap(response)))
        except RemoteException, exc:
          self.error(exc.error_code)
          self.response.headers['Content-Type'] = 'text/plain'
          traceback.print_exc(file=self.response.out)
 def get(self, key):
   """Gets an existing entity."""
   entity = new_class.get(key)
   if not entity:
     return self.error(404) # can't find the entity
   self.response.headers['Content-Type'] = 'text/json'
   self.response.out.write(json.dumps(chatter.wrap(entity)))
 def __set__(self, instance, value):
   if type(value) == appengine_text_type:
     # make sure that the text value is valid
     chatter.unwrap(json.loads(value))
     
     # pass the text value straight through
     text = value
   else:
     # convert the json object to a string
     text = json.dumps(chatter.wrap(value))
   db.TextProperty.__set__(self, instance, text)
 def post(self):
   """Creates a new entity."""
   try:
     entity = chatter.unwrap(json.loads(self.request.body))
     assert not entity.is_saved()
     entity.put()
     self.response.headers['Content-Type'] = 'text/json'
     self.response.out.write(json.dumps(chatter.wrap(entity)))
   except RemoteException, exc:
     self.error(exc.error_code)
     self.response.headers['Content-Type'] = 'text/plain'
     traceback.print_exc(file=self.response.out)
 def func_stub(**kwargs):
   msg = json.dumps(chatter.wrap([name, kwargs]))
   channel.send_message(self.client_id, msg)