def test_deep_update(self): val = { "captain": "picard", "beverage": { "type": "coffee", "temperature": "hot", }, } deep_update( val, { "beverage": { "type": "tea", "variant": "earl grey", }, "starship": "enterprise", }, ) self.assertEqual( val, { "captain": "picard", "beverage": { "type": "tea", "variant": "earl grey", "temperature": "hot", }, "starship": "enterprise", }, )
def __init__(self, params): super(ElasticsearchSearchBackend, self).__init__(params) # Get settings self.hosts = params.pop('HOSTS', None) self.index_name = params.pop('INDEX', 'wagtail') self.timeout = params.pop('TIMEOUT', 10) if params.pop('ATOMIC_REBUILD', False): self.rebuilder_class = self.atomic_rebuilder_class else: self.rebuilder_class = self.basic_rebuilder_class # If HOSTS is not set, convert URLS setting to HOSTS es_urls = params.pop('URLS', ['http://localhost:9200']) if self.hosts is None: self.hosts = [] for url in es_urls: parsed_url = urlparse(url) use_ssl = parsed_url.scheme == 'https' port = parsed_url.port or (443 if use_ssl else 80) http_auth = None if parsed_url.username is not None and parsed_url.password is not None: http_auth = (parsed_url.username, parsed_url.password) self.hosts.append({ 'host': parsed_url.hostname, 'port': port, 'url_prefix': parsed_url.path, 'use_ssl': use_ssl, 'verify_certs': use_ssl, 'http_auth': http_auth, }) self.settings = copy.deepcopy(self.settings) # Make the class settings attribute as instance settings attribute self.settings = deep_update(self.settings, params.pop("INDEX_SETTINGS", {})) # Get Elasticsearch interface # Any remaining params are passed into the Elasticsearch constructor options = params.pop('OPTIONS', {}) if not options and params: options = params warnings.warn( "Any extra parameter for the ElasticSearch constructor must be passed through the OPTIONS dictionary.", category=RemovedInWagtail110Warning, stacklevel=2 ) self.es = Elasticsearch( hosts=self.hosts, timeout=self.timeout, **options)
def __init__(self, params): super(Elasticsearch5SearchBackend, self).__init__(params) # Get settings self.hosts = params.pop("HOSTS", None) self.index_name = params.pop("INDEX", "wagtail") self.timeout = params.pop("TIMEOUT", 10) if params.pop("ATOMIC_REBUILD", False): self.rebuilder_class = self.atomic_rebuilder_class else: self.rebuilder_class = self.basic_rebuilder_class # If HOSTS is not set, convert URLS setting to HOSTS es_urls = params.pop("URLS", ["http://localhost:9200"]) if self.hosts is None: self.hosts = [] # if es_urls is not a list, convert it to a list if isinstance(es_urls, str): es_urls = [es_urls] for url in es_urls: parsed_url = urlparse(url) use_ssl = parsed_url.scheme == "https" port = parsed_url.port or (443 if use_ssl else 80) http_auth = None if parsed_url.username is not None and parsed_url.password is not None: http_auth = (parsed_url.username, parsed_url.password) self.hosts.append({ "host": parsed_url.hostname, "port": port, "url_prefix": parsed_url.path, "use_ssl": use_ssl, "verify_certs": use_ssl, "http_auth": http_auth, }) self.settings = copy.deepcopy( self.settings ) # Make the class settings attribute as instance settings attribute self.settings = deep_update(self.settings, params.pop("INDEX_SETTINGS", {})) # Get Elasticsearch interface # Any remaining params are passed into the Elasticsearch constructor options = params.pop("OPTIONS", {}) self.es = Elasticsearch(hosts=self.hosts, timeout=self.timeout, **options)