Skip to content

Commit 61d0720

Browse files
committed
python host_port
1 parent 65274f0 commit 61d0720

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

python-client/pypegasus/base/ttypes.py

+53
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,59 @@ def __eq__(self, other):
305305
def __ne__(self, other):
306306
return not (self == other)
307307

308+
309+
# TODO(yingchun): host_port is now just a place holder and not well implemented, need improve it
310+
class host_port:
311+
312+
thrift_spec = (
313+
(1, TType.STRING, 'host', None, None, ), # 1
314+
(2, TType.I16, 'port', None, None, ), # 2
315+
)
316+
317+
def __init__(self):
318+
self.host = ""
319+
self.port = 0
320+
321+
def is_valid(self):
322+
return self.port != 0
323+
324+
def from_string(self, host_port):
325+
host_and_port = host_port.split(':')
326+
if len(host_and_port) != 2:
327+
return False
328+
self.host = host_and_port[0]
329+
self.port = int(host_and_port[1])
330+
return True
331+
332+
def to_host_port(self):
333+
return self.host, self.port
334+
335+
def read(self, iprot):
336+
self.host = iprot.readString()
337+
self.port = iprot.readI16()
338+
339+
def write(self, oprot):
340+
oprot.writeString(self.host)
341+
oprot.writeI16(self.port)
342+
343+
def validate(self):
344+
return
345+
346+
def __hash__(self):
347+
return hash(self.host) ^ self.port
348+
349+
def __repr__(self):
350+
L = ['%s=%r' % (key, value)
351+
for key, value in self.__dict__.items()]
352+
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
353+
354+
def __eq__(self, other):
355+
return other.__class__.__name__ == "host_port" and self.__dict__ == other.__dict__
356+
357+
def __ne__(self, other):
358+
return not (self == other)
359+
360+
308361
class gpid:
309362

310363
thrift_spec = (

0 commit comments

Comments
 (0)