<s> '''<STR_LIT>''' <EOL> import os <EOL> import ssi <EOL> try : <EOL> from SimpleHTTPServer import SimpleHTTPRequestHandler <EOL> import SimpleHTTPServer <EOL> except ImportError : <EOL> from http . server import SimpleHTTPRequestHandler <EOL> import http . server as SimpleHTTPServer <EOL> import tempfile <EOL> class SSIRequestHandler ( SimpleHTTPRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , request , client_address , server ) : <EOL> self . temp_files = [ ] <EOL> SimpleHTTPRequestHandler . __init__ ( self , request , client_address , server ) <EOL> def do_GET ( self ) : <EOL> SimpleHTTPRequestHandler . do_GET ( self ) <EOL> self . delete_temp_files ( ) <EOL> def do_HEAD ( self ) : <EOL> SimpleHTTPRequestHandler . do_HEAD ( self ) <EOL> self . delete_temp_files ( ) <EOL> def translate_path ( self , path ) : <EOL> fs_path = SimpleHTTPRequestHandler . translate_path ( self , path ) <EOL> if self . path . endswith ( '<STR_LIT:/>' ) : <EOL> for index in "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" : <EOL> index = os . path . join ( fs_path , index ) <EOL> if os . path . exists ( index ) : <EOL> fs_path = index <EOL> break <EOL> if ( fs_path . endswith ( '<STR_LIT>' ) or fs_path . endswith ( "<STR_LIT>" ) ) and os . path . exists ( fs_path ) : <EOL> content = ssi . InlineIncludes ( fs_path , path ) <EOL> fs_path = self . create_temp_file ( fs_path , content ) <EOL> return fs_path <EOL> def delete_temp_files ( self ) : <EOL> for temp_file in self . temp_files : <EOL> os . remove ( temp_file ) <EOL> def create_temp_file ( self , original_path , content ) : <EOL> _ , ext = os . path . splitext ( original_path ) <EOL> if ext == "<STR_LIT>" : <EOL> ext = "<STR_LIT>" <EOL> fd , path = tempfile . mkstemp ( suffix = ext ) <EOL> try : <EOL> os . write ( fd , content ) <EOL> except TypeError : <EOL> os . write ( fd , bytes ( content , '<STR_LIT>' ) ) <EOL> os . close ( fd ) <EOL> self . temp_files . append ( path ) <EOL> return path <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> SimpleHTTPServer . test ( HandlerClass = SSIRequestHandler ) </s>
