def parse_invite(invite_url: str) -> Message: """ Parse an invite url """ matches = re.match('(.+)?c_i=(.+)', invite_url) assert matches, 'Improperly formatted invite url!' invite_msg = Message.deserialize( base64.urlsafe_b64decode(matches.group(2)).decode('ascii')) INVITE_SCHEMA.validate(invite_msg) return invite_msg
def test_message_serialization(): """ Test deserializing and serializing a message """ msg = Message.deserialize('{"@type": "%s"}' % TEST_TYPE) assert msg.type == TEST_TYPE assert msg.id is not None assert msg.doc_uri == 'test_type/' assert msg.protocol == 'protocol' assert msg.version == '1.0' assert msg.short_type == 'test' assert msg.version_info == Semver(1, 0, 0) assert msg.serialize() == \ '{"@type": "%s", "@id": "%s"}' % (TEST_TYPE, msg.id)