<s> """<STR_LIT>""" <EOL> import cStringIO <EOL> import thread <EOL> import threading <EOL> import urlparse <EOL> from google . appengine . api . logservice import logservice <EOL> from google . appengine . runtime import cgi <EOL> from google . appengine . runtime import request_environment <EOL> from google . appengine . runtime import wsgi <EOL> def _MakeStartNewThread ( base_start_new_thread ) : <EOL> """<STR_LIT>""" <EOL> def StartNewThread ( target , args , kw = None ) : <EOL> """<STR_LIT>""" <EOL> if kw is None : <EOL> kw = { } <EOL> cloner = request_environment . current_request . CloneRequestEnvironment ( ) <EOL> def Run ( ) : <EOL> try : <EOL> cloner ( ) <EOL> target ( * args , ** kw ) <EOL> finally : <EOL> request_environment . current_request . Clear ( ) <EOL> return base_start_new_thread ( Run , ( ) ) <EOL> return StartNewThread <EOL> thread . start_new_thread = _MakeStartNewThread ( thread . start_new_thread ) <EOL> reload ( threading ) <EOL> def HandleRequest ( environ , handler_name , url , post_data , application_root , <EOL> python_lib , import_hook = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> error = logservice . LogsBuffer ( ) <EOL> request_environment . current_request . Init ( error , environ ) <EOL> url = urlparse . urlsplit ( url ) <EOL> environ . update ( CgiDictFromParsedUrl ( url ) ) <EOL> if post_data : <EOL> environ [ '<STR_LIT>' ] = str ( len ( post_data ) ) <EOL> if '<STR_LIT>' in environ : <EOL> environ [ '<STR_LIT>' ] = environ [ '<STR_LIT>' ] <EOL> else : <EOL> environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> post_data = cStringIO . StringIO ( post_data ) <EOL> if '<STR_LIT:/>' in handler_name or handler_name . endswith ( '<STR_LIT>' ) : <EOL> response = cgi . HandleRequest ( environ , handler_name , url , post_data , error , <EOL> application_root , python_lib , import_hook ) <EOL> else : <EOL> response = wsgi . HandleRequest ( environ , handler_name , url , post_data , <EOL> error ) <EOL> response [ '<STR_LIT>' ] = error . parse_logs ( ) <EOL> return response <EOL> finally : <EOL> request_environment . current_request . Clear ( ) <EOL> def CgiDictFromParsedUrl ( url ) : <EOL> """<STR_LIT>""" <EOL> environ = { } <EOL> if url . port is not None : <EOL> environ [ '<STR_LIT>' ] = str ( url . port ) <EOL> elif url . scheme == '<STR_LIT>' : <EOL> environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> elif url . scheme == '<STR_LIT:http>' : <EOL> environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> environ [ '<STR_LIT>' ] = url . query <EOL> environ [ '<STR_LIT>' ] = url . hostname <EOL> if url . path : <EOL> environ [ '<STR_LIT>' ] = urlparse . unquote ( url . path ) <EOL> else : <EOL> environ [ '<STR_LIT>' ] = '<STR_LIT:/>' <EOL> return environ </s>
