From 1b5a0f12c14bc47e8b4250d4a7db3e8302ffeeeb Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Tue, 2 Mar 2010 19:31:37 +0100 Subject: [PATCH] fix a few glitches in the IPv6 address formatting --- pyweb/mumble/mmobjects.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyweb/mumble/mmobjects.py b/pyweb/mumble/mmobjects.py index ad8627b..ab61c19 100644 --- a/pyweb/mumble/mmobjects.py +++ b/pyweb/mumble/mmobjects.py @@ -199,15 +199,15 @@ class mmPlayer( object ): is_player = True; def getIpAsString( self ): - """ Get the client's IPv6 address, in a pretty format. """ + """ Get the client's IPv4 or IPv6 address, in a pretty format. """ ip = self.player_obj.address; if max( ip[:10] ) == 0 and ip[10:12] == (255, 255): return "%d.%d.%d.%d" % tuple( ip[12:] ); # colon-separated string: - ipstr = ':'.join([ ("%02x%02x" % (int(ip[idx]), int(ip[idx+1]))) + ipstr = ':'.join([ ("%x" % ((int(ip[idx])<<8) | int(ip[idx+1]))) for idx in range(0, len(ip), 2) ]); - # 0000:0000:0000 -> :: - return re.sub( "((^|:)(0000:)+)", '::', ipstr ); + # 0:0:0 -> :: + return re.sub( "((^|:)(0:)+)", '::', ipstr, 1 ); ipaddress = property( getIpAsString );