@@ -218,6 +218,24 @@ def _get_sniff_data(self, initial=False):
218218
219219 return list (node_info ['nodes' ].values ())
220220
221+ def _get_host_info (self , host_info ):
222+ address_key = self .connection_class .transport_schema + '_address'
223+ host = {}
224+ address = host_info .get (address_key , '' )
225+ if '/' in address :
226+ host ['host' ], address = address .split ('/' , 1 )
227+
228+ # malformed address
229+ if ':' not in address :
230+ return None
231+
232+ ip , port = address .rsplit (':' , 1 )
233+
234+ # use the ip if not overridden by publish_host
235+ host .setdefault ('host' , ip )
236+ host ['port' ] = int (port )
237+
238+ return self .host_info_callback (host_info , host )
221239
222240 def sniff_hosts (self , initial = False ):
223241 """
@@ -231,27 +249,7 @@ def sniff_hosts(self, initial=False):
231249 """
232250 node_info = self ._get_sniff_data (initial )
233251
234- hosts = []
235- address_key = self .connection_class .transport_schema + '_address'
236- for n in node_info :
237- host = {}
238- address = n .get (address_key , '' )
239- if '/' in address :
240- host ['host' ], address = address .split ('/' , 1 )
241-
242- # malformed address
243- if ':' not in address :
244- continue
245-
246- ip , port = address .rsplit (':' , 1 )
247-
248- # use the ip if not overridden by publish_host
249- host .setdefault ('host' , ip )
250- host ['port' ] = int (port )
251-
252- host = self .host_info_callback (n , host )
253- if host is not None :
254- hosts .append (host )
252+ hosts = list (filter (None , (self ._get_host_info (n ) for n in node_info )))
255253
256254 # we weren't able to get any nodes, maybe using an incompatible
257255 # transport_schema or host_info_callback blocked all - raise error.
0 commit comments