<s> """<STR_LIT>""" <EOL> try : <EOL> import simplejson as json <EOL> except ImportError : <EOL> import json <EOL> from bigml . resourcehandler import ResourceHandler <EOL> from bigml . resourcehandler import ( check_resource_type , <EOL> get_sample_id , get_resource_type , <EOL> get_dataset_id , check_resource ) <EOL> from bigml . constants import ( SAMPLE_PATH , DATASET_PATH , <EOL> TINY_RESOURCE ) <EOL> class SampleHandler ( ResourceHandler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> self . sample_url = self . url + SAMPLE_PATH <EOL> def create_sample ( self , dataset , args = None , wait_time = <NUM_LIT:3> , retries = <NUM_LIT:10> ) : <EOL> """<STR_LIT>""" <EOL> dataset_id = None <EOL> resource_type = get_resource_type ( dataset ) <EOL> if resource_type == DATASET_PATH : <EOL> dataset_id = get_dataset_id ( dataset ) <EOL> check_resource ( dataset_id , <EOL> query_string = TINY_RESOURCE , <EOL> wait_time = wait_time , retries = retries , <EOL> raise_on_error = True , api = self ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" % resource_type ) <EOL> create_args = { } <EOL> if args is not None : <EOL> create_args . update ( args ) <EOL> create_args . update ( { <EOL> "<STR_LIT>" : dataset_id } ) <EOL> body = json . dumps ( create_args ) <EOL> return self . _create ( self . sample_url , body ) <EOL> def get_sample ( self , sample , query_string = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> check_resource_type ( sample , SAMPLE_PATH , <EOL> message = "<STR_LIT>" ) <EOL> sample_id = get_sample_id ( sample ) <EOL> if sample_id : <EOL> return self . _get ( "<STR_LIT>" % ( self . url , sample_id ) , <EOL> query_string = query_string ) <EOL> def list_samples ( self , query_string = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> return self . _list ( self . sample_url , query_string ) <EOL> def update_sample ( self , sample , changes ) : <EOL> """<STR_LIT>""" <EOL> check_resource_type ( sample , SAMPLE_PATH , <EOL> message = "<STR_LIT>" ) <EOL> sample_id = get_sample_id ( sample ) <EOL> if sample_id : <EOL> body = json . dumps ( changes ) <EOL> return self . _update ( "<STR_LIT>" % ( self . url , sample_id ) , body ) <EOL> def delete_sample ( self , sample ) : <EOL> """<STR_LIT>""" <EOL> check_resource_type ( sample , SAMPLE_PATH , <EOL> message = "<STR_LIT>" ) <EOL> sample_id = get_sample_id ( sample ) <EOL> if sample_id : <EOL> return self . _delete ( "<STR_LIT>" % ( self . url , sample_id ) ) </s>
