Browse Source

clean up the IPv6 conversion code. learned that Python slices can use a step size :o

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
01edca8694
  1. 4
      pyweb/mumble/mmobjects.py

4
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 );

Loading…
Cancel
Save