Fresco/Fresco-Python/src/FrescoClient __init__.py,1.4,1.5

Neil John Pilgrim <[email protected]>
Newsgroups gmane.comp.video.fresco.cvs
Message-ID <[email protected]>
Update of /cvs/fresco/Fresco/Fresco-Python/src/FrescoClient
In directory purcel:/tmp/cvs-serv14510/Fresco-Python/src/FrescoClient

Modified Files:
	__init__.py 
Log Message:
Fix from (for) task128, with slight modifications:
Add more exception-handling to python module
Thanks to plfiorini.


Index: __init__.py
===================================================================
RCS file: /cvs/fresco/Fresco/Fresco-Python/src/FrescoClient/__init__.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- __init__.py	4 Mar 2003 05:30:01 -0000	1.4
+++ __init__.py	5 Apr 2003 03:08:01 -0000	1.5
@@ -180,7 +180,12 @@
 
         # Try with $FRESCO_DISPLAY
         if stringified_ior != "":
-            object = self.orb.string_to_object(stringified_ior)
+	    try:
+                object = self.orb.string_to_object(stringified_ior)
+	    except:
+		print >> sys.stderr, "WARNING: Server reference " \
+		  "from environment-variable is invalid.\n" \
+		  "Trying other methods."
         else:
             # Try with other methods
             if export_ref == "nameserver":
@@ -214,13 +219,35 @@
                       "published using another method; try the -R option." \
                       % ior_filename
                     sys.exit(1)
-                object = self.orb.string_to_object(stringified_ior)
+		try:
+                    object = self.orb.string_to_object(stringified_ior)
+		except:
+		    print >> sys.stderr, "ERROR: Server reference is invalid."
+		    sys.exit(1)
                 ior_file.close()
                 del ior_file
-        self.server = object._narrow(Fresco.Server)
-        self.context  = self.server.create_server_context(self.clientContext)
-        #print "Got Server var =",self.server
-        #print "Client Context var =",self.clientContext
+	try:
+            self.server = object._narrow(Fresco.Server)
+#        print "Got Server var =",self.server
+        except: 
+            print >> sys.stderr, "ERROR: Reference supplied is not a server."
+            sys.exit(1)
+        try:
+            self.context = self.server.create_server_context(self.clientContext)
+#            print "Client Context var =",self.clientContext
+	except:
+	    print >> sys.stderr, "ERROR: Server reference is valid, " \
+              "but this server cannot be contacted.\n" \
+              "This server may have terminated or is suspended.\n" \
+              "If this is the case, restart or resume the server and " \
+              "try again.\n" \
+              "Alternatively the most recent valid server reference " \
+              "may have been published\n" \
+              "using a different method, in a different place or under " \
+              "another name.\n" \
+              "If this is the case, try using different parameters to the " \
+              "-R, -I or -i options.\n"
+	    sys.exit(1)
 
 class KBThread (threading.Thread):
     """A thread that waits for the user to hit enter, and then signals an
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.