<s> """<STR_LIT>""" <EOL> '''<STR_LIT>''' <EOL> from flask import Flask <EOL> from flask . ext import restful <EOL> from flask . ext . restful import Resource , reqparse <EOL> import json <EOL> import next . utils <EOL> import next . broker . broker <EOL> from next . api . api_util import * <EOL> from next . api . api_util import APIArgument <EOL> from next . api . targetmapper import TargetMapper <EOL> from next . api . keychain import KeyChain <EOL> from next . api . resource_manager import ResourceManager <EOL> resource_manager = ResourceManager ( ) <EOL> broker = next . broker . broker . JobBroker ( ) <EOL> targetmapper = TargetMapper ( ) <EOL> keychain = KeyChain ( ) <EOL> post_parser = reqparse . RequestParser ( argument_class = APIArgument ) <EOL> meta_error = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:message>' : "<STR_LIT>" , <EOL> '<STR_LIT:code>' : <NUM_LIT> , <EOL> '<STR_LIT:status>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:message>' : "<STR_LIT>" , <EOL> '<STR_LIT:code>' : <NUM_LIT:200> , <EOL> '<STR_LIT:status>' : '<STR_LIT:OK>' <EOL> } <EOL> } <EOL> meta_success = { <EOL> '<STR_LIT:status>' : '<STR_LIT:OK>' , <EOL> '<STR_LIT:code>' : <NUM_LIT:200> <EOL> } <EOL> class Stats ( Resource ) : <EOL> def options ( self ) : <EOL> return None , <NUM_LIT:200> , { '<STR_LIT>' : '<STR_LIT:*>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> def post ( self ) : <EOL> """<STR_LIT>""" <EOL> post_parser . add_argument ( '<STR_LIT>' , type = str , required = True ) <EOL> post_parser . add_argument ( '<STR_LIT>' , type = str , required = True ) <EOL> post_parser . add_argument ( '<STR_LIT:args>' , type = dict , required = True ) <EOL> args_data = post_parser . parse_args ( ) <EOL> exp_uid = args_data [ "<STR_LIT>" ] <EOL> exp_key = args_data [ "<STR_LIT>" ] <EOL> if not keychain . verify_exp_key ( exp_uid , exp_key ) : <EOL> return api_util . attach_meta ( { } , api_util . verification_dictionary ) , <NUM_LIT> <EOL> app_id = resource_manager . get_app_id ( exp_uid ) <EOL> args_json = json . dumps ( args_data [ "<STR_LIT:args>" ] ) <EOL> response_json , didSucceed , message = broker . applyAsync ( app_id , exp_uid , "<STR_LIT>" , args_json ) <EOL> response_dict = json . loads ( response_json , parse_float = lambda o : round ( float ( o ) , <NUM_LIT:4> ) ) <EOL> try : <EOL> for d in response_dict [ "<STR_LIT:data>" ] : <EOL> try : <EOL> if '<STR_LIT:index>' in d . keys ( ) : <EOL> try : <EOL> d [ "<STR_LIT:target>" ] = targetmapper . get_target_data ( exp_uid , d [ "<STR_LIT:index>" ] ) <EOL> except : <EOL> print "<STR_LIT>" <EOL> except : <EOL> pass <EOL> except : <EOL> pass <EOL> if didSucceed and "<STR_LIT:data>" in response_dict . keys ( ) : <EOL> return attach_meta ( response_dict , meta_success ) , <NUM_LIT> <EOL> elif didSucceed and not "<STR_LIT:data>" in response_dict . keys ( ) : <EOL> return attach_meta ( { '<STR_LIT:data>' : [ ] } , meta_error [ '<STR_LIT>' ] ) , <NUM_LIT:200> <EOL> else : <EOL> return attach_meta ( { } , meta_error [ '<STR_LIT>' ] , backend_error = message ) , <NUM_LIT> </s>
