diff -r 4d5c02fe9c27 -r 14db3fe42b6c qmsk/net/transport/endpoint.py --- a/qmsk/net/transport/endpoint.py Sun Aug 23 22:43:39 2009 +0300 +++ b/qmsk/net/transport/endpoint.py Sun Aug 23 22:59:40 2009 +0300 @@ -11,23 +11,40 @@ Abstract network address interface, """ - def resolve (self, family, socktype, protocol = 0, passive = True) : + def resolve (self, socktype, protocol = 0, passive = True) : """ - Translate this Endpoint into a sequence of AddrInfo objects for the given family/socktype. + Translate this Endpoint into a sequence of AddrInfo objects for the given socktype. """ raise NotImplemented() -class InetAddr (Endpoint, address.endpoint) : +class InetAddr (Endpoint) : """ An internet address, either IPv4 or IPv6. hostname - [str] literal address or DNS hostname service - [str] port number or service name + family - AF_* associated with this address """ + + def __init__ (self, hostname=None, service=None, family=constants.AF_UNSPEC) : + """ + Initialize with given parameters, but doesn't perform any lookups yet. + """ + + self.endpoint = address.endpoint(hostname, service) + self.family = family - def resolve (self, family, socktype, protocol = 0, passive = True) : + @property + def hostname (self) : + return self.endpoint.hostname + + @property + def service (self) : + return self.endpoint.service + + def resolve (self, socktype, protocol = 0, passive = True) : """ Resolve using getaddrinfo """ @@ -37,7 +54,7 @@ if passive : flags |= constants.AI_PASSIVE - return self.getaddrinfo(family, socktype, protocol, flags) + return self.endpoint.getaddrinfo(self.family, socktype, protocol, flags) class UnixAddr (Endpoint) : """ @@ -48,10 +65,7 @@ self.path = path self.addr = af_unix.sockaddr_un(path) - def resolve (self, family, socktype, protocol = 0, passive = True) : - if family != constants.AF_UNIX : - raise ValueError("Address family mismatch: %s" % (family, )) - + def resolve (self, socktype, protocol = 0, passive = True) : if not socktype : raise ValueError("Unknown socktype: %s" % (socktype, )) @@ -74,18 +88,11 @@ self.family = family self.socktype = socktype - def resolve (self, family, socktype, protocol = 0, passive = True) : + def resolve (self, socktype, protocol = 0, passive = True) : """ Returns a single AddrInfo object representing this address """ - if family and family != self.family : - raise ValueError("Address family mismatch: %s should be %s" % (family, self.family)) - - elif not family : - family = self.family - - if socktype and self.socktype and socktype != self.socktype : raise ValueError("Socket type mismatch: %s should be %s" % (socktype, self.socktype)) @@ -97,5 +104,5 @@ raise ValueError("Socket type unknown") - return [AddrInfo(0, family, socktype, protocol, self.addr, None)] + return [AddrInfo(0, self.family, socktype, protocol, self.addr, None)]