dabo Commit
Revision 6059
Date: 2010-10-03 06:11:56 -0700 (Sun, 03 Oct 2010)
Author: Ed
Trac: http://trac.dabodev.com/changeset/6059
Changed:
U trunk/dabo/biz/RemoteBizobj.py
U trunk/dabo/biz/dBizobj.py
U trunk/dabo/db/dCursorMixin.py
U trunk/dabo/lib/utils.py
U trunk/dabo/ui/uiwx/dControlItemMixin.py
U trunk/dabo/ui/uiwx/dForm.py
U trunk/dabo/ui/uiwx/dImage.py
U trunk/dabo/ui/uiwx/dMenuItem.py
U trunk/dabo/ui/uiwx/dTextBoxMixin.py
Log:
Applied Jacek's patches for Trac #1378
Diff:
Modified: trunk/dabo/biz/RemoteBizobj.py
===================================================================
--- trunk/dabo/biz/RemoteBizobj.py 2010-10-03 05:02:05 UTC (rev 6058)
+++ trunk/dabo/biz/RemoteBizobj.py 2010-10-03 13:11:56 UTC (rev 6059)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
import pickle
import os
import time
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py 2010-10-03 05:02:05 UTC (rev 6058)
+++ trunk/dabo/biz/dBizobj.py 2010-10-03 13:11:56 UTC (rev 6059)
@@ -427,7 +427,7 @@
self.RowNumber = current_row
except StandardError, e:
# Need to record what sort of error could be
thrown
- dabo.log.error(_("Failed to set RowNumber.
Error: %s") % e)
+ dabo.log.error(_("Failed to set RowNumber.
Error: %s") % ustr(e))
def save(self, startTransaction=True):
@@ -841,7 +841,7 @@
func(*args, **kwargs)
except StandardError, e:
# Reset things and bail
- dabo.log.error(_("Error in
scanChangedRows: %s") % e)
+ dabo.log.error(_("Error in
scanChangedRows: %s") % ustr(e))
self._CurrentCursor =
old_currentCursorKey
self._positionUsingPK(old_pk)
raise
Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py 2010-10-03 05:02:05 UTC (rev 6058)
+++ trunk/dabo/db/dCursorMixin.py 2010-10-03 13:11:56 UTC (rev 6059)
@@ -314,7 +314,7 @@
', '.join("%s"
% p for p in params)))
except StandardError:
# A problem with writing to the
log, most likely due to encoding issues
- dabo.dbActivityLog.info("FAILED
SQL: %s")
+ dabo.dbActivityLog.info("FAILED
SQL: %r" % sql)
else:
res = self.superCursor.execute(self, sql)
if not self.IsPrefCursor:
@@ -333,15 +333,15 @@
', '.join("%s" % p for
p in params)))
except StandardError:
# A problem with writing to the log,
most likely due to encoding issues
- dabo.dbActivityLog.info("FAILED SQL:
%s")
+ dabo.dbActivityLog.info("FAILED SQL:
%r" % sql)
else:
dabo.dbActivityLog.info("FAILED SQL: %s" % (
sql.decode(self.Encoding).replace("\n", " "),))
# Database errors need to be decoded from database
encoding.
try:
- errMsg = ustr(e).decode(self.Encoding)
+ errMsg = unicode(str(e), self.Encoding)
except UnicodeError:
- errMsg = unicode(e)
+ errMsg = ustr(e)
# If this is due to a broken connection, let the user
know.
# Different backends have different messages, but they
# should all contain the string 'connect' in them.
Modified: trunk/dabo/lib/utils.py
===================================================================
--- trunk/dabo/lib/utils.py 2010-10-03 05:02:05 UTC (rev 6058)
+++ trunk/dabo/lib/utils.py 2010-10-03 13:11:56 UTC (rev 6059)
@@ -15,6 +15,7 @@
import sys
import dabo
from dabo.dLocalize import _
+from locale import getpreferredencoding
try:
from win32com.shell import shell, shellcon
except ImportError:
@@ -141,17 +142,46 @@
return ret
-def ustr(val):
+def getEncodings():
+ encodings = (dabo.getEncoding(), getpreferredencoding(), "iso8859-1",
"iso8859-15", "cp1252", "utf-8")
+ for enc in encodings:
+ yield enc
+
+
+def ustr(value):
"""When converting to a string, do not use the str() function, which
can create encoding errors with non-ASCII text.
"""
+ if isinstance(value, unicode):
+ return value
+ if isinstance(value, Exception):
+ return exceptionToUnicode(value)
try:
- return "%s" % val
- except TypeError:
- # tuples
- return val.__repr__()
+ return unicode(value)
+ except:
+ pass
+ for ln in getEncodings():
+ try:
+ return unicode(value, ln)
+ except:
+ pass
+ raise UnicodeError("Unable to convert '%r'." % value)
+def exceptionToUnicode(e):
+ # Handle DBQueryException first.
+ if hasattr(e, "err_desc"):
+ return ustr(e.err_desc)
+ if hasattr(e, "message"):
+ return ustr(e.message)
+ if hasattr(e, "args"):
+ return "\n".join((ustr(a) for a in e.args))
+ try:
+ return ustr(e)
+ except:
+ return u"Unknow message."
+
+
def relativePathList(toLoc, fromLoc=None):
"""Given two paths, returns a list that, when joined with
os.path.sep, gives the relative path from 'fromLoc' to
Modified: trunk/dabo/ui/uiwx/dControlItemMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dControlItemMixin.py 2010-10-03 05:02:05 UTC (rev
6058)
+++ trunk/dabo/ui/uiwx/dControlItemMixin.py 2010-10-03 13:11:56 UTC (rev
6059)
@@ -355,7 +355,7 @@
if isinstance(string, basestring):
index = self.FindString(string)
if index < 0:
- raise ValueError(_("String must
be present in the choices."))
+ raise ValueError(_("String must
be present in the choices: '%s'") % string)
else:
self.setSelection(index)
else:
Modified: trunk/dabo/ui/uiwx/dForm.py
===================================================================
--- trunk/dabo/ui/uiwx/dForm.py 2010-10-03 05:02:05 UTC (rev 6058)
+++ trunk/dabo/ui/uiwx/dForm.py 2010-10-03 13:11:56 UTC (rev 6059)
@@ -400,9 +400,9 @@
return True
except (dException.BusinessRuleViolation,
dException.DBQueryException), e:
- self.setStatusText(_("Save failed."))
txt = _("Save Failed")
- msg = "%(txt)s:\n\n%(e)s" % locals()
+ self.setStatusText(txt)
+ msg = "%s:\n\n%s" % (txt, ustr(e))
self.notifyUser(msg, severe=True, exception=e)
return False
@@ -564,8 +564,9 @@
self.notifyUser(msg, title=_("Data Connection
Lost"), severe=True, exception=e)
sys.exit()
except dException.dException, e:
- dabo.log.error(_("Delete failed with response:
%s") % e)
- self.notifyUser(ustr(e), title=_("Deletion Not
Allowed"), severe=True, exception=e)
+ msg = ustr(e)
+ dabo.log.error(_("Delete failed with response:
%s") % msg)
+ self.notifyUser(msg, title=_("Deletion Not
Allowed"), severe=True, exception=e)
self.afterDelete()
self.update()
self.refresh()
Modified: trunk/dabo/ui/uiwx/dImage.py
===================================================================
--- trunk/dabo/ui/uiwx/dImage.py 2010-10-03 05:02:05 UTC (rev 6058)
+++ trunk/dabo/ui/uiwx/dImage.py 2010-10-03 13:11:56 UTC (rev 6059)
@@ -284,7 +284,7 @@
self.__val = val
try:
isFile = os.path.exists(val)
- except TypeError:
+ except (TypeError, UnicodeDecodeError):
isFile = False
if not isFile:
# Probably an image stream
Modified: trunk/dabo/ui/uiwx/dMenuItem.py
===================================================================
--- trunk/dabo/ui/uiwx/dMenuItem.py 2010-10-03 05:02:05 UTC (rev 6058)
+++ trunk/dabo/ui/uiwx/dMenuItem.py 2010-10-03 13:11:56 UTC (rev 6059)
@@ -7,6 +7,7 @@
from dabo.dLocalize import _
import dabo.dEvents as dEvents
from dabo.ui import makeDynamicProperty
+from dabo.lib.utils import ustr
class dMenuItem(pm.dPemMixin, wx.MenuItem):
@@ -67,16 +68,10 @@
if hk:
cap = "%s\t%s" % (cap, hk)
curr = self.GetText()
- def toUni(s):
- if isinstance(s, str):
- enc = dabo.getEncoding()
- s = unicode(s, enc)
- return s
-
## pkm: On Windows at least, setting the Icon needs to happen
before setting the caption.
self.SetBitmap(self.Icon)
- if toUni(cap) != toUni(curr):
+ if ustr(cap) != ustr(curr):
## Win32 seems to need to clear the caption first, or
funkiness
## can arise. And win32 in wx2.8 needs for the caption
to never be
## an empty string, or you'll get an invalid stock id
assertion.
Modified: trunk/dabo/ui/uiwx/dTextBoxMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dTextBoxMixin.py 2010-10-03 05:02:05 UTC (rev 6058)
+++ trunk/dabo/ui/uiwx/dTextBoxMixin.py 2010-10-03 13:11:56 UTC (rev 6059)
@@ -6,8 +6,8 @@
import wx
import wx.lib.masked as masked
import dabo.lib.dates
+import dKeys
from dabo.lib.utils import ustr
-
import decimal
numericTypes = (int, long, decimal.Decimal, float)
valueErrors = (ValueError, decimal.InvalidOperation)
@@ -91,9 +91,8 @@
if not self:
# The control is being destroyed
return
- keyChar = evt.keyChar
- if keyChar is not None and (keyChar.isalnum()
- or keyChar in
""",./<>?;':"[]\\{}|`...@#$%%^&*()-_=+"""):
+ keyCode = evt.keyCode
+ if keyCode >= dKeys.key_Space:
dabo.ui.callAfter(self._checkForceCase)
dabo.ui.callAfter(self._checkTextLength)
@@ -631,7 +630,7 @@
# Get the string value as reported by wx, which is the
up-to-date
# string value of the control:
if isinstance(self, masked.TextCtrl) and hasattr(self,
"_template"):
- if self.UsePlainValue:
+ if self.ValueMode == "Unmasked": #No such
property UsePlainValue?
strVal = self.GetPlainValue()
else:
strVal = self.GetValue()
@@ -715,10 +714,9 @@
if strVal != _oldVal:
try:
setter(strVal)
- except ValueError:
+ except ValueError, e:
#PVG: maskedtextedit sometimes fails,
on value error..allow the code to continue
- uStrVal =
self.Application.str2Unicode(strVal)
- dabo.log.error(_("Error setting value
to '%(uStrVal)s: %(e)s") % locals())
+ dabo.log.error(_("Error setting value
to '%s': %s") % (ustr(strVal), ustr(e)))
if type(_oldVal) != type(val) or _oldVal != val:
self._afterValueChanged()
_______________________________________________
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]