<s> from __future__ import print_function <EOL> import logging <EOL> import os <EOL> import sys <EOL> import threading <EOL> try : <EOL> from urllib . parse import urlparse <EOL> except ImportError : <EOL> from urlparse import urlparse <EOL> from six . moves import SimpleHTTPServer <EOL> from six . moves import socketserver <EOL> from blogofile import config <EOL> from blogofile import util <EOL> from . cache import bf <EOL> bf . server = sys . modules [ '<STR_LIT>' ] <EOL> logger = logging . getLogger ( "<STR_LIT>" ) <EOL> class TCPServer ( socketserver . TCPServer ) : <EOL> """<STR_LIT>""" <EOL> allow_reuse_address = True <EOL> class Server ( threading . Thread ) : <EOL> def __init__ ( self , port , address = "<STR_LIT:127.0.0.1>" ) : <EOL> self . port = int ( port ) <EOL> self . address = address <EOL> if self . address == "<STR_LIT>" : <EOL> address = "<STR_LIT>" <EOL> threading . Thread . __init__ ( self ) <EOL> self . is_shutdown = False <EOL> server_address = ( address , self . port ) <EOL> HandlerClass = BlogofileRequestHandler <EOL> HandlerClass . protocol_version = "<STR_LIT>" <EOL> ServerClass = TCPServer <EOL> self . httpd = ServerClass ( server_address , HandlerClass ) <EOL> self . sa = self . httpd . socket . getsockname ( ) <EOL> def run ( self ) : <EOL> print ( "<STR_LIT>" <EOL> . format ( self . sa [ <NUM_LIT:0> ] , self . sa [ <NUM_LIT:1> ] ) ) <EOL> self . httpd . serve_forever ( ) <EOL> def shutdown ( self ) : <EOL> print ( "<STR_LIT>" ) <EOL> self . httpd . shutdown ( ) <EOL> self . httpd . socket . close ( ) <EOL> self . is_shutdown = True <EOL> class BlogofileRequestHandler ( SimpleHTTPServer . SimpleHTTPRequestHandler ) : <EOL> error_template = """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> path = urlparse ( config . site . url ) . path <EOL> self . BLOGOFILE_SUBDIR_ERROR = self . error_template . format ( path , path ) <EOL> SimpleHTTPServer . SimpleHTTPRequestHandler . __init__ ( <EOL> self , * args , ** kwargs ) <EOL> def translate_path ( self , path ) : <EOL> site_path = urlparse ( config . site . url ) . path <EOL> if ( len ( site_path . strip ( "<STR_LIT:/>" ) ) > <NUM_LIT:0> and <EOL> not path . startswith ( site_path ) ) : <EOL> self . error_message_format = self . BLOGOFILE_SUBDIR_ERROR <EOL> return "<STR_LIT>" <EOL> p = SimpleHTTPServer . SimpleHTTPRequestHandler . translate_path ( <EOL> self , path ) <EOL> if len ( site_path . strip ( "<STR_LIT:/>" ) ) > <NUM_LIT:0> : <EOL> build_path = os . path . join ( <EOL> os . getcwd ( ) , <EOL> util . path_join ( site_path . strip ( "<STR_LIT:/>" ) ) ) <EOL> else : <EOL> build_path = os . getcwd ( ) <EOL> build_path = p . replace ( build_path , os . path . join ( os . getcwd ( ) , "<STR_LIT>" ) ) <EOL> return build_path <EOL> def log_message ( self , format , * args ) : <EOL> pass </s>
