def render_GET_advanced(self, request, response): #enviar mensagem padrao de funcionando self.payload = request.payload logger.debug("\ndentro do get ") #,self.payload) request.parame assert (isinstance(response, Response)) response.mid = request.mid defines.acknowledged = True caminhos = request.uri_path.split("/") if caminhos[1] == "save": DBRegister.saveToFile("./registro.txt") response.payload = "dados salvos" self.payload = "dados salvos" response.code = defines.Codes.CREATED.number #CREATED.number print("dentro do save") elif caminhos[1] == "load": DBRegister.loadFromFile("./registro.txt") response.payload = "dados carregados" self.payload = "dados carregados" response.code = defines.Codes.CREATED.number #CREATED.number print("dentro do load") else: logger.debug("opcao invalida") response.code = defines.Codes.NOT_IMPLEMENTED.number #CREATED.number return self, response
def render_PUT(self, request): #registra dispositivo na memoria/BD #self.payload = request.payload logger.debug("\ndentro do put ") DBRegister.saveToFile("./registro.txt") response.payload = "dados salvos" self.payload = "dados salvos" response.code = defines.Codes.CREATED.number #CREATED.number print("dentro do save") return self
def render_POST_advanced(self, request, response): logger.debug("entrou no post advanced login") self.payload = request.payload par = Request() device = request.payload adevice = device.split(",") ''' print ("device :",device) print ("adevice :",adevice) print ("request :",request) print ("uri_path :",request.uri_path) print ("senha :", gerar_senha(device)) print ("usuario :", gerar_usuario(device)) print ("timestamp:", time.strftime('%Y%m%d%H%M%S')) ''' caminhos = request.uri_path.split("/") #logger.("caminhos :",caminhos) #url = urlparse(request.uri_path) """ for d in adevice: logger.debug("dados:",str(d)) """ hash_code = self.gerar_hash(device) register_response = self.device_register(hash_code, device) from coapthon.messages.response import Response assert (isinstance(response, Response)) response.payload = "" + register_response self.payload = "" + register_response response.code = defines.Codes.CHANGED.number #CREATED.number response.mid = request.mid defines.acknowledged = True print("response.token:", response.token) print("request.token:", request.token) print("response.mid:", response.mid) print("request.mid:", request.mid) DBRegister.saveToFile("./registro.txt") #print("response:",response) return self, response