<s> """<STR_LIT>""" <EOL> import logging <EOL> import os <EOL> import os . path <EOL> import sys <EOL> import threading <EOL> from google . appengine . api import appinfo <EOL> from google . appengine . tools . devappserver2 import application_configuration <EOL> from google . appengine . tools . devappserver2 import go_application <EOL> from google . appengine . tools . devappserver2 import http_runtime <EOL> from google . appengine . tools . devappserver2 import instance <EOL> _REBUILD_CONFIG_CHANGES = frozenset ( <EOL> [ application_configuration . SKIP_FILES_CHANGED , <EOL> application_configuration . NOBUILD_FILES_CHANGED ] ) <EOL> class _GoBuildFailureRuntimeProxy ( instance . RuntimeProxy ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , failure_exception ) : <EOL> self . _failure_exception = failure_exception <EOL> def start ( self ) : <EOL> pass <EOL> def quit ( self ) : <EOL> pass <EOL> def handle ( self , environ , start_response , url_map , match , request_id , <EOL> request_type ) : <EOL> """<STR_LIT>""" <EOL> start_response ( '<STR_LIT>' , <EOL> [ ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) ] ) <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT:\n>' <EOL> yield str ( self . _failure_exception ) <EOL> class GoRuntimeInstanceFactory ( instance . InstanceFactory ) : <EOL> """<STR_LIT>""" <EOL> START_URL_MAP = appinfo . URLMap ( <EOL> url = '<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> login = '<STR_LIT>' ) <EOL> WARMUP_URL_MAP = appinfo . URLMap ( <EOL> url = '<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> login = '<STR_LIT>' ) <EOL> FILE_CHANGE_INSTANCE_RESTART_POLICY = instance . ALWAYS <EOL> def __init__ ( self , request_data , runtime_config_getter , server_configuration ) : <EOL> """<STR_LIT>""" <EOL> super ( GoRuntimeInstanceFactory , self ) . __init__ ( request_data , <NUM_LIT:1> ) <EOL> self . _runtime_config_getter = runtime_config_getter <EOL> self . _server_configuration = server_configuration <EOL> self . _application_lock = threading . Lock ( ) <EOL> self . _go_application = go_application . GoApplication ( <EOL> self . _server_configuration ) <EOL> self . _modified_since_last_build = False <EOL> def get_restart_directories ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> go_path = os . environ [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> return [ ] <EOL> else : <EOL> if sys . platform . startswith ( '<STR_LIT:win32>' ) : <EOL> roots = go_path . split ( '<STR_LIT:;>' ) <EOL> else : <EOL> roots = go_path . split ( '<STR_LIT::>' ) <EOL> return [ os . path . join ( r , '<STR_LIT:src>' ) for r in roots ] <EOL> def files_changed ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . _application_lock : <EOL> self . _modified_since_last_build = True <EOL> def configuration_changed ( self , config_changes ) : <EOL> """<STR_LIT>""" <EOL> if config_changes & _REBUILD_CONFIG_CHANGES : <EOL> with self . _application_lock : <EOL> self . _modified_since_last_build = True <EOL> def new_instance ( self , instance_id , expect_ready_request = False ) : <EOL> """<STR_LIT>""" <EOL> def instance_config_getter ( ) : <EOL> runtime_config = self . _runtime_config_getter ( ) <EOL> runtime_config . instance_id = str ( instance_id ) <EOL> return runtime_config <EOL> with self . _application_lock : <EOL> try : <EOL> self . _go_application . maybe_build ( self . _modified_since_last_build ) <EOL> except go_application . BuildError as e : <EOL> logging . error ( '<STR_LIT>' , e ) <EOL> proxy = _GoBuildFailureRuntimeProxy ( e ) <EOL> else : <EOL> proxy = http_runtime . HttpRuntimeProxy ( <EOL> self . _go_application . go_executable , <EOL> instance_config_getter , <EOL> self . _server_configuration , <EOL> self . _go_application . get_environment ( ) ) <EOL> self . _modified_since_last_build = False <EOL> return instance . Instance ( self . request_data , <EOL> instance_id , <EOL> proxy , <EOL> self . max_concurrent_requests , <EOL> self . max_background_threads , <EOL> expect_ready_request ) </s>
