[Assorted-commits] SF.net SVN: assorted:[1510] python-commons/trunk/src/commons/networking.py
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-11-08 18:27:50
|
Revision: 1510 http://assorted.svn.sourceforge.net/assorted/?rev=1510&view=rev Author: yangzhang Date: 2009-11-08 18:27:35 +0000 (Sun, 08 Nov 2009) Log Message: ----------- added inet_nltoa, inet_hltoa Modified Paths: -------------- python-commons/trunk/src/commons/networking.py Modified: python-commons/trunk/src/commons/networking.py =================================================================== --- python-commons/trunk/src/commons/networking.py 2009-11-08 06:02:27 UTC (rev 1509) +++ python-commons/trunk/src/commons/networking.py 2009-11-08 18:27:35 UTC (rev 1510) @@ -5,11 +5,11 @@ Networking tools. """ -import os, sys +import os, socket, struct, sys from time import * from contextlib import contextmanager -class NoMacAddrError( Exception ): pass +class no_mac_addr_exception( Exception ): pass def get_mac_addr(): """ @@ -36,7 +36,7 @@ mac = line.split()[4] break if mac is None: - raise NoMacAddrError + raise no_mac_addr_exception return mac def retry_exp_backoff(initial_backoff, multiplier, func): @@ -67,8 +67,14 @@ @contextmanager def logout(x): - """ - A context manager for finally calling the C{logout()} method of an object. - """ + "A context manager for calling the C{logout()} method of an object." try: yield x finally: x.logout() + +def inet_nltoa(x): + "Convert an IPv4 address from an int in network byte order to a string." + return socket.inet_ntoa(struct.pack('>L', x)) + +def inet_hltoa(x): + "Convert an IPv4 address from an int in host byte order to a string." + return socket.inet_ntoa(struct.pack('L', x)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |