Skip to content

Commit

Permalink
python host_port
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed Jul 5, 2024
1 parent 65274f0 commit 61d0720
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions python-client/pypegasus/base/ttypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down

0 comments on commit 61d0720

Please sign in to comment.