Revision 1a8337f2 lib/netutils.py
b/lib/netutils.py | ||
---|---|---|
472 | 472 |
address_int = (address_int << 16) + int(part or '0', 16) |
473 | 473 |
|
474 | 474 |
return address_int |
475 |
|
|
476 |
def FormatAddress(family, address): |
|
477 |
"""Format a socket address |
|
478 |
|
|
479 |
@type family: integer |
|
480 |
@param family: socket family (one of socket.AF_*) |
|
481 |
@type address: family specific (usually tuple) |
|
482 |
@param address: address, as reported by this class |
|
483 |
|
|
484 |
""" |
|
485 |
if family == socket.AF_UNIX and len(address) == 3: |
|
486 |
return "pid=%s, uid=%s, gid=%s" % address |
|
487 |
|
|
488 |
if family in (socket.AF_INET, socket.AF_INET6) and len(address) == 2: |
|
489 |
host, port = address |
|
490 |
if family == socket.AF_INET6: |
|
491 |
res = "[%s]" % host |
|
492 |
else: |
|
493 |
res = host |
|
494 |
|
|
495 |
if port is not None: |
|
496 |
res += ":%s" % port |
|
497 |
|
|
498 |
return res |
|
499 |
|
|
500 |
raise errors.ParameterError(family, address) |
Also available in: Unified diff