dabo Commit
Revision 5097
Date: 2009-03-01 18:20:20 -0800 (Sun, 01 Mar 2009)
Author: Ed
Trac: http://trac.dabodev.com/changeset/5097

Changed:
U   trunk/dabo/lib/RemoteConnector.py

Log:
Improved some of the error handling, including the option to re-raise errors in 
_read() so that the calling proc can handle them.


Diff:
Modified: trunk/dabo/lib/RemoteConnector.py
===================================================================
--- trunk/dabo/lib/RemoteConnector.py   2009-03-02 01:56:02 UTC (rev 5096)
+++ trunk/dabo/lib/RemoteConnector.py   2009-03-02 02:20:20 UTC (rev 5097)
@@ -49,7 +49,7 @@
                return ret
 
 
-       def _read(self, url, params=None):
+       def _read(self, url, params=None, reRaise=False):
                if params:
                        prm = urllib.urlencode(params)
                else:
@@ -57,6 +57,8 @@
                try:
                        res = self.UrlOpener.open(url, data=prm)
                except urllib2.HTTPError, e:
+                       if reRaise:
+                               raise
                        dabo.errorLog.write("HTTPError: %s" % e)
                        return None
                ret = res.read()
@@ -169,14 +171,22 @@
                listURL = "%s://%s/manifest" % (scheme, host)
                res = None
                try:
-                       res = jsonDecode(self._read(listURL))
+                       res = jsonDecode(self._read(listURL, reRaise=True))
                except urllib2.URLError, e:
-                       code, msg = e.reason
-#                      print "CODE<MSG", code, msg
+                       try:
+                               code, msg = e.reason
+                       except AttributeError:
+                               # Probably an HTTP code
+                               code = e.code
+                               msg = e.msg
                        if code == 61:
                                # Connection refused; server's down
                                return "Error: The server is not responding. 
Please try later"
+                       elif code == 404:
+                               # Not a Dabo application server
+                               return "404 Not Found"
                except urllib2.HTTPError, e:
+                       print dir(e)
                        errText = e.read()
                        errMsg = "\n".join(errText.splitlines()[4:])
                        dabo.errorLog.write(_("HTTP Error getting app list: 
%s") % e)
@@ -351,19 +361,14 @@
                        # Set explicitly by the launch() method
                        return self._baseURL
                app = dabo.dAppRef
-               ret = ""
-               try:
+               if app:
+                       ret = app.SourceURL
+               else:
+                       ret = ""
+               if not ret:
+                       # See if it's specified in the connection
                        ret = self.Connection.ConnectInfo.RemoteHost
-               except AttributeError:
-                       # Might be an application object
-                       try:
-                               ret = self.obj.SourceURL
-                       except AttributeError:
-                               # Use the app object
-                               if app:
-                                       ret = app.SourceURL
-               else:
-                       if app and not app.SourceURL:
+                       if app:
                                app.SourceURL = ret
                return ret
 



_______________________________________________
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