def __init__(self, url):
     for link in url:
         self.start_urls.append(link["url"])
         category = link["Category"]
         service_name = link["ServiceName"]
         dict_url[link["url"]] = {
             "Category": category,
             "Service Name": service_name
         }
         response = Response("Service")
         response.Service_Name = service_name
         response.Category = category
         response.URL = link["url"]
         final_json[service_name] = {"response": response}
    def read_input(self):
        input = {}
        for device in self.__devices:
            values = {}
            connection = self.__devices[device].get_connection()
            if connection.inWaiting():
                response = connection.read_until(terminator=to_bytes(
                    [13, 10]))  # End with CR LF
                values = Response(response[:-2]).decode()

            input[device] = values

        return input
示例#3
0
    def __onMessage(self, client, userdata, message):
        Logger.info('Received response. Client   : ' + str(client))
        Logger.info('Received response. User data: ' + str(userdata))
        Logger.info('Received response. Message  : ' + str(message))

        response = Response()
        response_json = json.loads(message.payload)
        response.setId(response_json['id'])
        response.setReplyHost(str(response_json['replyHost']).strip())
        response.setReplyPort(int(response_json['replyPort']))
        response.setReplyChannel(str(response_json['replyChannel']).strip())
        response.setVersionProtocol(
            str(response_json['versionProtocol']).strip())
        response.setStatusCode(response_json['statusCode'])
        response.setStatusMessage(str(response_json['statusMessage']).strip())
        response.setHeader(str(response_json['header']).strip())
        response.setBody(str(response_json['body']).strip())

        self.__responseService.route(response)
示例#4
0
    def delete(self, request):
        responseDelete = requests.delete(self.__url + request.getUri())

        response = Response()
        response.setId(request.getId())
        response.setReplyHost(str(request.getReplyHost()))
        response.setReplyPort(int(request.getReplyPort()))
        response.setReplyChannel(str(request.getReplyChannel()))
        response.setVersionProtocol('HTTP/1.0' if responseDelete.raw.version ==
                                    10 else 'HTTP/1.1')
        response.setStatusCode(int(responseDelete.status_code))
        response.setStatusMessage(str(responseDelete.reason))
        response.setHeader(str(responseDelete.headers))
        response.setBody(str(responseDelete.text))

        self.__responseProducer.produce(response)
示例#5
0
    def update(self, request):
        body = json.loads(request.getBody().replace("'", '"'))
        responsePatch = requests.patch(self.__url + request.getUri(),
                                       json=body)

        response = Response()
        response.setId(request.getId())
        response.setReplyHost(str(request.getReplyHost()))
        response.setReplyPort(int(request.getReplyPort()))
        response.setReplyChannel(str(request.getReplyChannel()))
        response.setVersionProtocol('HTTP/1.0' if responsePatch.raw.version ==
                                    10 else 'HTTP/1.1')
        response.setStatusCode(int(responsePatch.status_code))
        response.setStatusMessage(str(responsePatch.reason))
        response.setHeader(str(responsePatch.headers))
        response.setBody(str(responsePatch.text))

        self.__responseProducer.produce(response)