-
Notifications
You must be signed in to change notification settings - Fork 1
/
Address.py
32 lines (23 loc) · 827 Bytes
/
Address.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from typing import TypedDict
class AddressData(TypedDict):
ip: str
port: int
class Address(dict):
def __init__(self, ip: str, port: int):
dict.__init__(self, ip=ip, port=port)
self.ip = ip
self.port = port
def __hash__(self):
return hash((self.ip, self.port))
def __eq__(self, other):
return self.ip == other.ip and self.port == other.port
def __str__(self):
return f"{self.ip}:{self.port}"
def __iter__(self):
return iter((self.ip, self.port))
def __eq__(self, other):
return self.ip == other.ip and self.port == other.port
def __ne__(self, other):
return self.ip != other.ip or self.port != other.port
def data(self) -> AddressData:
return AddressData(ip=self.ip, port=self.port)