dabo Commit
Revision 4875
Date: 2008-12-18 13:00:14 -0800 (Thu, 18 Dec 2008)
Author: Cito
Trac: http://trac.dabodev.com/dabo/changeset/4875

Changed:
U   trunk/dabo/__init__.py
U   trunk/dabo/dApp.py
U   trunk/dabo/dLocalize.py
U   trunk/dabo/db/dbSQLite.py
U   trunk/dabo/lib/connParser.py
U   trunk/dabo/lib/xmltodict.py
U   trunk/dabo/settings.py
U   trunk/dabo/ui/uiwx/dFormMixin.py

Log:
Fixed #1191 and improved #1185 (sys.getfilesystemencoding() can be None on 
certain platforms).

Diff:
Modified: trunk/dabo/__init__.py
===================================================================
--- trunk/dabo/__init__.py      2008-12-18 19:49:02 UTC (rev 4874)
+++ trunk/dabo/__init__.py      2008-12-18 21:00:14 UTC (rev 4875)
@@ -97,8 +97,9 @@
 Have fun in your exploration of Dabo! 
 """
 
+import sys
 import os
-import sys
+import locale
 import logging
 try:
        import pysqlite2
@@ -124,8 +125,10 @@
 # for the user application separately.
 import dLocalize
 dLocalize.install("dabo")
+# On some platforms getfilesystemencoding() can return None,
+# in these cases we wimply use the encoding from the default locale
+fileSystemEncoding = sys.getfilesystemencoding() or 
locale.getdefaultlocale()[1]
 
-
 # Import global settings (do this first, as other imports may rely on it):
 from settings import *
 

Modified: trunk/dabo/dApp.py
===================================================================
--- trunk/dabo/dApp.py  2008-12-18 19:49:02 UTC (rev 4874)
+++ trunk/dabo/dApp.py  2008-12-18 21:00:14 UTC (rev 4875)
@@ -1263,7 +1263,7 @@
                                pth = pth[:-3]
                        pthList = pth.strip(os.sep).split(os.sep)
                        ret = ".".join(pthList)
-                       ret = ret.decode(sys.getfilesystemencoding())
+                       ret = ret.decode(dabo.fileSystemEncoding)
                return ret
 
        def _setBasePrefKey(self, val):

Modified: trunk/dabo/dLocalize.py
===================================================================
--- trunk/dabo/dLocalize.py     2008-12-18 19:49:02 UTC (rev 4874)
+++ trunk/dabo/dLocalize.py     2008-12-18 21:00:14 UTC (rev 4875)
@@ -1,20 +1,22 @@
 # -*- coding: utf-8 -*-
+
 import sys
+import os
 import locale
-import os
 import gettext
 import warnings
 import dabo
 
 
-_defaultLanguage, _defaultEncoding = locale.getlocale()
+_defaultLanguage, _defaultEncoding = locale.getdefaultlocale()
 
 if _defaultLanguage is None:
-       _defaultLanguage = "en"
+       _defaultLanguage = dabo.settings.defaultLanguage
 
 if _defaultEncoding is None:
-       _defaultEncoding = "utf-8"
+       _defaultEncoding = dabo.settings.defaultEncoding
 
+
 _domains = {}
 _currentTrans = None
 
@@ -113,10 +115,19 @@
 
 
 if __name__ == "__main__":
+
        install()
+
+       print
        print "sys.getdefaultencoding():", sys.getdefaultencoding()
-       print "locale.getlocale():", locale.getlocale()
+       if dabo.settings.loadUserLocale:
+               locale.setlocale(locale.LC_ALL, '')
+               print "locale.getlocale():", locale.getlocale()
+       else:
+               print "locale.getdefaultlocale():", locale.getdefaultlocale()
        print "_defaultLanguage, _defaultEncoding:", _defaultLanguage, 
_defaultEncoding
+       print
+
        stringsToTranslate = ("&File", "&Edit", "&Help", "Application 
finished.")
        max_len = {}
        for s in stringsToTranslate:
@@ -132,24 +143,21 @@
                translatedStrings.append(tuple(translatedStringsLine))
 
        def line(strings=None):
+               lin = []
+               add = lin.append
                if strings is None:
                        # print the boundary
-                       lin =  "+----"
+                       add("+----")
                        for s in stringsToTranslate:
-                               lin += "+-%s-" % ("-" * max_len[s])
-                       lin += "+"
+                               add("+-%s-" % ("-" * max_len[s]))
+                       add("+")
                else:
                        # print the text
-                       lin = ''
-                       for idx, s in enumerate(strings):
-                               if idx == 0:
-                                       len_s = 2
-                               else:
-                                       len_s = 
max_len.get(stringsToTranslate[idx-1], len(s))
-                               s = s.decode("utf-8")
-                               lin += "| %s " % s.ljust(len_s)
-                       lin += "|"
-               return lin
+                       for i, s in enumerate(strings):
+                               len_s = max_len.get(i and 
stringsToTranslate[i-1], len(s))
+                               add("| %s " % s.ljust(len_s))
+                       add("|")
+               return ''.join(lin)
 
        print line()
        print line(("en",) + stringsToTranslate)

Modified: trunk/dabo/db/dbSQLite.py
===================================================================
--- trunk/dabo/db/dbSQLite.py   2008-12-18 19:49:02 UTC (rev 4874)
+++ trunk/dabo/db/dbSQLite.py   2008-12-18 21:00:14 UTC (rev 4875)
@@ -57,7 +57,7 @@
                        if not os.path.exists(pth):
                                # Database file does not exist; raise an error
                                raise DBFileDoesNotExistException(_("Database 
file '%s' does not exist") % pth)
-               pth = pth.decode(sys.getfilesystemencoding()).encode("utf-8")
+               pth = pth.decode(dabo.fileSystemEncoding).encode("utf-8")
                # Need to specify "isolation_level=None" to have transactions 
working correctly.
                self._connection = self.dbapi.connect(pth, 
factory=DictConnection, isolation_level=None)
                self._connection.connectInfo = connectInfo

Modified: trunk/dabo/lib/connParser.py
===================================================================
--- trunk/dabo/lib/connParser.py        2008-12-18 19:49:02 UTC (rev 4874)
+++ trunk/dabo/lib/connParser.py        2008-12-18 21:00:14 UTC (rev 4875)
@@ -76,7 +76,7 @@
                                if key=="database":
                                        osp = os.path
                                        relpath = utils.resolvePath(val, pth, 
abspath=False)
-                                       pth = 
pth.decode(sys.getfilesystemencoding())
+                                       pth = 
pth.decode(dabo.fileSystemEncoding)
                                        abspath = 
osp.abspath(osp.join(osp.split(pth)[0], relpath))
                                        if osp.exists(abspath):
                                                ret[cxn][key] = abspath 

Modified: trunk/dabo/lib/xmltodict.py
===================================================================
--- trunk/dabo/lib/xmltodict.py 2008-12-18 19:49:02 UTC (rev 4874)
+++ trunk/dabo/lib/xmltodict.py 2008-12-18 21:00:14 UTC (rev 4875)
@@ -15,13 +15,14 @@
 from dabo.dLocalize import _
 from dabo.lib.utils import resolvePath
 app = dabo.dAppRef
-if app is not None:
+if app:
        default_encoding = app.Encoding
 else:
-               enc = locale.getlocale()[1]
-               if enc is None:
-                       enc = dabo.defaultEncoding
-               default_encoding = enc
+       default_encoding = locale.getlocale()[1]
+       if default_encoding is None:
+               default_encoding = locale.getdefaultlocale()[1]
+               if default_encoding is None:
+                       default_encoding = dabo.defaultEncoding
                
 # Python seems to need to compile code with \n linesep:
 code_linesep = "\n"

Modified: trunk/dabo/settings.py
===================================================================
--- trunk/dabo/settings.py      2008-12-18 19:49:02 UTC (rev 4874)
+++ trunk/dabo/settings.py      2008-12-18 21:00:14 UTC (rev 4875)
@@ -105,6 +105,9 @@
 # Default font size when none other is specified
 defaultFontSize = 10
 
+# Default language to use when none is specified
+defaultLanguage = "en"
+
 # Default encoding to use when none is specified
 defaultEncoding = "utf-8"
 

Modified: trunk/dabo/ui/uiwx/dFormMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dFormMixin.py    2008-12-18 19:49:02 UTC (rev 4874)
+++ trunk/dabo/ui/uiwx/dFormMixin.py    2008-12-18 21:00:14 UTC (rev 4875)
@@ -707,7 +707,7 @@
        def _setCxnFile(self, val):
                if isinstance(val, unicode):
                        # file names should be byte strings
-                       val = val.encode(sys.getfilesystemencoding())
+                       val = val.encode(dabo.fileSystemEncoding)
                self._cxnFile = val
 
 




_______________________________________________
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]

Reply via email to