zeroconf: try utf-16 decoding if utf-8 fails
authorBrendan Cully <brendan@kublai.com>
Sun, 07 Feb 2010 18:37:14 +0100
changeset 10385 3dfc6b2cf916
parent 10384 832f35386067
child 10386 1ddb0ae26a55
zeroconf: try utf-16 decoding if utf-8 fails
hgext/zeroconf/Zeroconf.py
--- a/hgext/zeroconf/Zeroconf.py	Sun Feb 07 18:06:52 2010 +0100
+++ b/hgext/zeroconf/Zeroconf.py	Sun Feb 07 18:37:14 2010 +0100
@@ -575,8 +575,11 @@
 
 	def readUTF(self, offset, len):
 		"""Reads a UTF-8 string of a given length from the packet"""
-		result = self.data[offset:offset+len].decode('utf-8')
-		return result
+		result = self.data[offset:offset+len]
+		try:
+			return result.decode('utf-8')
+		except UnicodeDecodeError:
+			return result.decode('utf-16')
 
 	def readName(self):
 		"""Reads a domain name from the packet"""