From 01edca8694a241b0b61ca780882bd45e1db37377 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Tue, 2 Mar 2010 22:14:10 +0100 Subject: [PATCH] clean up the IPv6 conversion code. learned that Python slices can use a step size :o --- pyweb/mumble/mmobjects.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyweb/mumble/mmobjects.py b/pyweb/mumble/mmobjects.py index ab61c19..597e488 100644 --- a/pyweb/mumble/mmobjects.py +++ b/pyweb/mumble/mmobjects.py @@ -203,9 +203,9 @@ class mmPlayer( object ): ip = self.player_obj.address; if max( ip[:10] ) == 0 and ip[10:12] == (255, 255): return "%d.%d.%d.%d" % tuple( ip[12:] ); + ip6addr = [(hi << 8 | lo) for (hi, lo) in zip(addr[0::2], addr[1::2])] # colon-separated string: - ipstr = ':'.join([ ("%x" % ((int(ip[idx])<<8) | int(ip[idx+1]))) - for idx in range(0, len(ip), 2) ]); + ipstr = ':'.join([ ("%x" % part) for part in ip6addr ]); # 0:0:0 -> :: return re.sub( "((^|:)(0:)+)", '::', ipstr, 1 );