<s> """<STR_LIT>""" <EOL> import signal <EOL> import tempfile <EOL> import time <EOL> from subprocess import Popen <EOL> import requests <EOL> from tests . mock import pickup_port <EOL> from zerotest . utils . url_helper import urljoin <EOL> class Proxy ( object ) : <EOL> def __init__ ( self ) : <EOL> self . port = None <EOL> self . _process = None <EOL> _ , self . data_file = tempfile . mkstemp ( ) <EOL> @ property <EOL> def url ( self ) : <EOL> return '<STR_LIT>' . format ( self . port ) <EOL> @ property <EOL> def running ( self ) : <EOL> if not self . _process : <EOL> return False <EOL> self . _process . poll ( ) <EOL> return self . _process . returncode is None <EOL> def shutdown ( self ) : <EOL> if self . running : <EOL> self . _process . send_signal ( signal . SIGINT ) <EOL> self . _process . wait ( ) <EOL> def start_server ( self , url ) : <EOL> """<STR_LIT>""" <EOL> port = pickup_port ( ) <EOL> self . _process = Popen ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , str ( port ) , '<STR_LIT>' , self . data_file , url ] ) <EOL> self . port = port <EOL> test_count = <NUM_LIT:10> <EOL> while test_count > <NUM_LIT:0> : <EOL> try : <EOL> if self . running : <EOL> r = requests . get ( urljoin ( self . url , '<STR_LIT>' ) ) <EOL> if r . status_code == <NUM_LIT:200> : <EOL> return <EOL> except requests . exceptions . ConnectionError : <EOL> pass <EOL> print ( "<STR_LIT>" , test_count ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> test_count -= <NUM_LIT:1> <EOL> else : <EOL> self . shutdown ( ) <EOL> raise RuntimeError ( "<STR_LIT>" ) </s>
