How to use the tomodachi.helpers.dict.merge_dicts function in tomodachi

To help you get started, we’ve selected a few tomodachi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kalaspuff / tomodachi / tomodachi / transport / aws_sns_sqs.py View on Github external
async def routine_func(*a: Any, **kw: Any) -> Any:
                try:
                    if not message_protocol and len(values.args[1:]):
                        routine = func(*(obj, message, *a))
                    elif len(merge_dicts(kwargs, kw)):
                        routine = func(*(obj, *a), **merge_dicts(kwargs, kw))
                    elif len(values.args[1:]):
                        routine = func(*(obj, message, *a), **kw)
                    else:
                        routine = func(*(obj, *a), **kw)
                except Exception as e:
                    logging.getLogger('exception').exception('Uncaught exception: {}'.format(str(e)))
                    if issubclass(e.__class__, (AWSSNSSQSInternalServiceError, AWSSNSSQSInternalServiceErrorException, AWSSNSSQSInternalServiceException)):
                        if message_key:
                            del context['_aws_sns_sqs_received_messages'][message_key]
                        return
                    await cls.delete_message(cls, receipt_handle, queue_url, context)
                    return

                if isinstance(routine, Awaitable):
                    try:
                        return_value = await routine
github kalaspuff / tomodachi / tomodachi / transport / aws_sns_sqs.py View on Github external
async def routine_func(*a: Any, **kw: Any) -> Any:
                try:
                    if not message_protocol and len(values.args[1:]):
                        routine = func(*(obj, message, *a))
                    elif len(merge_dicts(kwargs, kw)):
                        routine = func(*(obj, *a), **merge_dicts(kwargs, kw))
                    elif len(values.args[1:]):
                        routine = func(*(obj, message, *a), **kw)
                    else:
                        routine = func(*(obj, *a), **kw)
                except Exception as e:
                    logging.getLogger('exception').exception('Uncaught exception: {}'.format(str(e)))
                    if issubclass(e.__class__, (AWSSNSSQSInternalServiceError, AWSSNSSQSInternalServiceErrorException, AWSSNSSQSInternalServiceException)):
                        if message_key:
                            del context['_aws_sns_sqs_received_messages'][message_key]
                        return
                    await cls.delete_message(cls, receipt_handle, queue_url, context)
                    return

                if isinstance(routine, Awaitable):
                    try:
github kalaspuff / tomodachi / tomodachi / transport / http.py View on Github external
result = compiled_pattern.match(request.path)
            values = inspect.getfullargspec(func)
            kwargs = {k: values.defaults[i] for i, k in enumerate(values.args[len(values.args) - len(values.defaults):])} if values.defaults else {}
            if result:
                for k, v in result.groupdict().items():
                    kwargs[k] = v

            if len(values.args) - (len(values.defaults) if values.defaults else 0) >= 3:
                # If the function takes a third required argument the value will be filled with the request object
                a = a + (request,)
            if 'request' in values.args and (len(values.args) - (len(values.defaults) if values.defaults else 0) < 3 or values.args[2] != 'request'):
                kwargs['request'] = request

            try:
                routine = func(*(obj, websocket, *a), **merge_dicts(kwargs, kw))
                callback_functions = (await routine) if isinstance(routine, Awaitable) else routine  # type: Optional[Union[Tuple, Callable]]
            except Exception as e:
                logging.getLogger('exception').exception('Uncaught exception: {}'.format(str(e)))
                try:
                    await websocket.close()
                except Exception:
                    pass

                try:
                    context['_http_open_websockets'].remove(websocket)
                except Exception:
                    pass

                if access_log:
                    logging.getLogger('transport.http').info('[{}] {} {} "{} {}{}" {} "{}" {}'.format(
                        RequestHandler.colorize_status('websocket', 500),
github kalaspuff / tomodachi / tomodachi / transport / amqp.py View on Github external
async def routine_func(*a: Any, **kw: Any) -> Any:
                try:
                    if not message_protocol and len(values.args[1:]):
                        routine = func(*(obj, message, *a))
                    elif len(merge_dicts(kwargs, kw)):
                        routine = func(*(obj, *a), **merge_dicts(kwargs, kw))
                    elif len(values.args[1:]):
                        routine = func(*(obj, message, *a), **kw)
                    else:
                        routine = func(*(obj, *a), **kw)
                except Exception as e:
                    logging.getLogger('exception').exception('Uncaught exception: {}'.format(str(e)))
                    if issubclass(e.__class__, (AmqpInternalServiceError, AmqpInternalServiceErrorException, AmqpInternalServiceException)):
                        if message_key:
                            del context['_amqp_received_messages'][message_key]
                        await cls.channel.basic_client_nack(delivery_tag)
                        return
                    await cls.channel.basic_client_ack(delivery_tag)
                    return

                if isinstance(routine, Awaitable):
github kalaspuff / tomodachi / tomodachi / config.py View on Github external
def parse_config_files(config_files: List[str]) -> Optional[Dict]:
    if not config_files:
        return None
    if isinstance(config_files, str):
        config_files = [config_files]

    configuration = {}  # type: Dict

    for config_file in config_files:
        with open(config_file) as f:
            data = f.read()
            json_data = json.loads(data)

            configuration = merge_dicts(configuration, json_data)

    return configuration
github kalaspuff / tomodachi / tomodachi / transport / amqp.py View on Github external
async def routine_func(*a: Any, **kw: Any) -> Any:
                try:
                    if not message_protocol and len(values.args[1:]):
                        routine = func(*(obj, message, *a))
                    elif len(merge_dicts(kwargs, kw)):
                        routine = func(*(obj, *a), **merge_dicts(kwargs, kw))
                    elif len(values.args[1:]):
                        routine = func(*(obj, message, *a), **kw)
                    else:
                        routine = func(*(obj, *a), **kw)
                except Exception as e:
                    logging.getLogger('exception').exception('Uncaught exception: {}'.format(str(e)))
                    if issubclass(e.__class__, (AmqpInternalServiceError, AmqpInternalServiceErrorException, AmqpInternalServiceException)):
                        if message_key:
                            del context['_amqp_received_messages'][message_key]
                        await cls.channel.basic_client_nack(delivery_tag)
                        return
                    await cls.channel.basic_client_ack(delivery_tag)
                    return

                if isinstance(routine, Awaitable):
                    try: