Exemplo n.º 1
0
 def __init__(self,
              status_code,
              request=None,
              rqi=None,
              pc=None,
              to=None,
              fr=None,
              rsc=None,
              ot=None,
              rset=None,
              ec=None,
              cts=None,
              cto=None,
              rvi=None,
              vsi=None,
              fields=None):
     # Operation result
     if isinstance(status_code, STATUS):
         self.response_status_code = status_code
     else:
         self.response_status_code = get_response_status(status_code)
     if request:
         self.request_identifier = request.rqi
         # Target uri
         self.to = request.to
         # Originator ID
         self.originator = request.fr
         self.originating_timestamp = request.ot
         self.result_expiration_timestamp = request.rset
         self.event_category = request.ec
         self.release_version_indicator = request.rvi
         self.vendor_information = request.vsi
     else:
         self.request_identifier = rqi
         # Target uri
         self.to = to
         # Originator ID
         self.originator = fr
         self.originating_timestamp = ot
         self.release_version_indicator = rvi
         self.vendor_information = vsi
     self.result_expiration_timestamp = rset
     self.event_category = ec
     # Resource content to be transferred.
     self.content = pc
     self.content_status = cts
     self.content_offset = cto
     self.fields = fields
Exemplo n.º 2
0
 def __init__(self, status_code, request=None, rqi=None, pc=None, to=None,
              fr=None, rsc=None):
     # Operation result
     if isinstance(status_code, STATUS):
         self.response_status_code = status_code
     else:
         self.response_status_code = get_response_status(status_code)
     if request:
         self.request_identifier = request.rqi
         # Target uri
         self.to = request.to
         # Originator ID
         self.originator = request.fr
     else:
         self.request_identifier = rqi
         # Target uri
         self.to = to
         # Originator ID
         self.originator = fr
     # Resource content to be transferred.
     self.content = pc
Exemplo n.º 3
0
    def map_http_response_to_onem2m_response(self, onem2m_request, response):
        """
        Maps HTTP response to OneM2M response
        :param onem2m_request: the OneM2M request that created the response
        :param response: the HTTP response
        :return: resulting OneM2MResponse or OneM2MErrorResponse
        """
        if not isinstance(response, HTTPResponse):
            self.logger.error("Not a valid response: %s", response)
            # return OneM2MErrorResponse(STATUS_INTERNAL_SERVER_ERROR)
        self.logger.debug("Mapping HTTP response for OneM2M response: %s", response)
        rsc = response.get("x-m2m-rsc", 5000)
        if int(rsc) >= ERROR_MIN:
            return OneM2MErrorResponse(
                get_error_class(rsc).response_status_code, onem2m_request)

        return OneM2MResponse(
            get_response_status(rsc),
            request=onem2m_request,
            rsc=rsc,
            pc=decode_onem2m_content(response.read(), response.get("content-type"))
        )
Exemplo n.º 4
0
 def wrapper(request):
     if not request.content.verificationRequest:
         notification = self._unpack_notification(request.content)
         self._callback(request.originator, **notification)
     return OneM2MResponse(status_code=get_response_status(2000),
                           request=request)