<s> from __future__ import absolute_import , division , print_function , with_statement <EOL> import sys <EOL> import os <EOL> import signal <EOL> import select <EOL> import time <EOL> import argparse <EOL> from subprocess import Popen , PIPE <EOL> python = [ '<STR_LIT>' ] <EOL> default_url = '<STR_LIT>' <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT:-c>' , '<STR_LIT>' , type = str , default = None ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , type = str , default = None ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , type = str , default = None ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , type = str , default = None ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = None ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = None ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = None ) <EOL> parser . add_argument ( '<STR_LIT>' , type = str , default = default_url ) <EOL> parser . add_argument ( '<STR_LIT>' , type = str , default = '<STR_LIT>' ) <EOL> config = parser . parse_args ( ) <EOL> if config . with_coverage : <EOL> python = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> client_args = python + [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> server_args = python + [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if config . client_conf : <EOL> client_args . extend ( [ '<STR_LIT:-c>' , config . client_conf ] ) <EOL> if config . server_conf : <EOL> server_args . extend ( [ '<STR_LIT:-c>' , config . server_conf ] ) <EOL> else : <EOL> server_args . extend ( [ '<STR_LIT:-c>' , config . client_conf ] ) <EOL> if config . client_args : <EOL> client_args . extend ( config . client_args . split ( ) ) <EOL> if config . server_args : <EOL> server_args . extend ( config . server_args . split ( ) ) <EOL> else : <EOL> server_args . extend ( config . client_args . split ( ) ) <EOL> if config . url == default_url : <EOL> server_args . extend ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> p1 = Popen ( server_args , stdin = PIPE , stdout = PIPE , stderr = PIPE , close_fds = True ) <EOL> p2 = Popen ( client_args , stdin = PIPE , stdout = PIPE , stderr = PIPE , close_fds = True ) <EOL> p3 = None <EOL> p4 = None <EOL> p3_fin = False <EOL> p4_fin = False <EOL> stage = <NUM_LIT:1> <EOL> try : <EOL> local_ready = False <EOL> server_ready = False <EOL> fdset = [ p1 . stdout , p2 . stdout , p1 . stderr , p2 . stderr ] <EOL> while True : <EOL> r , w , e = select . select ( fdset , [ ] , fdset ) <EOL> if e : <EOL> break <EOL> for fd in r : <EOL> line = fd . readline ( ) <EOL> if not line : <EOL> if stage == <NUM_LIT:2> and fd == p3 . stdout : <EOL> stage = <NUM_LIT:3> <EOL> if stage == <NUM_LIT:4> and fd == p4 . stdout : <EOL> stage = <NUM_LIT:5> <EOL> if bytes != str : <EOL> line = str ( line , '<STR_LIT:utf8>' ) <EOL> sys . stderr . write ( line ) <EOL> if line . find ( '<STR_LIT>' ) >= <NUM_LIT:0> : <EOL> local_ready = True <EOL> if line . find ( '<STR_LIT>' ) >= <NUM_LIT:0> : <EOL> server_ready = True <EOL> if stage == <NUM_LIT:1> : <EOL> time . sleep ( <NUM_LIT:2> ) <EOL> p3 = Popen ( [ '<STR_LIT>' , config . url , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> stdin = PIPE , stdout = PIPE , stderr = PIPE , close_fds = True ) <EOL> if p3 is not None : <EOL> fdset . append ( p3 . stdout ) <EOL> fdset . append ( p3 . stderr ) <EOL> stage = <NUM_LIT:2> <EOL> else : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if stage == <NUM_LIT:3> and p3 is not None : <EOL> fdset . remove ( p3 . stdout ) <EOL> fdset . remove ( p3 . stderr ) <EOL> r = p3 . wait ( ) <EOL> if config . should_fail : <EOL> if r == <NUM_LIT:0> : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> if r != <NUM_LIT:0> : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if config . tcp_only : <EOL> break <EOL> p4 = Popen ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' % config . dns , <EOL> '<STR_LIT>' ] , <EOL> stdin = PIPE , stdout = PIPE , stderr = PIPE , close_fds = True ) <EOL> if p4 is not None : <EOL> fdset . append ( p4 . stdout ) <EOL> fdset . append ( p4 . stderr ) <EOL> stage = <NUM_LIT:4> <EOL> else : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if stage == <NUM_LIT:5> : <EOL> r = p4 . wait ( ) <EOL> if config . should_fail : <EOL> if r == <NUM_LIT:0> : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> print ( '<STR_LIT>' ) <EOL> else : <EOL> if r != <NUM_LIT:0> : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> print ( '<STR_LIT>' ) <EOL> break <EOL> finally : <EOL> for p in [ p1 , p2 ] : <EOL> try : <EOL> os . kill ( p . pid , signal . SIGINT ) <EOL> os . waitpid ( p . pid , <NUM_LIT:0> ) <EOL> except OSError : <EOL> pass </s>
