Determine if connection is local or remote
321570
def _use_remote_connection(self, kwargs):
        '''
        
        '''
        kwargs['host'] = kwargs.get('host')
        kwargs['username'] = kwargs.get('username')
        kwargs['password'] = kwargs.get('password')
        if kwargs['host'] is None or \
           kwargs['username'] is None or \
           kwargs['password'] is None:
            return False
        else:
            return True
1211336
def mixed_use_of_local_and_run(self):
        
        cxn = Connection("localhost")
        result = cxn.local("echo foo", hide=True)
        assert result.stdout == "foo\n"
        assert not cxn.is_connected  # meh way of proving it didn't use SSH yet
        result = cxn.run("echo foo", hide=True)
        assert cxn.is_connected  # NOW it's using SSH
        assert result.stdout == "foo\n"
842426
def local(self, *args, **kwargs):
        
        # Superclass run() uses runners.local, so we can literally just call it
        # straight.
        return super(Connection, self).run(*args, **kwargs)
1204065
def is_connectable(port, host="localhost"):
    
    socket_ = None
    try:
        socket_ = socket.create_connection((host, port), 1)
        result = True
    except _is_connectable_exceptions:
        result = False
    finally:
        if socket_:
            socket_.close()
    return result
1135832
def get_remote_file(url):
    
    try:
        return requests.get(url)
    except requests.exceptions.ConnectionError as e:
        print("Connection error!")
        print(e.message.reason)
        exit(1)
170899
public function determineIfLocal() {

		// Default it to false
		$this->local = false;

		// Compare the MPD host a few different ways to try and determine if it's local to the Apache server
		if( 	( stream_is_local( $this->socket )) ||
			( $this->host == (isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : getHostByName( getHostName() ))) ||
			( $this->host == 'localhost' ) || 
			( $this->host == '127.0.0.1' )) {

			$this->local = true;
		}
	}
879324
function isUrl(string){
    if (typeof string !== 'string') {
      return false;
    }

    var match = string.match(protocolAndDomainRE);
    if (!match) {
      return false;
    }

    var everythingAfterProtocol = match[1];
    if (!everythingAfterProtocol) {
      return false;
    }

    return localhostDomainRE.test(everythingAfterProtocol) ||
        nonLocalhostDomainRE.test(everythingAfterProtocol);
  }
338239
public void assertLocalClient() {
    NetworkInterface iface = null;
    try {
      iface = NetworkInterface.getByInetAddress(getInetAddress());
    } catch (java.net.SocketException se) {
      throw (new SecurityException("Unable to determine if client is local.  Assuming he isn't."));
    }

    if ((iface == null) && (!getInetAddress().isLoopbackAddress())) {
      throw (new SecurityException("Client is not local."));
    }
  }
592937
def is_running(self, port):
        """"""
        try:
            con = self.client('localhost:%s' % port)
            con.admin.command('ping')
            return True
        except (AutoReconnect, ConnectionFailure, OperationFailure):
            # Catch OperationFailure to work around SERVER-31916.
            return False
263286
protected boolean isConnectionOk(IoSession session) {
        SocketAddress remoteAddress = session.getRemoteAddress();
        if (remoteAddress instanceof InetSocketAddress) {
            InetSocketAddress addr = (InetSocketAddress) remoteAddress;
            long now = System.currentTimeMillis();

            if (clients.containsKey(addr.getAddress().getHostAddress())) {

                LOGGER.debug("This is not a new client");
                Long lastConnTime = clients.get(addr.getAddress()
                        .getHostAddress());

                clients.put(addr.getAddress().getHostAddress(), now);

                // if the interval between now and the last connection is
                // less than the allowed interval, return false
                if (now - lastConnTime < allowedInterval) {
                    LOGGER.warn("Session connection interval too short");
                    return false;
                }
                
                return true;
            }

            clients.put(addr.getAddress().getHostAddress(), now);
            return true;
        }

        return false;
    }
1142200
function checkRemote (remotes, remote) {
  if (remotes === "ALL") {
    return true;
  }

  if (!_.isArray(remotes)) {
    remotes = _.invoke(remotes.split(","), "trim");
  }

  return _.any(remotes, _.partial(minimatch, remote));
}
284860
def check_internet_connection(self, remote_server: str = "api.isogeo.com") -> bool:
        
        try:
            # see if we can resolve the host name -- tells us if there is
            # a DNS listening
            host = socket.gethostbyname(remote_server)
            # connect to the host -- tells us if it's reachable
            sock = socket.create_connection((host, 80), 2)
            sock.close()
            return True
        except Exception as e:
            logging.error(e)
            return False
292337
def is_remote_allowed(remote):
  
  if settings.debug:
    return True
  if not remote:
    return False
  for domain_pattern in settings.node['cors_whitelist_domains']:
    if domain_pattern.match(remote):
      return True
  return False
479660
def remotesByConnected(self):
        
        conns, disconns = [], []
        for r in self.remotes.values():
            array = conns if self.isRemoteConnected(r) else disconns
            array.append(r)
        return conns, disconns
1309888
def do_local(self, host="localhost", port=8000):
        
        port = int(port)
        if host == "off":
            self._local_endpoint = None
        else:
            self._local_endpoint = (host, port)
        self.onecmd("use %s" % self.engine.region)
157361
def local_run():
  """"""
  server_software = os.environ.get('SERVER_SOFTWARE')
  if server_software is None:
    return True
  if 'remote_api' in server_software:
    return False
  if server_software.startswith(('Development', 'testutil')):
    return True
  return False
755646
def remote(self, name='origin'):
        """"""
        r = Remote(self, name)
        if not r.exists():
            raise ValueError("Remote named '%s' didn't exist" % name)
        return r