def link_format_from_message(message): try: if message.opt.content_format == aiocoap.numbers.media_types_rev['application/link-format']: return link_header.parse(message.payload.decode('utf8')) # FIXME this should support json/cbor too else: raise error.UnsupportedMediaType() except (UnicodeDecodeError, link_header.ParseException): raise error.BadRequest()
def link_format_from_message(message): try: if message.opt.content_format == media_types_rev['application/link-format']: return parse(message.payload.decode('utf8')) elif message.opt.content_format == media_types_rev['application/link-format+json']: return LinkFormat.from_json_string(message.payload.decode('utf8')) elif message.opt.content_format == media_types_rev['application/link-format+cbor']: return LinkFormat.from_cbor_bytes(message.payload) else: raise error.UnsupportedMediaType() except (UnicodeDecodeError, link_header.ParseException): raise error.BadRequest()
def link_format_from_message(message): """Convert a response message into a LinkFormat object This expects an explicit media type set on the response (or was explicitly requested) """ certain_format = message.opt.content_format if certain_format is None: certain_format = message.request.opt.accept try: if certain_format == ContentFormat.LINKFORMAT: return parse(message.payload.decode('utf8')) else: raise error.UnsupportedMediaType() except (UnicodeDecodeError, link_header.ParseException): raise error.BadRequest()
def link_format_from_message(message): """Convert a response message into a LinkFormat object This expects an explicit media type set on the response (or was explicitly requested) """ certain_format = message.opt.content_format if certain_format is None: certain_format = message.request.opt.accept try: if certain_format == media_types_rev['application/link-format']: return parse(message.payload.decode('utf8')) elif certain_format == media_types_rev['application/link-format+json']: return LinkFormat.from_json_string(message.payload.decode('utf8')) elif certain_format == media_types_rev['application/link-format+cbor']: return LinkFormat.from_cbor_bytes(message.payload) else: raise error.UnsupportedMediaType() except (UnicodeDecodeError, link_header.ParseException): raise error.BadRequest()