changeset 10385:3dfc6b2cf916

zeroconf: try utf-16 decoding if utf-8 fails
author Brendan Cully <brendan@kublai.com>
date Sun, 07 Feb 2010 18:37:14 +0100
parents 832f35386067
children 1ddb0ae26a55
files hgext/zeroconf/Zeroconf.py
diffstat 1 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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"""