<s> from BaseHTTPServer import BaseHTTPRequestHandler , HTTPServer <EOL> from functools import wraps <EOL> from random import randint <EOL> import json <EOL> import ssl <EOL> import time <EOL> import threading <EOL> import unittest <EOL> def sslwrap ( func ) : <EOL> @ wraps ( func ) <EOL> def bar ( * args , ** kw ) : <EOL> kw [ '<STR_LIT>' ] = ssl . PROTOCOL_TLSv1 <EOL> return func ( * args , ** kw ) <EOL> return bar <EOL> request_counts = dict ( ) <EOL> class Handler ( BaseHTTPRequestHandler ) : <EOL> '''<STR_LIT>''' <EOL> def do_PUT ( self ) : <EOL> global request_counts <EOL> _id = self . path . split ( "<STR_LIT:/>" ) [ - <NUM_LIT:1> ] <EOL> content_len = int ( self . headers . getheader ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> params = json . loads ( self . rfile . read ( content_len ) ) <EOL> fail_count = params . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> processed = request_counts . get ( _id , <NUM_LIT:0> ) <EOL> if processed > fail_count : <EOL> self . send_response ( <NUM_LIT:200> ) <EOL> return <EOL> request_counts [ _id ] = processed + <NUM_LIT:1> <EOL> return <EOL> def log_message ( self , format , * args ) : <EOL> return <EOL> class HTTPSTestCase ( unittest . TestCase ) : <EOL> '''<STR_LIT>''' <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . server = HTTPServer ( ( "<STR_LIT:localhost>" , <NUM_LIT:0> ) , Handler ) <EOL> ssl . wrap_socket = sslwrap ( ssl . wrap_socket ) <EOL> cls . server . socket = ssl . wrap_socket ( cls . server . socket , <EOL> certfile = '<STR_LIT>' , <EOL> server_side = True ) <EOL> cls . server_thread = threading . Thread ( target = cls . server . serve_forever ) <EOL> cls . server_thread . start ( ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> cls . server . shutdown ( ) <EOL> cls . server . socket . close ( ) <EOL> cls . server_thread . join ( ) </s>
