def handle(self, request: Request) -> Response: try: data_in_vending = request.body.readline().decode().strip()[:32] vm_pub, vm_private = self.vm_keys.add_new_vending_machine_items(data_in_vending, 8) return Response(200, f"{vm_pub}:{':'.join(vm_private)}".encode()) except (TypeError, ValueError): return Response(400, b'Bad Request')
def handle(self, request: Request) -> Response: try: machine, key = request.body.readline().decode().split() return Response(200, (self.vm_keys[machine][key]).encode()) except (IndexError, KeyError): return Response(404, b'Not Found') except (TypeError, ValueError): return Response(400, b'Bad Request')
def handle(self, request: Request) -> Response: if request.path not in self.route_table: return Response(404, b'Not Found') if request.method not in self.route_table[request.path]: return Response( 405, b'Method not allowed!', (("Allow", ','.join(self.route_table[request.path].keys())), )) return self.route_table[request.path][request.method].handle(request)
def handle(self, request: Request) -> Response: try: return Response( 200, bytes( self.vm.get_machine_manufacturer( int(request.body.readline().decode())))) except (TypeError, ValueError): return Response(400, b'Bad Request')
def handle(self, request: Request) -> Response: try: vm_id, key = request.body.readline().decode().split() return Response( 200, bytes(self.vm.get_master_info(int(vm_id), key.encode('ascii')))) except (TypeError, ValueError): return Response(400, b'Bad Request')
def handle(self, request: Request) -> Response: try: name, inventor, meta, key, master_key = request.body.readline().decode().strip().split() except (TypeError, ValueError): return Response(400, b'Bad request') res = self.vm.add_new_machine(name, inventor, meta, key, master_key) if res is not None: return Response(200, b"Created:" + str(res).encode()) return Response(400, b'Bad request')
def handle(self, request: Request) -> Response: return Response(200, DOCS, (("Content-Type", "text/plain"), ))