<s> import httplib <EOL> import socket <EOL> import ssl <EOL> import sys <EOL> import json <EOL> import urllib <EOL> import urllib2 <EOL> import uuid <EOL> import random <EOL> from argparse import ArgumentParser <EOL> class HTTPSConnectionV3 ( httplib . HTTPSConnection ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> httplib . HTTPSConnection . __init__ ( self , * args , ** kwargs ) <EOL> def connect ( self ) : <EOL> sock = socket . create_connection ( ( self . host , self . port ) , self . timeout ) <EOL> if self . _tunnel_host : <EOL> self . sock = sock <EOL> self . _tunnel ( ) <EOL> try : <EOL> self . sock = ssl . wrap_socket ( sock , self . key_file , self . cert_file , ssl_version = ssl . PROTOCOL_TLSv1 ) <EOL> except ssl . SSLError , e : <EOL> print ( "<STR_LIT>" ) <EOL> self . sock = ssl . wrap_socket ( sock , self . key_file , self . cert_file , ssl_version = ssl . PROTOCOL_TLSv1 ) <EOL> class HTTPSHandlerV3 ( urllib2 . HTTPSHandler ) : <EOL> def https_open ( self , req ) : <EOL> return self . do_open ( HTTPSConnectionV3 , req ) <EOL> def send_request ( data ) : <EOL> url = '<STR_LIT>' <EOL> response = urllib2 . urlopen ( url , urllib . urlencode ( data ) ) <EOL> res = json . loads ( response . read ( ) ) <EOL> if res [ '<STR_LIT:status>' ] != '<STR_LIT>' : <EOL> print '<STR_LIT>' <EOL> def create_query_results ( query_ids ) : <EOL> urllib2 . install_opener ( urllib2 . build_opener ( HTTPSHandlerV3 ( ) ) ) <EOL> for query_id , num_groups in query_ids . iteritems ( ) : <EOL> is_grouped = num_groups > <NUM_LIT:1> <EOL> if is_grouped : <EOL> results = { <EOL> '<STR_LIT>' % ( i + <NUM_LIT:1> ) : random . uniform ( <NUM_LIT> , <NUM_LIT> ) for i in range ( num_groups ) <EOL> } <EOL> query_string = "<STR_LIT>" <EOL> else : <EOL> results = random . uniform ( <NUM_LIT> , <NUM_LIT> ) <EOL> query_string = "<STR_LIT>" <EOL> data = { <EOL> '<STR_LIT>' : query_string , <EOL> '<STR_LIT>' : query_id , <EOL> '<STR_LIT>' : str ( uuid . uuid4 ( ) ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : "<STR_LIT:true>" if is_grouped else "<STR_LIT:false>" , <EOL> '<STR_LIT>' : json . dumps ( results ) <EOL> } <EOL> send_request ( data ) <EOL> def parse_args ( ) : <EOL> parser = ArgumentParser ( <EOL> description = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , nargs = "<STR_LIT:+>" , metavar = "<STR_LIT>" , <EOL> help = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , nargs = "<STR_LIT:+>" , type = int , <EOL> metavar = "<STR_LIT>" , <EOL> help = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> args = parser . parse_args ( ) <EOL> if not args . query_ids : <EOL> args . query_ids = [ str ( uuid . uuid4 ( ) ) ] <EOL> if not args . num_groups : <EOL> args . num_groups = [ <NUM_LIT:1> for _ in args . query_ids ] <EOL> for num_group in args . num_groups : <EOL> if num_group < <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if len ( args . num_groups ) != len ( args . query_ids ) : <EOL> print ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> print "<STR_LIT>" <EOL> parser . print_usage ( ) <EOL> sys . exit ( ) <EOL> args . query_id_map = { <EOL> args . query_ids [ i ] : args . num_groups [ i ] for i in range ( len ( args . query_ids ) ) <EOL> } <EOL> return args <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> args = parse_args ( ) <EOL> create_query_results ( args . query_id_map ) </s>
