<s> from __future__ import absolute_import <EOL> __all__ = [ '<STR_LIT>' ] <EOL> class SerializerManager ( object ) : <EOL> def __init__ ( self ) : <EOL> self . registry = { } <EOL> def add ( self , type , cls_or_none = None ) : <EOL> if cls_or_none is not None : <EOL> return self . add ( type ) ( cls_or_none ) <EOL> def wrapped ( cls ) : <EOL> self . registry [ type ] = cls ( ) <EOL> return cls <EOL> return wrapped <EOL> def get ( self , type ) : <EOL> return self . registry [ type ] <EOL> def serialize ( self , value ) : <EOL> if not value : <EOL> return value <EOL> elif not isinstance ( value , ( list , tuple ) ) : <EOL> return self . serialize ( [ value ] ) [ <NUM_LIT:0> ] <EOL> try : <EOL> serializer = self . registry [ type ( value [ <NUM_LIT:0> ] ) ] <EOL> except KeyError : <EOL> return value <EOL> attrs = serializer . get_attrs ( item_list = value ) <EOL> return [ serializer ( o , attrs = attrs . get ( o , { } ) ) for o in value ] <EOL> default_manager = SerializerManager ( ) <EOL> add = default_manager . add <EOL> serialize = default_manager . serialize </s>
