<s> from contextlib import closing <EOL> import httplib <EOL> import json <EOL> from bottle import abort , local , post , request <EOL> from codalab . server . authenticated_plugin import AuthenticatedPlugin <EOL> @ post ( '<STR_LIT>' , <EOL> apply = AuthenticatedPlugin ( ) ) <EOL> def checkin ( worker_id ) : <EOL> """<STR_LIT>""" <EOL> WAIT_TIME_SECS = <NUM_LIT> <EOL> socket_id = local . worker_model . worker_checkin ( <EOL> request . user . user_id , worker_id , <EOL> request . json [ '<STR_LIT>' ] , request . json [ '<STR_LIT>' ] ) <EOL> with closing ( local . worker_model . start_listening ( socket_id ) ) as sock : <EOL> return local . worker_model . get_json_message ( sock , WAIT_TIME_SECS ) <EOL> @ post ( '<STR_LIT>' , <EOL> apply = AuthenticatedPlugin ( ) ) <EOL> def checkout ( worker_id ) : <EOL> """<STR_LIT>""" <EOL> local . worker_model . worker_cleanup ( request . user . user_id , worker_id ) <EOL> def check_reply_permission ( worker_id , socket_id ) : <EOL> """<STR_LIT>""" <EOL> if not local . worker_model . has_reply_permission ( request . user . user_id , worker_id , socket_id ) : <EOL> abort ( httplib . FORBIDDEN , '<STR_LIT>' ) <EOL> @ post ( '<STR_LIT>' , <EOL> apply = AuthenticatedPlugin ( ) ) <EOL> def reply ( worker_id , socket_id ) : <EOL> """<STR_LIT>""" <EOL> check_reply_permission ( worker_id , socket_id ) <EOL> local . worker_model . send_json_message ( socket_id , request . json , <NUM_LIT> , autoretry = False ) <EOL> @ post ( '<STR_LIT>' , <EOL> apply = AuthenticatedPlugin ( ) ) <EOL> def reply_data ( worker_id , socket_id ) : <EOL> """<STR_LIT>""" <EOL> if not '<STR_LIT>' in request . query : <EOL> abort ( httplib . BAD_REQUEST , '<STR_LIT>' ) <EOL> try : <EOL> header_message = json . loads ( request . query . header_message ) <EOL> except ValueError : <EOL> abort ( httplib . BAD_REQUEST , '<STR_LIT>' ) <EOL> check_reply_permission ( worker_id , socket_id ) <EOL> local . worker_model . send_json_message ( socket_id , header_message , <NUM_LIT> , autoretry = False ) <EOL> local . worker_model . send_stream ( socket_id , request [ '<STR_LIT>' ] , <NUM_LIT> ) </s>
