mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
* Problem: Source files contain no license info Solution: Add comments with SPDX license info to source files * Python 3 files don't need # -*- coding: utf-8 -*-
27 lines
1.0 KiB
Python
27 lines
1.0 KiB
Python
# Copyright BigchainDB GmbH and BigchainDB contributors
|
|
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
|
# Code is Apache-2.0 and docs are CC-BY-4.0
|
|
|
|
|
|
class ModuleDispatchRegistrationError(Exception):
|
|
"""Raised when there is a problem registering dispatched functions for a
|
|
module
|
|
"""
|
|
|
|
|
|
def module_dispatch_registrar(module):
|
|
def dispatch_wrapper(obj_type):
|
|
def wrapper(func):
|
|
func_name = func.__name__
|
|
try:
|
|
dispatch_registrar = getattr(module, func_name)
|
|
return dispatch_registrar.register(obj_type)(func)
|
|
except AttributeError as ex:
|
|
raise ModuleDispatchRegistrationError(
|
|
('`{module}` does not contain a single-dispatchable '
|
|
'function named `{func}`. The module being registered '
|
|
'was not implemented correctly!').format(
|
|
func=func_name, module=module.__name__)) from ex
|
|
return wrapper
|
|
return dispatch_wrapper
|