def post(self):
     dao = ListingDAO(self.db)
     cursor = yield (dao.create())
     if not cursor.closed:
         self.write('closing cursor')
         cursor.close()
     self.finish()
 def delete(self):
     dao = ListingDAO(self.db)
     cursor = yield (dao.delete_table())
     if not cursor.closed:
         self.write('closing cursor')
         cursor.close()
     self.finish()
 def delete(self, id=None):
     if id:
         dao = ListingDAO(self.db)
         result = yield (dao.delete(id))
         self.write('listing deleted')
     else:
         self.write('invalid listing')
     self.finish()
 def get(self, id=None):
     dao = ListingDAO(self.db)
     if not id:
         dict_result = yield (dao.get_list())
     else:
         dict_result = yield (dao.get(id))
     self.write(json.dumps(dict_result))
     self.finish()
 def put(self, id=None):
     if not hasattr(self, 'json_args'):
         self.write('invalid request')
         self.finish()
     else:
         dao = ListingDAO(self.db)
         if id:
             result = yield (dao.update(id, data=self.json_args))
             dict_result = yield (dao.get(id))
             self.write(json.dumps(dict_result))
         else:
             self.write('invalid listing')
         self.finish()