<s> import six <EOL> from wsme import types as wtypes <EOL> class ExceptionType ( wtypes . UserType ) : <EOL> basetype = wtypes . DictType <EOL> name = '<STR_LIT>' <EOL> def validate ( self , value ) : <EOL> if not isinstance ( value , BaseException ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> return value <EOL> def tobasetype ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return { <EOL> '<STR_LIT:type>' : value . __class__ . __name__ , <EOL> '<STR_LIT:code>' : getattr ( value , '<STR_LIT>' , <NUM_LIT> ) , <EOL> '<STR_LIT:message>' : str ( value ) , <EOL> '<STR_LIT>' : getattr ( value , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } <EOL> frombasetype = tobasetype <EOL> exception_type = ExceptionType ( ) <EOL> class MultiType ( wtypes . UserType ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * types ) : <EOL> self . types = types <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' . join ( map ( str , self . types ) ) <EOL> def validate ( self , value ) : <EOL> for t in self . types : <EOL> if t is wtypes . text and isinstance ( value , wtypes . bytes ) : <EOL> value = value . decode ( ) <EOL> if isinstance ( value , t ) : <EOL> return value <EOL> else : <EOL> raise ValueError ( <EOL> "<STR_LIT>" . format ( <EOL> type = self . types , value = type ( value ) ) ) <EOL> json_type = MultiType ( list , dict , six . integer_types , wtypes . text ) <EOL> class APIBase ( wtypes . Base ) : <EOL> pass </s>
