<s> import wsme <EOL> import wsme . types <EOL> try : <EOL> import simplejson as json <EOL> except ImportError : <EOL> import json <EOL> class ReadResultBase ( wsme . types . Base ) : <EOL> total = int <EOL> success = bool <EOL> message = wsme . types . text <EOL> def make_readresult ( datatype ) : <EOL> ReadResult = type ( <EOL> datatype . __name__ + '<STR_LIT>' , <EOL> ( ReadResultBase , ) , { <EOL> '<STR_LIT:data>' : [ datatype ] <EOL> } <EOL> ) <EOL> return ReadResult <EOL> class DataStoreControllerMeta ( type ) : <EOL> def __init__ ( cls , name , bases , dct ) : <EOL> if cls . __datatype__ is None : <EOL> return <EOL> if getattr ( cls , '<STR_LIT>' , None ) is None : <EOL> cls . __readresulttype__ = make_readresult ( cls . __datatype__ ) <EOL> cls . create = wsme . expose ( <EOL> cls . __readresulttype__ , <EOL> extdirect_params_notation = '<STR_LIT>' ) ( cls . create ) <EOL> cls . create = wsme . validate ( cls . __datatype__ ) ( cls . create ) <EOL> cls . read = wsme . expose ( <EOL> cls . __readresulttype__ , <EOL> extdirect_params_notation = '<STR_LIT>' ) ( cls . read ) <EOL> cls . read = wsme . validate ( str , str , int , int , int ) ( cls . read ) <EOL> cls . update = wsme . expose ( <EOL> cls . __readresulttype__ , <EOL> extdirect_params_notation = '<STR_LIT>' ) ( cls . update ) <EOL> cls . update = wsme . validate ( cls . __datatype__ ) ( cls . update ) <EOL> cls . destroy = wsme . expose ( <EOL> cls . __readresulttype__ , <EOL> extdirect_params_notation = '<STR_LIT>' ) ( cls . destroy ) <EOL> cls . destroy = wsme . validate ( cls . __idtype__ ) ( cls . destroy ) <EOL> class DataStoreControllerMixin ( object ) : <EOL> __datatype__ = None <EOL> __idtype__ = int <EOL> __readresulttype__ = None <EOL> def create ( self , obj ) : <EOL> pass <EOL> def read ( self , query = None , sort = None , page = None , start = None , limit = None ) : <EOL> pass <EOL> def update ( self , obj ) : <EOL> pass <EOL> def destroy ( self , obj_id ) : <EOL> pass <EOL> def model ( self ) : <EOL> tpl = """<STR_LIT>""" <EOL> fields = [ <EOL> attr . name for attr in self . __datatype__ . _wsme_attributes <EOL> ] <EOL> d = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' + self . __datatype__ . __name__ . lower ( ) , <EOL> '<STR_LIT>' : self . __datatype__ . __name__ , <EOL> '<STR_LIT>' : json . dumps ( fields ) <EOL> } <EOL> return tpl % d <EOL> def store ( self ) : <EOL> tpl = """<STR_LIT>""" <EOL> d = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . __datatype__ . __name__ , <EOL> } <EOL> return tpl % d <EOL> DataStoreController = DataStoreControllerMeta ( <EOL> '<STR_LIT>' , <EOL> ( DataStoreControllerMixin , ) , { } <EOL> ) </s>
