<s> import collections <EOL> from ooi . occi . rendering import headers as header_rendering <EOL> from ooi . occi . rendering import text as text_rendering <EOL> from ooi . occi . rendering import urilist as urilist_rendering <EOL> from ooi . wsgi import utils <EOL> _MEDIA_TYPE_MAP = collections . OrderedDict ( [ <EOL> ( '<STR_LIT>' , '<STR_LIT:text>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ] ) <EOL> class BaseSerializer ( object ) : <EOL> def __init__ ( self , env ) : <EOL> self . env = env <EOL> class TextSerializer ( BaseSerializer ) : <EOL> def serialize ( self , data ) : <EOL> if not isinstance ( data , list ) : <EOL> data = [ data ] <EOL> renderers = [ ] <EOL> for d in data : <EOL> renderers . append ( text_rendering . get_renderer ( d ) ) <EOL> ret = "<STR_LIT:\n>" . join ( [ r . render ( env = self . env ) for r in renderers ] ) <EOL> return None , utils . utf8 ( ret ) <EOL> class HeaderSerializer ( BaseSerializer ) : <EOL> def serialize ( self , data ) : <EOL> if not isinstance ( data , list ) : <EOL> data = [ data ] <EOL> renderers = [ ] <EOL> for d in data : <EOL> renderers . append ( header_rendering . get_renderer ( d ) ) <EOL> headers = [ i for r in renderers for i in r . render ( env = self . env ) ] <EOL> return headers , utils . utf8 ( "<STR_LIT>" ) <EOL> class UriListSerializer ( TextSerializer ) : <EOL> def serialize ( self , data ) : <EOL> if not isinstance ( data , list ) : <EOL> data = [ data ] <EOL> renderers = [ ] <EOL> for d in data : <EOL> renderers . append ( urilist_rendering . get_renderer ( d ) ) <EOL> ret = "<STR_LIT:\n>" . join ( [ r . render ( env = self . env ) for r in renderers ] ) <EOL> return None , utils . utf8 ( ret ) <EOL> _SERIALIZERS_MAP = { <EOL> "<STR_LIT:text>" : TextSerializer , <EOL> "<STR_LIT>" : HeaderSerializer , <EOL> "<STR_LIT>" : UriListSerializer , <EOL> } <EOL> def get_media_map ( ) : <EOL> return _MEDIA_TYPE_MAP <EOL> def get_default_serializers ( ) : <EOL> return _SERIALIZERS_MAP <EOL> def get_supported_content_types ( ) : <EOL> return _MEDIA_TYPE_MAP . keys ( ) </s>
