Utilities/__init__.py

changeset 159
2e79b9c72e59
parent 141
c76f1ec28766
child 177
c822ccc4d138
equal deleted inserted replaced
158:6a561f87bc07 159:2e79b9c72e59
173 if coding: 173 if coding:
174 return str(text, coding), coding 174 return str(text, coding), coding
175 except (UnicodeError, LookupError): 175 except (UnicodeError, LookupError):
176 pass 176 pass
177 177
178 # Assume UTF-8
179 try:
180 return str(text, 'utf-8'), 'utf-8-guessed'
181 except (UnicodeError, LookupError):
182 pass
183
178 guess = None 184 guess = None
179 if Preferences.getEditor("AdvancedEncodingDetection"): 185 if Preferences.getEditor("AdvancedEncodingDetection"):
180 # Try the universal character encoding detector 186 # Try the universal character encoding detector
181 try: 187 try:
182 import ThirdParty.CharDet.chardet 188 import ThirdParty.CharDet.chardet
191 197
192 # Try default encoding 198 # Try default encoding
193 try: 199 try:
194 codec = Preferences.getEditor("DefaultEncoding") 200 codec = Preferences.getEditor("DefaultEncoding")
195 return str(text, codec), '%s-default' % codec 201 return str(text, codec), '%s-default' % codec
196 except (UnicodeError, LookupError):
197 pass
198
199 # Assume UTF-8
200 try:
201 return str(text, 'utf-8'), 'utf-8-guessed'
202 except (UnicodeError, LookupError): 202 except (UnicodeError, LookupError):
203 pass 203 pass
204 204
205 if Preferences.getEditor("AdvancedEncodingDetection"): 205 if Preferences.getEditor("AdvancedEncodingDetection"):
206 # Use the guessed one even if confifence level is low 206 # Use the guessed one even if confifence level is low

eric ide

mercurial