<s> """<STR_LIT>""" <EOL> from google . appengine . api import apiproxy_stub <EOL> from google . appengine . api import request_info <EOL> from google . appengine . api . servers import servers_service_pb <EOL> from google . appengine . runtime import apiproxy_errors <EOL> class ServersServiceStub ( apiproxy_stub . APIProxyStub ) : <EOL> _ACCEPTS_REQUEST_ID = True <EOL> def __init__ ( self , request_data ) : <EOL> super ( ServersServiceStub , self ) . __init__ ( '<STR_LIT>' , <EOL> request_data = request_data ) <EOL> def _GetServerFromRequest ( self , request , request_id ) : <EOL> dispatcher = self . request_data . get_dispatcher ( ) <EOL> if request . has_server ( ) : <EOL> server = request . server ( ) <EOL> else : <EOL> server = self . request_data . get_server ( request_id ) <EOL> return server , dispatcher <EOL> def _GetServerAndVersionFromRequest ( self , request , request_id ) : <EOL> server , dispatcher = self . _GetServerFromRequest ( request , request_id ) <EOL> if request . has_version ( ) : <EOL> version = request . version ( ) <EOL> else : <EOL> version = self . request_data . get_version ( request_id ) <EOL> if version not in dispatcher . get_versions ( server ) : <EOL> version = dispatcher . get_default_version ( server ) <EOL> return server , version , dispatcher <EOL> def _Dynamic_GetServers ( self , request , response , request_id ) : <EOL> dispatcher = self . request_data . get_dispatcher ( ) <EOL> for server in dispatcher . get_server_names ( ) : <EOL> response . add_server ( server ) <EOL> def _Dynamic_GetVersions ( self , request , response , request_id ) : <EOL> server , dispatcher = self . _GetServerFromRequest ( request , request_id ) <EOL> try : <EOL> for version in dispatcher . get_versions ( server ) : <EOL> response . add_version ( version ) <EOL> except request_info . ServerDoesNotExistError : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> servers_service_pb . ServersServiceError . INVALID_SERVER ) <EOL> def _Dynamic_GetDefaultVersion ( self , request , response , request_id ) : <EOL> server , dispatcher = self . _GetServerFromRequest ( request , request_id ) <EOL> try : <EOL> response . set_version ( dispatcher . get_default_version ( server ) ) <EOL> except request_info . ServerDoesNotExistError : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> servers_service_pb . ServersServiceError . INVALID_SERVER ) <EOL> def _Dynamic_GetNumInstances ( self , request , response , request_id ) : <EOL> try : <EOL> server , version , dispatcher = self . _GetServerAndVersionFromRequest ( <EOL> request , request_id ) <EOL> response . set_instances ( dispatcher . get_num_instances ( server , version ) ) <EOL> except ( request_info . ServerDoesNotExistError , <EOL> request_info . VersionDoesNotExistError , <EOL> request_info . NotSupportedWithAutoScalingError ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> servers_service_pb . ServersServiceError . INVALID_VERSION ) <EOL> def _Dynamic_SetNumInstances ( self , request , response , request_id ) : <EOL> try : <EOL> server , version , dispatcher = self . _GetServerAndVersionFromRequest ( <EOL> request , request_id ) <EOL> dispatcher . set_num_instances ( server , version , request . instances ( ) ) <EOL> except ( request_info . ServerDoesNotExistError , <EOL> request_info . VersionDoesNotExistError , <EOL> request_info . NotSupportedWithAutoScalingError ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> servers_service_pb . ServersServiceError . INVALID_VERSION ) <EOL> def _Dynamic_StartServer ( self , request , response , request_id ) : <EOL> server = request . server ( ) <EOL> version = request . version ( ) <EOL> dispatcher = self . request_data . get_dispatcher ( ) <EOL> try : <EOL> dispatcher . start_server ( server , version ) <EOL> except ( request_info . ServerDoesNotExistError , <EOL> request_info . VersionDoesNotExistError , <EOL> request_info . NotSupportedWithAutoScalingError ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> servers_service_pb . ServersServiceError . INVALID_VERSION ) <EOL> except request_info . ServerAlreadyStartedError : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> servers_service_pb . ServersServiceError . UNEXPECTED_STATE ) <EOL> def _Dynamic_StopServer ( self , request , response , request_id ) : <EOL> try : <EOL> server , version , dispatcher = self . _GetServerAndVersionFromRequest ( <EOL> request , request_id ) <EOL> dispatcher . stop_server ( server , version ) <EOL> except ( request_info . ServerDoesNotExistError , <EOL> request_info . VersionDoesNotExistError , <EOL> request_info . NotSupportedWithAutoScalingError ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> servers_service_pb . ServersServiceError . INVALID_VERSION ) <EOL> except request_info . ServerAlreadyStoppedError : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> servers_service_pb . ServersServiceError . UNEXPECTED_STATE ) <EOL> def _Dynamic_GetHostname ( self , request , response , request_id ) : <EOL> if request . has_instance ( ) : <EOL> instance = request . instance ( ) <EOL> else : <EOL> instance = None <EOL> try : <EOL> server , version , dispatcher = self . _GetServerAndVersionFromRequest ( <EOL> request , request_id ) <EOL> response . set_hostname ( dispatcher . get_hostname ( server , version , instance ) ) <EOL> except ( request_info . ServerDoesNotExistError , <EOL> request_info . VersionDoesNotExistError ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> servers_service_pb . ServersServiceError . INVALID_SERVER ) <EOL> except request_info . InvalidInstanceIdError : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> servers_service_pb . ServersServiceError . INVALID_INSTANCES ) </s>
