Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

add private method __getHost for setup default port to 9092 #948

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions pykafka/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def __init__(self,
raise ImportError('use_greenlets can only be used when gevent is installed.')
self._handler = GEventHandler() if use_greenlets else ThreadingHandler()
self.cluster = Cluster(
hosts,
hosts if not ':' in hosts else '{}:{}'.format(hosts, '9092'),
self._handler,
socket_timeout_ms=self._socket_timeout_ms,
offsets_channel_socket_timeout_ms=self._offsets_channel_socket_timeout_ms,
Expand All @@ -148,7 +148,7 @@ def __repr__(self):
module=self.__class__.__module__,
name=self.__class__.__name__,
id_=hex(id(self)),
hosts=self._seed_hosts,
hosts=self.__getHost(self._seed_hosts),
)

def update_cluster(self):
Expand All @@ -158,3 +158,23 @@ def update_cluster(self):
with current metadata from the cluster.
"""
self.cluster.update()

def __getHost(self, host):
"""
Private method for setup default port
:param host:
:return: string with hosts 'host:port,host:port.....'
"""
hosts = host.split(',')
resp = ''

for item in range(len(hosts)):
if ':' in item:
resp += hosts[item]
else:
resp += '{}:{}'.format(hosts[item], '9092')

if len(hosts) > item-1:
resp += ','

return resp