Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class StartPrimitiveHandler(PoppyRequestHandler):
def get(self, primitive_name):
self.restful_robot.start_primitive(primitive_name)
class StopPrimitiveHandler(PoppyRequestHandler):
def get(self, primitive_name):
self.restful_robot.stop_primitive(primitive_name)
class PausePrimitiveHandler(PoppyRequestHandler):
def get(self, primitive_name):
self.restful_robot.pause_primitive(primitive_name)
class ResumePrimitiveHandler(PoppyRequestHandler):
def get(self, primitive_name):
self.restful_robot.resume_primitive(primitive_name)
class PrimitivePropertiesListHandler(PoppyRequestHandler):
def get(self, primitive_name):
self.write_json({
'property': self.restful_robot.get_primitive_properties_list(primitive_name)
})
class PrimitivePropertyHandler(PoppyRequestHandler):
def get(self, primitive_name, prop):
response = self.restful_robot.get_primitive_property(primitive_name, prop)
self.write_json({
'{}.{}'.format(primitive_name, prop): response
class SensorsListHandler(PoppyRequestHandler):
def get(self):
self.write_json({
'sensors': self.restful_robot.get_sensors_list()
})
class MotorsAliasesListHandler(PoppyRequestHandler):
def get(self):
self.write_json({
'alias': self.restful_robot.get_motors_alias()
})
class MotorRegistersListHandler(PoppyRequestHandler):
def get(self, motor_name):
self.write_json({
'registers': self.restful_robot.get_motor_registers_list(motor_name)
})
class MotorRegisterHandler(PoppyRequestHandler):
def get(self, motor_name, register_name):
self.write_json({
register_name: self.restful_robot.get_motor_register_value(motor_name, register_name)
})
class UpdateMotorRegisterHandler(PoppyRequestHandler):
def post(self, motor_name, register_name):
data = json.loads(self.request.body.decode())
class MotorRegisterHandler(PoppyRequestHandler):
def get(self, motor_name, register_name):
self.write_json({
register_name: self.restful_robot.get_motor_register_value(motor_name, register_name)
})
class UpdateMotorRegisterHandler(PoppyRequestHandler):
def post(self, motor_name, register_name):
data = json.loads(self.request.body.decode())
self.restful_robot.set_motor_register_value(motor_name, register_name, data)
self.write_json({})
class PrimitivesListHandler(PoppyRequestHandler):
def get(self):
self.write_json({
'primitives': self.restful_robot.get_primitives_list()
})
class RunningPrimitivesListHandler(PoppyRequestHandler):
def get(self):
self.write_json({
'running_primitives': self.restful_robot.get_running_primitives_list()
})
class StartPrimitiveHandler(PoppyRequestHandler):
def get(self, primitive_name):
self.restful_robot.start_primitive(primitive_name)
every OPTIONS request."""
def set_default_headers(self):
self.set_header('Cache-control', 'no-store')
self.set_header('Access-Control-Allow-Origin', '*')
self.set_header('Access-Control-Allow-Headers', 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token')
self.set_header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
def options(self, *args, **kwargs):
self.set_status(204)
def write_json(self, obj):
self.write(json.dumps(obj, cls=MyJSONEncoder))
class IndexHandler(PoppyRequestHandler):
def get(self, *args):
out = {
'motors': [],
'primitives': []
}
for m in self.restful_robot.get_motors_list('motors'):
motor = {}
for r in self.restful_robot.get_motor_registers_list(m):
try:
motor[r] = self.restful_robot.get_motor_register_value(m, r)
except AttributeError:
pass
out['motors'].append(motor)
running_primitives = self.restful_robot.get_running_primitives_list()
for prim in self.restful_robot.get_primitives_list():
self.restful_robot.pause_primitive(primitive_name)
class ResumePrimitiveHandler(PoppyRequestHandler):
def get(self, primitive_name):
self.restful_robot.resume_primitive(primitive_name)
class PrimitivePropertiesListHandler(PoppyRequestHandler):
def get(self, primitive_name):
self.write_json({
'property': self.restful_robot.get_primitive_properties_list(primitive_name)
})
class PrimitivePropertyHandler(PoppyRequestHandler):
def get(self, primitive_name, prop):
response = self.restful_robot.get_primitive_property(primitive_name, prop)
self.write_json({
'{}.{}'.format(primitive_name, prop): response
})
class SetPrimitivePropertyHandler(PoppyRequestHandler):
def post(self, primitive_name, prop):
data = json.loads(self.request.body.decode())
self.restful_robot.set_primitive_property(primitive_name, prop, data)
self.set_status(204)
class ListPrimitiveMethodsHandler(PoppyRequestHandler):
def get(self, primitive_name):
class PrimitivePropertyHandler(PoppyRequestHandler):
def get(self, primitive_name, prop):
response = self.restful_robot.get_primitive_property(primitive_name, prop)
self.write_json({
'{}.{}'.format(primitive_name, prop): response
})
class SetPrimitivePropertyHandler(PoppyRequestHandler):
def post(self, primitive_name, prop):
data = json.loads(self.request.body.decode())
self.restful_robot.set_primitive_property(primitive_name, prop, data)
self.set_status(204)
class ListPrimitiveMethodsHandler(PoppyRequestHandler):
def get(self, primitive_name):
self.write_json({
'methods': self.restful_robot.get_primitive_methods_list(primitive_name)
})
class CallPrimitiveMethodHandler(PoppyRequestHandler):
def post(self, primitive_name, method_name):
data = json.loads(self.request.body.decode())
response = self.restful_robot.call_primitive_method(primitive_name, method_name, data)
self.write_json({
'{}:{}'.format(primitive_name, method_name): response
})
class MotorsRegistersHandler(PoppyRequestHandler):
def get(self, primitive_name):
self.write_json({
'methods': self.restful_robot.get_primitive_methods_list(primitive_name)
})
class CallPrimitiveMethodHandler(PoppyRequestHandler):
def post(self, primitive_name, method_name):
data = json.loads(self.request.body.decode())
response = self.restful_robot.call_primitive_method(primitive_name, method_name, data)
self.write_json({
'{}:{}'.format(primitive_name, method_name): response
})
class MotorsRegistersHandler(PoppyRequestHandler):
def get(self, register_name):
motors_list = self.restful_robot.get_motors_list('motors')
registers_motors = {}
for motor_name in motors_list:
registers_motors[motor_name] = {
register_name: self.restful_robot.get_motor_register_value(
motor_name, register_name)
}
self.write_json(registers_motors)
class HTTPRobotServer(AbstractServer):
"""Refer to the REST API for an exhaustive list of the possible routes."""
def make_app(self):
PoppyRequestHandler.restful_robot = self.restful_robot
return Application([
(r'/(robot\.json)?', IndexHandler),
(r'/motor/alias/list\.json', MotorsAliasesListHandler),
(r'/motor/(?P[a-zA-Z0-9_]+)/?list\.json', MotorsListHandler),
(r'/sensor/list\.json', SensorsListHandler),
(r'/motor/(?P[a-zA-Z0-9_]+)/register/list\.json', MotorRegistersListHandler),
(r'/sensor/(?P[a-zA-Z0-9_]+)/register/list\.json', MotorRegistersListHandler),
(r'/motor/(?P[a-zA-Z0-9_]+)/register/(?P[a-zA-Z0-9_]+)/list\.json', MotorRegisterHandler),
(r'/sensor/(?P[a-zA-Z0-9_]+)/register/(?P[a-zA-Z0-9_]+)/list\.json', MotorRegisterHandler),
(r'/motor/(?P[a-zA-Z0-9_]+)/register/(?P[a-zA-Z0-9_]+)', MotorRegisterHandler),
(r'/sensor/(?P[a-zA-Z0-9_]+)/register/(?P[a-zA-Z0-9_]+)', MotorRegisterHandler),
(r'/motor/(?P[a-zA-Z0-9_]+)/register/(?P[a-zA-Z0-9_]+)/value\.json', UpdateMotorRegisterHandler),
(r'/sensor/(?P[a-zA-Z0-9_]+)/register/(?P[a-zA-Z0-9_]+)/value\.json', UpdateMotorRegisterHandler),
class MotorRegistersListHandler(PoppyRequestHandler):
def get(self, motor_name):
self.write_json({
'registers': self.restful_robot.get_motor_registers_list(motor_name)
})
class MotorRegisterHandler(PoppyRequestHandler):
def get(self, motor_name, register_name):
self.write_json({
register_name: self.restful_robot.get_motor_register_value(motor_name, register_name)
})
class UpdateMotorRegisterHandler(PoppyRequestHandler):
def post(self, motor_name, register_name):
data = json.loads(self.request.body.decode())
self.restful_robot.set_motor_register_value(motor_name, register_name, data)
self.write_json({})
class PrimitivesListHandler(PoppyRequestHandler):
def get(self):
self.write_json({
'primitives': self.restful_robot.get_primitives_list()
})
class RunningPrimitivesListHandler(PoppyRequestHandler):
def get(self):
self.write_json({
class MotorsListHandler(PoppyRequestHandler):
def get(self, alias='motors'):
self.write_json({
'alias': self.restful_robot.get_motors_list(alias)
})
class SensorsListHandler(PoppyRequestHandler):
def get(self):
self.write_json({
'sensors': self.restful_robot.get_sensors_list()
})
class MotorsAliasesListHandler(PoppyRequestHandler):
def get(self):
self.write_json({
'alias': self.restful_robot.get_motors_alias()
})
class MotorRegistersListHandler(PoppyRequestHandler):
def get(self, motor_name):
self.write_json({
'registers': self.restful_robot.get_motor_registers_list(motor_name)
})
class MotorRegisterHandler(PoppyRequestHandler):
def get(self, motor_name, register_name):
self.write_json({