Esempio n. 1
0
 def serialize(addr, protocol_version):
     if ':' in addr:
         return util.inet_pton(socket.AF_INET6, addr)
     else:
         # util.inet_pton could also handle, but this is faster
         # since we've already determined the AF
         return socket.inet_aton(addr)
Esempio n. 2
0
 def serialize(addr, protocol_version):
     if ":" in addr:
         return util.inet_pton(socket.AF_INET6, addr)
     else:
         # util.inet_pton could also handle, but this is faster
         # since we've already determined the AF
         return socket.inet_aton(addr)
Esempio n. 3
0
def write_inet(f, addrtuple):
    addr, port = addrtuple
    if ':' in addr:
        addrfam = socket.AF_INET6
    else:
        addrfam = socket.AF_INET
    addrbytes = util.inet_pton(addrfam, addr)
    write_byte(f, len(addrbytes))
    f.write(addrbytes)
    write_int(f, port)
Esempio n. 4
0
def write_inet(f, addrtuple):
    addr, port = addrtuple
    if ':' in addr:
        addrfam = socket.AF_INET6
    else:
        addrfam = socket.AF_INET
    addrbytes = util.inet_pton(addrfam, addr)
    write_byte(f, len(addrbytes))
    f.write(addrbytes)
    write_int(f, port)
Esempio n. 5
0
 def serialize(addr, protocol_version):
     try:
         if ':' in addr:
             return util.inet_pton(socket.AF_INET6, addr)
         else:
             # util.inet_pton could also handle, but this is faster
             # since we've already determined the AF
             return socket.inet_aton(addr)
     except:
         if six.PY3 and isinstance(addr, (ipaddress.IPv4Address, ipaddress.IPv6Address)):
             return addr.packed
         raise ValueError("can't interpret %r as an inet address" % (addr,))
Esempio n. 6
0
 def serialize(addr, protocol_version):
     try:
         if ':' in addr:
             return util.inet_pton(socket.AF_INET6, addr)
         else:
             # util.inet_pton could also handle, but this is faster
             # since we've already determined the AF
             return socket.inet_aton(addr)
     except:
         if six.PY3 and isinstance(addr, (ipaddress.IPv4Address, ipaddress.IPv6Address)):
             return addr.packed
         raise ValueError("can't interpret %r as an inet address" % (addr,))