Get a cached client for a project, otherwise create one.
558376
def client_for(self, config_path, quiet=False, bootstrap_server=False,
                   create_client=False):
        """"""
        client = None
        abs_path = os.path.abspath(config_path)
        if abs_path in self.clients:
            client = self.clients[abs_path]
        elif create_client:
            client = self.create_client(config_path)
            if client.setup(quiet=quiet, bootstrap_server=bootstrap_server):
                self.clients[abs_path] = client
        return client
232819
def get_client():
	
	with contextlib.suppress(Exception):
		store = Storage.from_URI()
		assert isinstance(store, pmxbot.storage.MongoDBStorage)
		return store.db.database.client
601422
def create_github_client(self, project):
        """"""
        token = self._get_installation_key(project=project)
        if not token:
            LOGGER.warning(
                "Could not find an authentication token for '%s'. Do you "
                "have access to this repository?",
                project,
            )
            return
        gh = github3.GitHubEnterprise(self.base_url)
        gh.login(token=token)
        return gh
872705
@SuppressWarnings("unchecked")
	private Map<String, String> loadOrCreateCache(String projectName, String projectVersion) {
		if (projectName != null && projectVersion != null) {
			// Get the project dir or create it
			File projectDir = new File(getCacheDir(), projectName);
			if (!projectDir.exists()) {
				projectDir.mkdir();
			}
			
			// Get the version file or create it
			File versionFile = new File(projectDir, projectVersion);
			if (versionFile.exists()) {
				ObjectInputStream ois = null;
				try {
					ois = new ObjectInputStream(new FileInputStream(versionFile));
					return (Map<String, String>) ois.readObject();
				}
				catch (IOException ioe) {
					LOGGER.warn("Unable to read the cache for {}-{}", projectName, projectVersion);
				}
				catch (ClassNotFoundException cnfe) {
					LOGGER.warn("The cache for {}-{} is corrupted.", projectName, projectVersion);
				}
				finally { if (ois != null) { try { ois.close(); } catch (IOException ioe) {} } }
			}
		}
		
		return new HashMap<>();
	}
1026430
function Client(opts) {

    this.opts = new clientOptions(opts)
    this.streamData = {}
    this.currentIndex = 0
    this.cachedItems = new lru({maxSize: this.opts.maxCacheSize})
}
35980
def get_client(provider, token=''):
    ""
    cls = OAuth2Client
    if provider.request_token_url:
        cls = OAuthClient
    return cls(provider, token)
896925
def Get(self):
    """"""

    args = client_pb2.ApiGetClientArgs(client_id=self.client_id)
    result = self._context.SendRequest("GetClient", args)
    return Client(data=result, context=self._context)
497910
function Client(client) {
  if (this instanceof Client === false) {
    return new Client(client);
  }

  if (!client) {
    throw new Error('Must configure an S3 client before attempting to create an S3 upload stream.');
  }

  this.cachedClient = client;
}
1140529
def create(cls, path_name=None, name=None, project_id=None,
               log_modified_at=None, crawlable=True):
        """"""
        result = cls(path_name, name, project_id, log_modified_at, crawlable)

        db.session.add(result)
        db.session.commit()

        crawl_result(result, True)

        return result
376432
def get(self, project_name, updatetime=None, md5sum=None):
        ''''''
        if time.time() - self.last_check_projects > self.CHECK_PROJECTS_INTERVAL:
            self._check_projects()
        if self._need_update(project_name, updatetime, md5sum):
            self._update_project(project_name)
        return self.projects.get(project_name, None)
1246639
private CachedProviderServiceInstance getCachedServiceInstance(
            String serviceName, String providerId) {
        try {
            read.lock();
            ServiceInstanceId id = new ServiceInstanceId(serviceName, providerId);
            return getCacheServiceInstances().get(id);
        } finally {
            read.unlock();
        }
    }
927086
def connectCached(self, endpoint, protocolFactory,
                      extraWork=lambda x: x,
                      extraHash=None):
        
        key = endpoint, extraHash
        D = Deferred()
        if key in self.cachedConnections:
            D.callback(self.cachedConnections[key])
        elif key in self.inProgress:
            self.inProgress[key].append(D)
        else:
            self.inProgress[key] = [D]
            endpoint.connect(
                _CachingClientFactory(
                    self, key, protocolFactory,
                    extraWork))
        return D
718605
def __make_client(self):
        ""
        notice('Making client, getting server connection', self.color)
        self.mode = 'c'
        addr = utils.get_existing_server_addr()
        sock = utils.get_client_sock(addr)
        self.__s = sock
        with self.__client_list_lock:
            self.clients = deque()
        self.threads = deque()
105604
def create(cls, path_name=None, name=None, crawlable=True):
        """"""

        project = cls(path_name, name, crawlable)

        db.session.add(project)
        db.session.commit()

        return collect_results(project, force=True)
527588
def getclient():
        '''
        
        '''
        if not Configuration.client_initialized:
            Configuration._initconf()
            Configuration.client_settings = Configuration.settings['client']
            Configuration.client_initialized = True
        return Configuration.client_settings
521709
def cache(self, resource):
        """"""
        if not isinstance(resource, APIResource):
            raise TypeError('Cannot cache `{!r}`, can only cache APIResource instances'.format(resource))

        # Disable inserts to cache when disabled
        if self.__cache_max_size == 0:
            return

        try:
            cache_internal_key = resource.get_cache_internal_key()
            cache_index_keys = resource.get_cache_index_keys().items()
        except NotImplementedError:
            logger.warning(
                'Not caching `{!r}`, resource did not provide all necessary cache details'.format(resource)
            )
        else:
            resource_type = type(resource)

            for key, value in cache_index_keys:
                self.__cache_index_key_map[(resource_type, key, value)] = cache_internal_key

            self.__caches[resource_type][cache_internal_key] = resource

            logger.debug('Cached `{!r}`'.format(resource))
10652
public Client build(final Client client) {
    client.register(TracingClientFilter.create(tracing));
    return client;
  }