#NEWLINE# def register_serializer( format , serializer_module , serializers = None ) : #NEWLINE# #INDENT# 'Register a new serializer.\n\n    ``serializer_module`` should be the fully qualified module name\n    for the serializer.\n\n    If ``serializers`` is provided, the registration will be added\n    to the provided dictionary.\n\n    If ``serializers`` is not provided, the registration will be made\n    directly into the global register of serializers. Adding serializers\n    directly is not a thread-safe operation.\n    ' #NEWLINE# if ( ( serializers is None ) and ( not _serializers ) ) : #NEWLINE# #INDENT# _load_serializers ( ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# module = importlib . import_module ( serializer_module ) #NEWLINE# #UNINDENT# except ImportError as exc : #NEWLINE# #INDENT# bad_serializer = BadSerializer ( exc ) #NEWLINE# module = type ( 'BadSerializerModule' , ( object , ) , { #NEWLINE# #INDENT# 'Deserializer' : bad_serializer , #NEWLINE# 'Serializer' : bad_serializer , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# if ( serializers is None ) : #NEWLINE# #INDENT# _serializers [ format ] = module #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# serializers [ format ] = module