def _get_notification_data(self, data, content_type): try: serializer = get_onem2m_decoder(content_type) notification = serializer.decode(data) resource = notification.notificationEvent.representation return resource except (KeyError, TypeError, ValueError, IndexError): self.logger.error("Failed to get notification data from %s" % data) return None
def _decode_content(self, request): try: request.content = request.content.read() except AttributeError: pass serializer = get_onem2m_decoder(request.content_type) # TODO: kca: properly handle encodings return serializer.decode_resource_values(request.content)
def index(): assert 'x-m2m-origin' in request.headers, 'No originator set' assert 'x-m2m-ri' in request.headers, 'Missing request id' assert 'content-type' in request.headers, 'Unspecified content type' notification = self._unpack_notification( get_onem2m_decoder(request.content_type).decode(request.data)) self._callback(request.headers['x-m2m-origin'], **notification) return Response(headers={ 'x-m2m-rsc': 2000, }, )
def decode_onem2m_content(content, content_type): if content == "": content = None if content_type and content is not None: serializer = get_onem2m_decoder(content_type) try: data = serializer.decode(content) except CSEValueError as e: logger.exception("Error reading input") raise e return data return None
def index(): assert 'x-m2m-origin' in request.headers, 'No originator set' assert 'x-m2m-ri' in request.headers, 'Missing request id' assert 'content-type' in request.headers, 'Unspecified content type' if not request.data: if request.environ.get('HTTP_TRANSFER_ENCODING') == 'chunked': request.data = request.environ['wsgi.input'].read() else: cl = int(request.environ.get('CONTENT_LENGTH'), 0) request.data = request.environ['wsgi.input'].read(cl) notification = get_onem2m_decoder(request.content_type).decode( request.data) if not notification.verificationRequest: notification = self._unpack_notification(notification) self._callback(request.headers['x-m2m-origin'], **notification) return Response(headers={ 'x-m2m-rsc': 2000, }, )