dabo Commit
Revision 4554
Date: 2008-10-05 19:52:47 -0700 (Sun, 05 Oct 2008)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/4554
Changed:
U trunk/dabo/biz/RemoteBizobj.py
U trunk/dabo/lib/RemoteConnector.py
Log:
Updates to work with the changes to the server files posted earlier today.
Diff:
Modified: trunk/dabo/biz/RemoteBizobj.py
===================================================================
--- trunk/dabo/biz/RemoteBizobj.py 2008-10-05 22:51:41 UTC (rev 4553)
+++ trunk/dabo/biz/RemoteBizobj.py 2008-10-06 02:52:47 UTC (rev 4554)
@@ -61,8 +61,10 @@
crs.execute(sql, (hashval, ))
if crs.RowCount:
biz.KeyField = crs.Record.keyfield
- # Unpickle
- crsData = pickle.loads(crs.Record.pickledata)
+ try:
+ crsData = pickle.loads(crs.Record.pickledata)
+ except UnicodeEncodeError:
+ crsData =
pickle.loads(crs.Record.pickledata.encode("utf-8"))
# This is a dict with cursor keys as the keys, and
# values as a (dataset, typedef) tuple.
for kk, (ds, typinfo) in crsData.items():
@@ -105,9 +107,19 @@
cursorDict = self._cursorDictReference()
for kk, cursor in cursorDict.items():
pd[kk] = (cursor.getDataSet(returnInternals=True),
cursor.getDataTypes())
- pklData = pickle.dumps(pd, pickle.HIGHEST_PROTOCOL)
- print
- print "PKTYP", type(pklData)
+ pklData = pickle.dumps(pd, 0)
+ enctype = ""
+ if isinstance(pklData, str):
+ try:
+ unicode(pklData, "utf-8")
+ except UnicodeDecodeError:
+ # Try typical encodings, starting with the
default.
+ for enctype in (self.Encoding, "utf-8",
"latin-1"):
+ try:
+ pklData = unicode(pklData,
enctype)
+ break
+ except UnicodeDecodeError:
+ continue
crs.execute(sql, (hashval, updated, self.KeyField, pklData))
Modified: trunk/dabo/lib/RemoteConnector.py
===================================================================
--- trunk/dabo/lib/RemoteConnector.py 2008-10-05 22:51:41 UTC (rev 4553)
+++ trunk/dabo/lib/RemoteConnector.py 2008-10-06 02:52:47 UTC (rev 4554)
@@ -90,16 +90,31 @@
try:
res = self.UrlOpener.open(url, data=prm)
except urllib2.HTTPError, e:
- print "ERR %s" % e
+ dabo.errorLog.write("HTTPError: %s" % e)
return None
ret = res.read()
return ret
def _storeEncodedDataSet(self, enc):
- data, typs = dabo.lib.jsonDecode(enc)
- # 'typs' is pickled, as it has actual Python types, and cannot
be JSON encoded.
- typs = pickle.loads(typs)
+ pdata, ptyps = dabo.lib.jsonDecode(enc)
+ # Both values are pickled, so we need to unpickle them first
+ def safeLoad(val):
+ ret = None
+ try:
+ ret = pickle.loads(val)
+ except UnicodeEncodeError, e:
+ for enctype in (dabo.defaultEncoding, "utf-8",
"latin-1"):
+ try:
+ ret =
pickle.loads(val.encode(enctype))
+ break
+ except KeyError:
+ continue
+ if ret is None:
+ raise UnicodeEncodeError, e
+ return ret
+ typs = safeLoad(ptyps)
+ data = safeLoad(pdata)
self.obj._storeData(data, typs)
@@ -208,7 +223,7 @@
# A zero filecode represents no changed files
if filecode:
# Request the files
- url = self._getManifestUrl("files", str(filecode))
+ url = self._getManifestUrl(appname, "files",
str(filecode))
try:
res = self.UrlOpener.open(url)
except urllib2.HTTPError, e:
_______________________________________________
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]