<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from hug . decorators import auto_kwargs <EOL> def content_type ( transformers , default = None ) : <EOL> """<STR_LIT>""" <EOL> transformers = { content_type : auto_kwargs ( transformer ) if transformer else transformer <EOL> for content_type , transformer in transformers . items ( ) } <EOL> default = default and auto_kwargs ( default ) <EOL> def transform ( data , request ) : <EOL> transformer = transformers . get ( request . content_type . split ( '<STR_LIT:;>' ) [ <NUM_LIT:0> ] , default ) <EOL> if not transformer : <EOL> return data <EOL> return transformer ( data ) <EOL> return transform <EOL> def suffix ( transformers , default = None ) : <EOL> """<STR_LIT>""" <EOL> transformers = { suffix : auto_kwargs ( transformer ) if transformer <EOL> else transformer for suffix , transformer in transformers . items ( ) } <EOL> default = default and auto_kwargs ( default ) <EOL> def transform ( data , request ) : <EOL> path = request . path <EOL> transformer = default <EOL> for suffix_test , suffix_transformer in transformers . items ( ) : <EOL> if path . endswith ( suffix_test ) : <EOL> transformer = suffix_transformer <EOL> break <EOL> return transformer ( data ) if transformer else data <EOL> return transform <EOL> def prefix ( transformers , default = None ) : <EOL> """<STR_LIT>""" <EOL> transformers = { prefix : auto_kwargs ( transformer ) if transformer else transformer <EOL> for prefix , transformer in transformers . items ( ) } <EOL> default = default and auto_kwargs ( default ) <EOL> def transform ( data , request = None , response = None ) : <EOL> path = request . path <EOL> transformer = default <EOL> for prefix_test , prefix_transformer in transformers . items ( ) : <EOL> if path . startswith ( prefix_test ) : <EOL> transformer = prefix_transformer <EOL> break <EOL> return transformer ( data ) if transformer else data <EOL> return transform <EOL> def all ( * transformers ) : <EOL> """<STR_LIT>""" <EOL> transformers = tuple ( auto_kwargs ( transformer ) for transformer in transformers ) <EOL> def transform ( data , request = None , response = None ) : <EOL> for transformer in transformers : <EOL> data = transformer ( data , request = request , response = response ) <EOL> return data <EOL> return transform </s>
