From 61d072086f7522041d9cc07b26ae123c66ab9172 Mon Sep 17 00:00:00 2001 From: Yingchun Lai Date: Fri, 5 Jul 2024 23:30:00 +0800 Subject: [PATCH] python host_port --- python-client/pypegasus/base/ttypes.py | 53 ++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/python-client/pypegasus/base/ttypes.py b/python-client/pypegasus/base/ttypes.py index def909a0d6..abd8893f02 100644 --- a/python-client/pypegasus/base/ttypes.py +++ b/python-client/pypegasus/base/ttypes.py @@ -305,6 +305,59 @@ def __eq__(self, other): def __ne__(self, other): return not (self == other) + +# TODO(yingchun): host_port is now just a place holder and not well implemented, need improve it +class host_port: + + thrift_spec = ( + (1, TType.STRING, 'host', None, None, ), # 1 + (2, TType.I16, 'port', None, None, ), # 2 + ) + + def __init__(self): + self.host = "" + self.port = 0 + + def is_valid(self): + return self.port != 0 + + def from_string(self, host_port): + host_and_port = host_port.split(':') + if len(host_and_port) != 2: + return False + self.host = host_and_port[0] + self.port = int(host_and_port[1]) + return True + + def to_host_port(self): + return self.host, self.port + + def read(self, iprot): + self.host = iprot.readString() + self.port = iprot.readI16() + + def write(self, oprot): + oprot.writeString(self.host) + oprot.writeI16(self.port) + + def validate(self): + return + + def __hash__(self): + return hash(self.host) ^ self.port + + def __repr__(self): + L = ['%s=%r' % (key, value) + for key, value in self.__dict__.items()] + return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) + + def __eq__(self, other): + return other.__class__.__name__ == "host_port" and self.__dict__ == other.__dict__ + + def __ne__(self, other): + return not (self == other) + + class gpid: thrift_spec = (