def setup_stubs(config): """Sets up API stubs using remote API. Args: config: a runtime_config.Config instance. """ remote_api_stub.ConfigureRemoteApi( config.app_id, '/', lambda: ('', ''), '%s:%d' % (str(config.api_host), config.api_port), use_remote_datastore=False, grpc_apis=config.grpc_apis, grpc_proxy_port=config.python_config.grpc_proxy_port) if config.HasField('cloud_sql_config'): # Connect the RDBMS API to MySQL. sys.modules['google.appengine.api.rdbms'] = rdbms_mysqldb google.appengine.api.rdbms = rdbms_mysqldb connect_kwargs = dict(host=config.cloud_sql_config.mysql_host, port=config.cloud_sql_config.mysql_port, user=config.cloud_sql_config.mysql_user, passwd=config.cloud_sql_config.mysql_password) if config.cloud_sql_config.mysql_socket: connect_kwargs[ 'unix_socket'] = config.cloud_sql_config.mysql_socket elif (os.name == 'posix' and config.cloud_sql_config.mysql_host == 'localhost'): # From http://dev.mysql.com/doc/refman/5.0/en/connecting.html: # "On Unix, MySQL programs treat the host name localhost specially, # in a way that is likely different from what you expect compared to # other network-based programs. For connections to localhost, MySQL # programs attempt to connect to the local server by using a Unix socket # file. This occurs even if a --port or -P option is given to specify a # port number." # # This logic is duplicated in rdbms_mysqldb.connect but FindUnixSocket # will not worked in devappserver2 when rdbms_mysqldb.connect is called # because os.access is replaced in the sandboxed environment. # # A warning is not logged if FindUnixSocket returns None because it would # appear for all users, not just those who call connect. socket = rdbms_mysqldb.FindUnixSocket() # Don't set socket to None or the mysql driver will blow up with a # TypeError. This way it will raise a nicer connection error message. if socket is not None: connect_kwargs['unix_socket'] = socket rdbms_mysqldb.SetConnectKwargs(**connect_kwargs)
def setup_stubs(config, external_api_port=None): """Sets up API stubs using remote API.""" if external_api_port is None: external_api_server = None else: external_api_server = 'localhost:{}'.format(external_api_port) remote_api_stub.ConfigureRemoteApi(config.app_id, '/', lambda: ('', ''), 'localhost:%d' % config.api_port, use_remote_datastore=False, use_async_rpc=True, external_api_server=external_api_server) if config.HasField('cloud_sql_config'): # Connect the RDBMS API to MySQL. sys.modules['google.appengine.api.rdbms'] = rdbms_mysqldb google.appengine.api.rdbms = rdbms_mysqldb connect_kwargs = dict(host=config.cloud_sql_config.mysql_host, port=config.cloud_sql_config.mysql_port, user=config.cloud_sql_config.mysql_user, passwd=config.cloud_sql_config.mysql_password) if config.cloud_sql_config.mysql_socket: connect_kwargs[ 'unix_socket'] = config.cloud_sql_config.mysql_socket elif (os.name == 'posix' and config.cloud_sql_config.mysql_host == 'localhost'): # From http://dev.mysql.com/doc/refman/5.0/en/connecting.html: # "On Unix, MySQL programs treat the host name localhost specially, # in a way that is likely different from what you expect compared to # other network-based programs. For connections to localhost, MySQL # programs attempt to connect to the local server by using a Unix socket # file. This occurs even if a --port or -P option is given to specify a # port number." # # This logic is duplicated in rdbms_mysqldb.connect but FindUnixSocket # will not worked in devappserver2 when rdbms_mysqldb.connect is called # because os.access is replaced in the sandboxed environment. # # A warning is not logged if FindUnixSocket returns None because it would # appear for all users, not just those who call connect. connect_kwargs['unix_socket'] = rdbms_mysqldb.FindUnixSocket() rdbms_mysqldb.SetConnectKwargs(**connect_kwargs)