<s> class JSONType ( object ) : <EOL> """<STR_LIT>""" <EOL> json_types = { <EOL> '<STR_LIT>' : ( bool , ) , <EOL> '<STR_LIT>' : ( float , int ) , <EOL> '<STR_LIT:str>' : ( basestring , str , unicode ) , <EOL> '<STR_LIT>' : ( list , ) , <EOL> '<STR_LIT>' : ( dict , ) , <EOL> '<STR_LIT>' : ( None , ) , <EOL> '<STR_LIT>' : ( bool , float , int , str , unicode , list , dict , None ) , <EOL> } <EOL> def __init__ ( self , type_key ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . _types = self . json_types [ type_key ] <EOL> except KeyError : <EOL> raise ValueError ( '<STR_LIT>' . format ( type_key ) ) <EOL> else : <EOL> self . _json_type_code = type_key <EOL> def __eq__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return other in self . _types <EOL> def __repr__ ( self ) : <EOL> return self . _json_type_code <EOL> @ classmethod <EOL> def by_python_type ( cls , p_type ) : <EOL> """<STR_LIT>""" <EOL> for key , python_types in cls . json_types . iteritems ( ) : <EOL> if not key == '<STR_LIT>' and p_type in python_types : <EOL> return cls ( key ) <EOL> raise ValueError ( u'<STR_LIT>' . format ( t = p_type ) ) <EOL> def __unicode__ ( self ) : <EOL> return self . _json_type_code <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import doctest <EOL> doctest . testmod ( ) </s>
