<s> import socket <EOL> import default_handler <EOL> import re <EOL> HOST = re . compile ( '<STR_LIT>' , re . IGNORECASE ) <EOL> get_header = default_handler . get_header <EOL> class virtual_handler : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , handler , hostname ) : <EOL> self . handler = handler <EOL> self . hostname = hostname <EOL> try : <EOL> self . ip = socket . gethostbyname ( hostname ) <EOL> except socket . error : <EOL> raise ValueError , "<STR_LIT>" % hostname <EOL> def match ( self , request ) : <EOL> if ( request . channel . addr [ <NUM_LIT:0> ] == self . ip ) : <EOL> return <NUM_LIT:1> <EOL> else : <EOL> return <NUM_LIT:0> <EOL> def handle_request ( self , request ) : <EOL> return self . handler . handle_request ( request ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . hostname <EOL> class virtual_handler_with_host : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , handler , hostname ) : <EOL> self . handler = handler <EOL> self . hostname = hostname <EOL> def match ( self , request ) : <EOL> host = get_header ( HOST , request . header ) <EOL> if host == self . hostname : <EOL> return <NUM_LIT:1> <EOL> else : <EOL> return <NUM_LIT:0> <EOL> def handle_request ( self , request ) : <EOL> return self . handler . handle_request ( request ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . hostname </s>
