dabo Commit
Revision 6361
Date: 2011-02-01 09:51:59 -0800 (Tue, 01 Feb 2011)
Author: Jacekk
Trac: http://trac.dabodev.com/changeset/6361
Changed:
U trunk/dabo/__init__.py
Log:
Little code improvement in dabo.getEncoding() function for better encoding
detection.
Diff:
Modified: trunk/dabo/__init__.py
===================================================================
--- trunk/dabo/__init__.py 2011-02-01 03:55:02 UTC (rev 6360)
+++ trunk/dabo/__init__.py 2011-02-01 17:51:59 UTC (rev 6361)
@@ -128,8 +128,29 @@
from settings import *
def getEncoding():
- return locale.getdefaultlocale()[1] or defaultEncoding
+ encoding = locale.getlocale()[1] or locale.getdefaultlocale()[1] or
defaultEncoding
+ def _getEncodingName():
+ yield encoding
+ if encoding.isdigit():
+ # Fix for missing encoding aliases e.g. '874'.
+ yield "cp%s" % encoding
+ prefEncoding = locale.getpreferredencoding()
+ if not encoding == prefEncoding:
+ yield prefEncoding
+ if not encoding == defaultEncoding:
+ yield defaultEncoding
+ raise ValueError, "Unknown encoding: %s" % encoding
+
+ for encoding in _getEncodingName():
+ try:
+ "".encode(encoding)
+ except LookupError:
+ pass
+ else:
+ break
+ return encoding
+
def getXMLEncoding():
ret = getEncoding()
if ret.lower().strip().replace("-", "") == "utf8":
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message:
http://leafe.com/archives/byMID/[email protected]