示例#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
示例#2
0
 def test_import_function(self):
     assert import_from_path("nameko.rpc.rpc") is rpc
示例#3
0
 def test_import_module(self):
     assert import_from_path("nameko.rpc") is nameko.rpc
示例#4
0
 def test_import_class(self):
     assert import_from_path("nameko.rpc.Rpc") is Rpc
示例#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)
     )
示例#6
0
 def test_path_is_none(self):
     assert import_from_path(None) is None
示例#7
0
def get_container_cls(config):
    class_path = config.get('SERVICE_CONTAINER_CLS')
    return import_from_path(class_path) or ServiceContainer
示例#8
0
 def test_import_function(self):
     assert import_from_path("nameko.rpc.rpc") is rpc
示例#9
0
 def test_import_module(self):
     assert import_from_path("nameko.rpc") is nameko.rpc
示例#10
0
 def test_import_class(self):
     assert import_from_path("nameko.rpc.Rpc") is Rpc
示例#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)
     )
示例#12
0
 def test_path_is_none(self):
     assert import_from_path(None) is None
示例#13
0
def get_container_cls(config):
    class_path = config.get('SERVICE_CONTAINER_CLS')
    return import_from_path(class_path) or ServiceContainer