Database Reference
In-Depth Information
message='Could not parse body as json: ' +
str(e))
return
self.response.headers['Content-Type'] =
'application/json'
try:
result = json.dumps(self.handle(arg))
except Exception, e:
result = self.json_error(e)
self.response.out.write(result)
def json_error(self, e):
logging.warn('Handler Error: %s' % unicode(e))
return json.dumps({'error': e.__class__.__name__,
'message': e.message})
def handle(self, arg):
raise NotImplementedError
class RegisterHandler(_JsonHandler):
'''Handle the registration command.'''
def handle(self, arg):
device_id = arg.get('id', None)
if not device_id:
raise ValueError('id entry missing from
argument')
candidate =
models.Candidate.get_by_device_id(device_id)
if not candidate:
raise KeyError('Id %s not valid' % device_id)
candidate.register(arg)
return {}
class RecordHandler(_JsonHandler):
'''Handle the logging command.'''
def handle(self, arg):
device_id = arg.get('id', None)
if not device_id:
Search WWH ::




Custom Search