<s> RCS_ID = '<STR_LIT>' <EOL> import os <EOL> import re <EOL> import socket <EOL> import string <EOL> import sys <EOL> import time <EOL> import asyncore_25 as asyncore <EOL> import asynchat_25 as asynchat <EOL> import http_date <EOL> import producers <EOL> import status_handler <EOL> import logger <EOL> VERSION_STRING = string . split ( RCS_ID ) [ <NUM_LIT:2> ] <EOL> from counter import counter <EOL> from urllib import unquote , splitquery <EOL> class http_request : <EOL> reply_code = <NUM_LIT:200> <EOL> request_counter = counter ( ) <EOL> use_chunked = <NUM_LIT:1> <EOL> collector = None <EOL> def __init__ ( self , * args ) : <EOL> ( self . channel , self . request , <EOL> self . command , self . uri , self . version , <EOL> self . header ) = args <EOL> self . outgoing = [ ] <EOL> self . reply_headers = { <EOL> '<STR_LIT>' : '<STR_LIT>' % VERSION_STRING , <EOL> '<STR_LIT>' : http_date . build_http_date ( time . time ( ) ) <EOL> } <EOL> self . __reply_header_list = [ ] <EOL> self . request_number = http_request . request_counter . increment ( ) <EOL> self . _split_uri = None <EOL> self . _header_cache = { } <EOL> def __setitem__ ( self , key , value ) : <EOL> self . reply_headers [ key ] = value <EOL> def __getitem__ ( self , key ) : <EOL> return self . reply_headers [ key ] <EOL> def has_key ( self , key ) : <EOL> return self . reply_headers . has_key ( key ) <EOL> def build_reply_header ( self ) : <EOL> return string . join ( <EOL> [ self . response ( self . reply_code ) ] + map ( <EOL> lambda x : '<STR_LIT>' % x , <EOL> self . reply_headers . items ( ) <EOL> ) , <EOL> '<STR_LIT:\r\n>' <EOL> ) + '<STR_LIT>' <EOL> def add_header ( self , name , value ) : <EOL> """<STR_LIT>""" <EOL> self . __reply_header_list . append ( ( name , value ) ) <EOL> def clear_headers ( self ) : <EOL> """<STR_LIT>""" <EOL> self . reply_headers . clear ( ) <EOL> self . __reply_header_list [ : ] = [ ] <EOL> def remove_header ( self , name , value = None ) : <EOL> """<STR_LIT>""" <EOL> found_it = <NUM_LIT:0> <EOL> if ( self . reply_headers . has_key ( name ) and <EOL> ( value is None or <EOL> self . reply_headers [ name ] == value ) ) : <EOL> del self . reply_headers [ name ] <EOL> found_it = <NUM_LIT:1> <EOL> if not value is None : <EOL> if ( name , value ) in self . __reply_header_list : <EOL> removed_headers = [ ( name , value ) ] <EOL> found_it = <NUM_LIT:1> <EOL> else : <EOL> removed_headers = [ ] <EOL> for h in self . __reply_header_list : <EOL> if h [ <NUM_LIT:0> ] == name : <EOL> removed_headers . append ( h ) <EOL> found_it = <NUM_LIT:1> <EOL> if not found_it : <EOL> if value is None : <EOL> search_value = "<STR_LIT:%s>" % name <EOL> else : <EOL> search_value = "<STR_LIT>" % ( name , value ) <EOL> raise LookupError ( "<STR_LIT>" % search_value ) <EOL> for h in removed_headers : <EOL> self . __reply_header_list . remove ( h ) <EOL> def get_reply_headers ( self ) : <EOL> """<STR_LIT>""" <EOL> header_tuples = self . __reply_header_list [ : ] <EOL> header_names = [ n for n , v in header_tuples ] <EOL> for n , v in self . reply_headers . items ( ) : <EOL> if n not in header_names : <EOL> header_tuples . append ( ( n , v ) ) <EOL> header_names . append ( n ) <EOL> return header_tuples <EOL> def get_reply_header_text ( self ) : <EOL> """<STR_LIT>""" <EOL> header_tuples = self . get_reply_headers ( ) <EOL> headers = [ self . response ( self . reply_code ) ] <EOL> headers += [ "<STR_LIT>" % h for h in header_tuples ] <EOL> return string . join ( headers , '<STR_LIT:\r\n>' ) + '<STR_LIT>' <EOL> path_regex = re . compile ( <EOL> r'<STR_LIT>' <EOL> ) <EOL> def split_uri ( self ) : <EOL> if self . _split_uri is None : <EOL> m = self . path_regex . match ( self . uri ) <EOL> if m . end ( ) != len ( self . uri ) : <EOL> raise ValueError , "<STR_LIT>" <EOL> else : <EOL> self . _split_uri = m . groups ( ) <EOL> return self . _split_uri <EOL> def get_header_with_regex ( self , head_reg , group ) : <EOL> for line in self . header : <EOL> m = head_reg . match ( line ) <EOL> if m . end ( ) == len ( line ) : <EOL> return m . group ( group ) <EOL> return '<STR_LIT>' <EOL> def get_header ( self , header ) : <EOL> header = string . lower ( header ) <EOL> hc = self . _header_cache <EOL> if not hc . has_key ( header ) : <EOL> h = header + '<STR_LIT>' <EOL> hl = len ( h ) <EOL> for line in self . header : <EOL> if string . lower ( line [ : hl ] ) == h : <EOL> r = line [ hl : ] <EOL> hc [ header ] = r <EOL> return r <EOL> hc [ header ] = None <EOL> return None <EOL> else : <EOL> return hc [ header ] <EOL> def collect_incoming_data ( self , data ) : <EOL> if self . collector : <EOL> self . collector . collect_incoming_data ( data ) <EOL> else : <EOL> self . log_info ( <EOL> '<STR_LIT>' % len ( data ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> def found_terminator ( self ) : <EOL> if self . collector : <EOL> self . collector . found_terminator ( ) <EOL> else : <EOL> self . log_info ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> def push ( self , thing ) : <EOL> if type ( thing ) == type ( '<STR_LIT>' ) : <EOL> self . outgoing . append ( producers . simple_producer ( thing ) ) <EOL> else : <EOL> self . outgoing . append ( thing ) <EOL> def response ( self , code = <NUM_LIT:200> ) : <EOL> message = self . responses [ code ] <EOL> self . reply_code = code <EOL> return '<STR_LIT>' % ( self . version , code , message ) <EOL> def error ( self , code ) : <EOL> self . reply_code = code <EOL> message = self . responses [ code ] <EOL> s = self . DEFAULT_ERROR_MESSAGE % { <EOL> '<STR_LIT:code>' : code , <EOL> '<STR_LIT:message>' : message , <EOL> } <EOL> self [ '<STR_LIT>' ] = len ( s ) <EOL> self [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> self . push ( s ) <EOL> self . done ( ) <EOL> reply_now = error <EOL> def done ( self ) : <EOL> "<STR_LIT>" <EOL> connection = string . lower ( get_header ( CONNECTION , self . header ) ) <EOL> close_it = <NUM_LIT:0> <EOL> wrap_in_chunking = <NUM_LIT:0> <EOL> if self . version == '<STR_LIT:1.0>' : <EOL> if connection == '<STR_LIT>' : <EOL> if not self . has_key ( '<STR_LIT>' ) : <EOL> close_it = <NUM_LIT:1> <EOL> else : <EOL> self [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> else : <EOL> close_it = <NUM_LIT:1> <EOL> elif self . version == '<STR_LIT>' : <EOL> if connection == '<STR_LIT>' : <EOL> close_it = <NUM_LIT:1> <EOL> elif not self . has_key ( '<STR_LIT>' ) : <EOL> if self . has_key ( '<STR_LIT>' ) : <EOL> if not self [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> close_it = <NUM_LIT:1> <EOL> elif self . use_chunked : <EOL> self [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> wrap_in_chunking = <NUM_LIT:1> <EOL> else : <EOL> close_it = <NUM_LIT:1> <EOL> elif self . version is None : <EOL> close_it = <NUM_LIT:1> <EOL> outgoing_header = producers . simple_producer ( self . get_reply_header_text ( ) ) <EOL> if close_it : <EOL> self [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if wrap_in_chunking : <EOL> outgoing_producer = producers . chunked_producer ( <EOL> producers . composite_producer ( self . outgoing ) <EOL> ) <EOL> outgoing_producer = producers . composite_producer ( <EOL> [ outgoing_header , outgoing_producer ] <EOL> ) <EOL> else : <EOL> self . outgoing . insert ( <NUM_LIT:0> , outgoing_header ) <EOL> outgoing_producer = producers . composite_producer ( self . outgoing ) <EOL> self . channel . push_with_producer ( <EOL> producers . globbing_producer ( <EOL> producers . hooked_producer ( <EOL> outgoing_producer , <EOL> self . log <EOL> ) <EOL> ) <EOL> ) <EOL> self . channel . current_request = None <EOL> if close_it : <EOL> self . channel . close_when_done ( ) <EOL> def log_date_string ( self , when ) : <EOL> gmt = time . gmtime ( when ) <EOL> if time . daylight and gmt [ <NUM_LIT:8> ] : <EOL> tz = time . altzone <EOL> else : <EOL> tz = time . timezone <EOL> if tz > <NUM_LIT:0> : <EOL> neg = <NUM_LIT:1> <EOL> else : <EOL> neg = <NUM_LIT:0> <EOL> tz = - tz <EOL> h , rem = divmod ( tz , <NUM_LIT> ) <EOL> m , rem = divmod ( rem , <NUM_LIT> ) <EOL> if neg : <EOL> offset = '<STR_LIT>' % ( h , m ) <EOL> else : <EOL> offset = '<STR_LIT>' % ( h , m ) <EOL> return time . strftime ( '<STR_LIT>' , gmt ) + offset <EOL> def log ( self , bytes ) : <EOL> self . channel . server . logger . log ( <EOL> self . channel . addr [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' % ( <EOL> self . channel . addr [ <NUM_LIT:1> ] , <EOL> self . log_date_string ( time . time ( ) ) , <EOL> self . request , <EOL> self . reply_code , <EOL> bytes <EOL> ) <EOL> ) <EOL> responses = { <EOL> <NUM_LIT:100> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT:200> : "<STR_LIT:OK>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" <EOL> } <EOL> DEFAULT_ERROR_MESSAGE = string . join ( <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] , <EOL> '<STR_LIT:\r\n>' <EOL> ) <EOL> class http_channel ( asynchat . async_chat ) : <EOL> ac_out_buffer_size = <NUM_LIT:1> << <NUM_LIT:16> <EOL> current_request = None <EOL> channel_counter = counter ( ) <EOL> def __init__ ( self , server , conn , addr ) : <EOL> self . channel_number = http_channel . channel_counter . increment ( ) <EOL> self . request_counter = counter ( ) <EOL> asynchat . async_chat . __init__ ( self , conn ) <EOL> self . server = server <EOL> self . addr = addr <EOL> self . set_terminator ( '<STR_LIT>' ) <EOL> self . in_buffer = '<STR_LIT>' <EOL> self . creation_time = int ( time . time ( ) ) <EOL> self . check_maintenance ( ) <EOL> def __repr__ ( self ) : <EOL> ar = asynchat . async_chat . __repr__ ( self ) [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> return '<STR_LIT>' % ( <EOL> ar , <EOL> self . channel_number , <EOL> self . request_counter <EOL> ) <EOL> maintenance_interval = <NUM_LIT> <EOL> def check_maintenance ( self ) : <EOL> if not self . channel_number % self . maintenance_interval : <EOL> self . maintenance ( ) <EOL> def maintenance ( self ) : <EOL> self . kill_zombies ( ) <EOL> zombie_timeout = <NUM_LIT:30> * <NUM_LIT> <EOL> def kill_zombies ( self ) : <EOL> now = int ( time . time ( ) ) <EOL> for channel in asyncore . socket_map . values ( ) : <EOL> if channel . __class__ == self . __class__ : <EOL> if ( now - channel . creation_time ) > channel . zombie_timeout : <EOL> channel . close ( ) <EOL> def send ( self , data ) : <EOL> result = asynchat . async_chat . send ( self , data ) <EOL> self . server . bytes_out . increment ( len ( data ) ) <EOL> return result <EOL> def recv ( self , buffer_size ) : <EOL> try : <EOL> result = asynchat . async_chat . recv ( self , buffer_size ) <EOL> self . server . bytes_in . increment ( len ( result ) ) <EOL> return result <EOL> except MemoryError : <EOL> sys . exit ( "<STR_LIT>" ) <EOL> def handle_error ( self ) : <EOL> t , v = sys . exc_info ( ) [ : <NUM_LIT:2> ] <EOL> if t is SystemExit : <EOL> raise t , v <EOL> else : <EOL> asynchat . async_chat . handle_error ( self ) <EOL> def log ( self , * args ) : <EOL> pass <EOL> def collect_incoming_data ( self , data ) : <EOL> if self . current_request : <EOL> self . current_request . collect_incoming_data ( data ) <EOL> else : <EOL> self . in_buffer = self . in_buffer + data <EOL> def found_terminator ( self ) : <EOL> if self . current_request : <EOL> self . current_request . found_terminator ( ) <EOL> else : <EOL> header = self . in_buffer <EOL> self . in_buffer = '<STR_LIT>' <EOL> lines = string . split ( header , '<STR_LIT:\r\n>' ) <EOL> while lines and not lines [ <NUM_LIT:0> ] : <EOL> lines = lines [ <NUM_LIT:1> : ] <EOL> if not lines : <EOL> self . close_when_done ( ) <EOL> return <EOL> request = lines [ <NUM_LIT:0> ] <EOL> command , uri , version = crack_request ( request ) <EOL> header = join_headers ( lines [ <NUM_LIT:1> : ] ) <EOL> rpath , rquery = splitquery ( uri ) <EOL> if '<STR_LIT:%>' in rpath : <EOL> if rquery : <EOL> uri = unquote ( rpath ) + '<STR_LIT:?>' + rquery <EOL> else : <EOL> uri = unquote ( rpath ) <EOL> r = http_request ( self , request , command , uri , version , header ) <EOL> self . request_counter . increment ( ) <EOL> self . server . total_requests . increment ( ) <EOL> if command is None : <EOL> self . log_info ( '<STR_LIT>' % repr ( request ) , '<STR_LIT:error>' ) <EOL> r . error ( <NUM_LIT> ) <EOL> return <EOL> for h in self . server . handlers : <EOL> if h . match ( r ) : <EOL> try : <EOL> self . current_request = r <EOL> h . handle_request ( r ) <EOL> except : <EOL> self . server . exceptions . increment ( ) <EOL> ( file , fun , line ) , t , v , tbinfo = asyncore . compact_traceback ( ) <EOL> self . log_info ( <EOL> '<STR_LIT>' % ( t , v , file , line ) , <EOL> '<STR_LIT:error>' ) <EOL> try : <EOL> r . error ( <NUM_LIT> ) <EOL> except : <EOL> pass <EOL> return <EOL> r . error ( <NUM_LIT> ) <EOL> def writable_for_proxy ( self ) : <EOL> if self . ac_out_buffer : <EOL> return <NUM_LIT:1> <EOL> elif len ( self . producer_fifo ) : <EOL> p = self . producer_fifo . first ( ) <EOL> if hasattr ( p , '<STR_LIT>' ) : <EOL> return not p . stalled ( ) <EOL> else : <EOL> return <NUM_LIT:1> <EOL> class http_server ( asyncore . dispatcher ) : <EOL> SERVER_IDENT = '<STR_LIT>' % VERSION_STRING <EOL> channel_class = http_channel <EOL> def __init__ ( self , ip , port , resolver = None , logger_object = None ) : <EOL> self . ip = ip <EOL> self . port = port <EOL> asyncore . dispatcher . __init__ ( self ) <EOL> self . create_socket ( socket . AF_INET , socket . SOCK_STREAM ) <EOL> self . handlers = [ ] <EOL> if not logger_object : <EOL> logger_object = logger . file_logger ( sys . stdout ) <EOL> self . set_reuse_addr ( ) <EOL> self . bind ( ( ip , port ) ) <EOL> self . listen ( <NUM_LIT> ) <EOL> host , port = self . socket . getsockname ( ) <EOL> if not ip : <EOL> self . log_info ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ip = socket . gethostbyname ( socket . gethostname ( ) ) <EOL> try : <EOL> self . server_name = socket . gethostbyaddr ( ip ) [ <NUM_LIT:0> ] <EOL> except socket . error : <EOL> self . log_info ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . server_name = ip <EOL> self . server_port = port <EOL> self . total_clients = counter ( ) <EOL> self . total_requests = counter ( ) <EOL> self . exceptions = counter ( ) <EOL> self . bytes_out = counter ( ) <EOL> self . bytes_in = counter ( ) <EOL> if not logger_object : <EOL> logger_object = logger . file_logger ( sys . stdout ) <EOL> if resolver : <EOL> self . logger = logger . resolving_logger ( resolver , logger_object ) <EOL> else : <EOL> self . logger = logger . unresolving_logger ( logger_object ) <EOL> self . log_info ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT:\n>' % ( <EOL> VERSION_STRING , <EOL> time . ctime ( time . time ( ) ) , <EOL> self . server_name , <EOL> port , <EOL> ) <EOL> ) <EOL> def writable ( self ) : <EOL> return <NUM_LIT:0> <EOL> def handle_read ( self ) : <EOL> pass <EOL> def readable ( self ) : <EOL> return self . accepting <EOL> def handle_connect ( self ) : <EOL> pass <EOL> def handle_accept ( self ) : <EOL> self . total_clients . increment ( ) <EOL> try : <EOL> conn , addr = self . accept ( ) <EOL> except socket . error : <EOL> self . log_info ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return <EOL> except TypeError : <EOL> self . log_info ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return <EOL> self . channel_class ( self , conn , addr ) <EOL> def install_handler ( self , handler , back = <NUM_LIT:0> ) : <EOL> if back : <EOL> self . handlers . append ( handler ) <EOL> else : <EOL> self . handlers . insert ( <NUM_LIT:0> , handler ) <EOL> def remove_handler ( self , handler ) : <EOL> self . handlers . remove ( handler ) <EOL> def status ( self ) : <EOL> def nice_bytes ( n ) : <EOL> return string . join ( status_handler . english_bytes ( n ) ) <EOL> handler_stats = filter ( None , map ( maybe_status , self . handlers ) ) <EOL> if self . total_clients : <EOL> ratio = self . total_requests . as_long ( ) / float ( self . total_clients . as_long ( ) ) <EOL> else : <EOL> ratio = <NUM_LIT:0.0> <EOL> return producers . composite_producer ( <EOL> [ producers . lines_producer ( <EOL> [ '<STR_LIT>' % self . SERVER_IDENT , <EOL> '<STR_LIT>' % self . server_name , <EOL> '<STR_LIT>' % self . port , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % self . total_clients , <EOL> '<STR_LIT>' % self . total_requests , <EOL> '<STR_LIT>' % ( ratio ) , <EOL> '<STR_LIT>' % ( nice_bytes ( self . bytes_in . as_long ( ) ) ) , <EOL> '<STR_LIT>' % ( nice_bytes ( self . bytes_out . as_long ( ) ) ) , <EOL> '<STR_LIT>' % self . exceptions , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> ] ) ] + handler_stats + [ producers . simple_producer ( '<STR_LIT>' ) ] <EOL> ) <EOL> def maybe_status ( thing ) : <EOL> if hasattr ( thing , '<STR_LIT:status>' ) : <EOL> return thing . status ( ) <EOL> else : <EOL> return None <EOL> CONNECTION = re . compile ( '<STR_LIT>' , re . IGNORECASE ) <EOL> def join_headers ( headers ) : <EOL> r = [ ] <EOL> for i in range ( len ( headers ) ) : <EOL> if headers [ i ] [ <NUM_LIT:0> ] in '<STR_LIT>' : <EOL> r [ - <NUM_LIT:1> ] = r [ - <NUM_LIT:1> ] + headers [ i ] [ <NUM_LIT:1> : ] <EOL> else : <EOL> r . append ( headers [ i ] ) <EOL> return r <EOL> def get_header ( head_reg , lines , group = <NUM_LIT:1> ) : <EOL> for line in lines : <EOL> m = head_reg . match ( line ) <EOL> if m and m . end ( ) == len ( line ) : <EOL> return m . group ( group ) <EOL> return '<STR_LIT>' <EOL> def get_header_match ( head_reg , lines ) : <EOL> for line in lines : <EOL> m = head_reg . match ( line ) <EOL> if m and m . end ( ) == len ( line ) : <EOL> return m <EOL> return '<STR_LIT>' <EOL> REQUEST = re . compile ( '<STR_LIT>' ) <EOL> def crack_request ( r ) : <EOL> m = REQUEST . match ( r ) <EOL> if m and m . end ( ) == len ( r ) : <EOL> if m . group ( <NUM_LIT:3> ) : <EOL> version = m . group ( <NUM_LIT:5> ) <EOL> else : <EOL> version = None <EOL> return m . group ( <NUM_LIT:1> ) , m . group ( <NUM_LIT:2> ) , version <EOL> else : <EOL> return None , None , None <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import sys <EOL> if len ( sys . argv ) < <NUM_LIT:2> : <EOL> print '<STR_LIT>' % ( sys . argv [ <NUM_LIT:0> ] ) <EOL> else : <EOL> import monitor <EOL> import filesys <EOL> import default_handler <EOL> import status_handler <EOL> import ftp_server <EOL> import chat_server <EOL> import resolver <EOL> import logger <EOL> rs = resolver . caching_resolver ( '<STR_LIT:127.0.0.1>' ) <EOL> lg = logger . file_logger ( sys . stdout ) <EOL> ms = monitor . secure_monitor_server ( '<STR_LIT>' , '<STR_LIT:127.0.0.1>' , <NUM_LIT> ) <EOL> fs = filesys . os_filesystem ( sys . argv [ <NUM_LIT:1> ] ) <EOL> dh = default_handler . default_handler ( fs ) <EOL> hs = http_server ( '<STR_LIT>' , string . atoi ( sys . argv [ <NUM_LIT:2> ] ) , rs , lg ) <EOL> hs . install_handler ( dh ) <EOL> ftp = ftp_server . ftp_server ( <EOL> ftp_server . dummy_authorizer ( sys . argv [ <NUM_LIT:1> ] ) , <EOL> port = <NUM_LIT> , <EOL> resolver = rs , <EOL> logger_object = lg <EOL> ) <EOL> cs = chat_server . chat_server ( '<STR_LIT>' , <NUM_LIT> ) <EOL> sh = status_handler . status_extension ( [ hs , ms , ftp , cs , rs ] ) <EOL> hs . install_handler ( sh ) <EOL> if ( '<STR_LIT>' in sys . argv ) : <EOL> def profile_loop ( ) : <EOL> try : <EOL> asyncore . loop ( ) <EOL> except KeyboardInterrupt : <EOL> pass <EOL> import profile <EOL> profile . run ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> else : <EOL> asyncore . loop ( ) </s>
