Commits

Nathan Durnan committed 971cb1d Merge

Merge with mbcs support

Comments (0)

Files changed (2)

 "Tests/BBI38_EmptyUpdate_Test.bat": {"timestamp": 1341604677.09},
 "Tests/TimestampMod_BBI37_Test.bat": {"timestamp": 1341343207.95},
 "TimeStampMod.png": {"timestamp": 1305052883.0},
-"TimestampMod.py": {"timestamp": 1341612935.72},
+"TimestampMod.py": {"timestamp": 1341933428.41},
 "TimeStampMod.xmind": {"timestamp": 1306451621.66},
 "TimestampMod_LastRecord": {"timestamp": 0}
 }
 		return True
 	# end of check for existing file
 	try:
-		myTimeStampJSONFile = open(repo.wjoin(IN_TimestampFileName), 'r')
+		myTimeStampJSONFile = open(repo.wjoin(IN_TimestampFileName), 'rb')
 		repo.ui.debug( \
 			'______\n', 
 			'Retrieving timestamps from JSON record file:\n', \
 			'------\n')
 		try:
-			myData = json.load(myTimeStampJSONFile)
+			# Read in file content into local string.
+			s_Content = myTimeStampJSONFile.read()
+			myTimeStampJSONFile.close()
+			openedEncoding = None
+			encodingList = list(('utf_8', sys.getfilesystemencoding(),  'ascii'))
+			for testEncoding in encodingList:
+				repo.ui.debug('testEncoding = ', testEncoding, '\n')
+				try:
+					myData =json.loads(unicode(s_Content, testEncoding))
+				except:
+					continue   #move on to check next encoding.
+				else:
+					openedEncoding = testEncoding
+					break   #valid encoding found, no need to try others.
+				# end of load attempt.
+			# end of loop through encoding list.
+			if not openedEncoding: #openedEncoding not detected - try older version.
+				# Try opening as a pre-v0.2.0 CSV file insted:
+				repo.ui.warn('Opening ', IN_TimestampFileName, ' as CSV file\n')
+				myErr = _read_TimestampRecords(repo, IN_TimestampFileName, INOUT_TimeStamp_dict)
+				return myErr
 			# Check for version and object data:
 			if ('FileData' in myData):
 				if (LastPlaceholder in myData['FileData']):
 					del myData['FileData'][LastPlaceholder]
 				myWarnCount = 0 #initialize counter.
 				for s_fileName, obj_fileData in myData['FileData'].items():
+					# convert s_fileName encode (unicode) to sys.getfilesystemencoding()
+					s_fileName = s_fileName.encode(sys.getfilesystemencoding())
+						
 					#Only import data for entries already in local dictionary.
 					if s_fileName in INOUT_TimeStamp_dict:
 						myWarn = False #initialize warning flag for each item.
 				str(sys.exc_info()), '  ***\n')
 			myErr = True	# Error - problem loading JSON file.
 		finally: #cleanup clause
-			myTimeStampJSONFile.close()
-			if myErr: #error return detected - try older version.
-				# Try opening as a pre-v0.2.0 CSV file insted:
-				repo.ui.warn( \
-					'Opening ', \
-					IN_TimestampFileName, \
-					' as CSV file\n')
-				myErr = _read_TimestampRecords( \
-							repo, \
-							IN_TimestampFileName, \
-							INOUT_TimeStamp_dict)
+			pass
 		# end of reading record file.
 		return myErr
 	except: #report errors