Beispiel #1
0
def parse(data):
    '''
	Unpacks data string into JSON object. Ensures basic props are there.
	'''

    # 1. let's inspect the wrapper message
    try:
        message = json_decode(data)
    except Exception as ex:
        raise ex

    if 'method' not in message or 'params' not in message or \
     message['method'] not in ALLOWED_COMMANDS:
        raise Exception(
            "MessageParser: Did not find proper components in the message.")

    # JSON-RPC style child args
    return (
        message['method'],
        message.get(
            'params', {}
        )  # when there are no args to pass, JSON-RPC allows to ommit 'params'
        ,
        message.get('id',
                    None)  # lack of 'id' elem = 'Notify' mode in JSON-RPC
    )
def parse(message):
	'''
	Parses and validates (against Protocol v7) the incoming string.
	Returns Dictionary structure (as parsed from received JSON string)
	'''
	# we only talk and validate V7 protocol.

	command_not_found = {'command':'not found'}

	try:
		message = json_decode(message)
	except Exception as ex:
		logging.debug("MessageParser: Were not able to JSON parse the message. '%s'" % ex)
		return command_not_found

	if 'command' not in message or message['command'] not in ALLOWED_COMMANDS:
		logging.debug("MessageParser: Did not find proper command in the message.")
		return command_not_found

	### HELLO
	if message['command'] == 'hello' and 'protocols' in message:
		return message
	### INFO and URL (update push from client)
	elif message['command'] in ('info','url') and 'url' in message:
		return message
	else:
		return command_not_found
Beispiel #3
0
def parse(message):
    '''
	Parses and validates (against Protocol v7) the incoming string.
	Returns Dictionary structure (as parsed from received JSON string)
	'''
    # we only talk and validate V7 protocol.

    command_not_found = {'command': 'not found'}

    try:
        message = json_decode(message)
    except Exception as ex:
        logging.debug(
            "MessageParser: Were not able to JSON parse the message. '%s'" %
            ex)
        return command_not_found

    if 'command' not in message or message['command'] not in ALLOWED_COMMANDS:
        logging.debug(
            "MessageParser: Did not find proper command in the message.")
        return command_not_found

    ### HELLO
    if message['command'] == 'hello' and 'protocols' in message:
        return message
    ### INFO and URL (update push from client)
    elif message['command'] in ('info', 'url') and 'url' in message:
        return message
    else:
        return command_not_found
def parse(data):
	'''
	Unpacks data string into JSON object. Ensures basic props are there.
	'''

	# 1. let's inspect the wrapper message
	try:
		message = json_decode(data)
	except Exception as ex:
		raise ex

	if 'method' not in message or 'params' not in message or \
		message['method'] not in ALLOWED_COMMANDS:
		raise Exception("MessageParser: Did not find proper components in the message.")

	# JSON-RPC style child args
	return (
		message['method']
		, message.get('params', {}) # when there are no args to pass, JSON-RPC allows to ommit 'params'
		, message.get('id', None) # lack of 'id' elem = 'Notify' mode in JSON-RPC
	)