Ejemplo n.º 1
0
def setup(config):

    serializers = deepcopy(config.get(SERIALIZERS_CONFIG_KEY, {}))
    for name, kwargs in serializers.items():
        encoder = import_from_path(kwargs.pop('encoder'))
        decoder = import_from_path(kwargs.pop('decoder'))
        kombu.serialization.register(name,
                                     encoder=encoder,
                                     decoder=decoder,
                                     **kwargs)

    serializer = config.get(SERIALIZER_CONFIG_KEY, DEFAULT_SERIALIZER)

    accept = config.get(ACCEPT_CONFIG_KEY, [serializer])

    for name in [serializer] + accept:
        try:
            kombu.serialization.registry.name_to_type[name]
        except KeyError:
            raise ConfigurationError(
                'Please register a serializer for "{}" format'.format(name))

    return serializer, accept
Ejemplo n.º 2
0
 def test_import_function(self):
     assert import_from_path("nameko.rpc.rpc") is rpc
Ejemplo n.º 3
0
 def test_import_module(self):
     assert import_from_path("nameko.rpc") is nameko.rpc
Ejemplo n.º 4
0
 def test_import_class(self):
     assert import_from_path("nameko.rpc.Rpc") is Rpc
Ejemplo n.º 5
0
 def test_import_error(self):
     with pytest.raises(ImportError) as exc_info:
         import_from_path("foo.bar.Baz")
     assert (
         "`foo.bar.Baz` could not be imported" in str(exc_info.value)
     )
Ejemplo n.º 6
0
 def test_path_is_none(self):
     assert import_from_path(None) is None
Ejemplo n.º 7
0
def get_container_cls(config):
    class_path = config.get('SERVICE_CONTAINER_CLS')
    return import_from_path(class_path) or ServiceContainer
Ejemplo n.º 8
0
 def test_import_function(self):
     assert import_from_path("nameko.rpc.rpc") is rpc
Ejemplo n.º 9
0
 def test_import_module(self):
     assert import_from_path("nameko.rpc") is nameko.rpc
Ejemplo n.º 10
0
 def test_import_class(self):
     assert import_from_path("nameko.rpc.Rpc") is Rpc
Ejemplo n.º 11
0
 def test_import_error(self):
     with pytest.raises(ImportError) as exc_info:
         import_from_path("foo.bar.Baz")
     assert (
         "`foo.bar.Baz` could not be imported" in str(exc_info.value)
     )
Ejemplo n.º 12
0
 def test_path_is_none(self):
     assert import_from_path(None) is None
Ejemplo n.º 13
0
def get_container_cls(config):
    class_path = config.get('SERVICE_CONTAINER_CLS')
    return import_from_path(class_path) or ServiceContainer