commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

r6203 - in trunk/gnue-common/src: apps datasources datasources/drivers/a


From: johannes
Subject: r6203 - in trunk/gnue-common/src: apps datasources datasources/drivers/appserver/appserver logic logic/adapters rpc rpc/drivers rpc/drivers/xmlrpc/pw_xmlrpc
Date: Wed, 25 Aug 2004 07:30:13 -0500 (CDT)

Author: johannes
Date: 2004-08-25 07:30:12 -0500 (Wed, 25 Aug 2004)
New Revision: 6203

Added:
   trunk/gnue-common/src/apps/GExceptions.py
Modified:
   trunk/gnue-common/src/apps/__init__.py
   trunk/gnue-common/src/apps/i18n.py
   trunk/gnue-common/src/datasources/GDataSource.py
   trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
   trunk/gnue-common/src/logic/GTrigger.py
   trunk/gnue-common/src/logic/adapters/Base.py
   trunk/gnue-common/src/logic/adapters/python.py
   trunk/gnue-common/src/logic/language.py
   trunk/gnue-common/src/rpc/client.py
   trunk/gnue-common/src/rpc/drivers/Base.py
   trunk/gnue-common/src/rpc/drivers/xmlrpc/pw_xmlrpc/ClientAdapter.py
   trunk/gnue-common/src/rpc/drivers/xmlrpc/pw_xmlrpc/ServerAdapter.py
   trunk/gnue-common/src/rpc/server.py
Log:
Indroduced new base-exception-classes and improved handling of remote exceptions


Added: trunk/gnue-common/src/apps/GExceptions.py
===================================================================
--- trunk/gnue-common/src/apps/GExceptions.py   2004-08-25 09:11:19 UTC (rev 
6202)
+++ trunk/gnue-common/src/apps/GExceptions.py   2004-08-25 12:30:12 UTC (rev 
6203)
@@ -0,0 +1,240 @@
+# GNU Enterprise Common - Base exception classes
+#
+# Copyright 2001-2004 Free Software Foundation
+#
+# This file is part of GNU Enterprise
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id: $
+
+import sys
+import traceback
+import types
+import string
+import exceptions
+
+from gnue.common.apps import i18n
+
+# =============================================================================
+# New basic exception class. Python's standard exception class cannot handle
+# unicode messages.
+# =============================================================================
+
+class gException (Exception):
+  """
+  The same as the builtin python Exception, but can handle messages that are
+  unicode strings.  This exception is available as the builtin class
+  "gException".  All other user-defined exceptions should be derived from this
+  class.
+  """
+  def __init__ (self, message):
+    self.message = message
+    self.exType   = "gException"
+    self.exName   = None
+    self.exDetail = None
+    exceptions.Exception.__init__ (self, o(message))
+
+  # ---------------------------------------------------------------------------
+  # Get the type of the exception
+  # ---------------------------------------------------------------------------
+
+  def getType (self):
+    """
+    This function returns the type (i.e. 'gException', 'System', 'User', ...)
+    of the exception.
+    @return: type of the exception as unicode string
+    """
+    return self._fmtUnicode (self.exType)
+
+
+  # ---------------------------------------------------------------------------
+  # Return the name of the exception
+  # ---------------------------------------------------------------------------
+
+  def getName (self):
+    """
+    This function returns the name of the exception (i.e. 'FooBarError')
+    @return: name of the exception as unicode string
+    """
+    rep = self.exName is not None and self.exName or "%s" % sys.exc_info () [0]
+    return self._fmtUnicode (rep.split ('.') [-1])
+
+
+  # ---------------------------------------------------------------------------
+  # Get the detail of an exception
+  # ---------------------------------------------------------------------------
+
+  def getDetail (self):
+    """
+    This function returns the exception's detail which is a traceback for
+    gException instances.
+    @return: unicode string with the exception's traceback
+    """
+    if self.exDetail is not None:
+      return self._fmtUnicode (self.exDetail, i18n.encoding)
+
+    tStack = traceback.format_exception (*sys.exc_info ())
+    return self._fmtUnicode ("%s" % string.join (tStack), i18n.encoding)
+
+
+  # ---------------------------------------------------------------------------
+  # Get the message of an exception
+  # ---------------------------------------------------------------------------
+
+  def getMessage (self):
+    """
+    This function returns the message of an exception
+    @return: unicode string with the message of the exception
+    """
+    return self._fmtUnicode (self.message)
+
+
+  # ---------------------------------------------------------------------------
+  # Make sure a given text is a unicode string
+  # ---------------------------------------------------------------------------
+
+  def _fmtUnicode (self, text, encoding = None):
+    """
+    This function returns a given text as unicode string using an optional
+    encoding or the system's default encoding.
+    @param text: the string to be encoded. If this string is already unicode no
+        modification will take place.
+    @return: unicode representation of @text.
+    """
+    if isinstance (text, types.UnicodeType):
+      return text
+    else:
+      if encoding is not None:
+        return unicode (text, encoding, 'replace')
+      else:
+        return unicode (text, errors = 'replace')
+
+
+# =============================================================================
+# System Error
+# =============================================================================
+
+class SystemError (gException):
+  """
+  This exception class should be used for exceptions indicating a bug in GNUe.
+  Whenever such an exception is raised, one have found such a bug :)
+  """
+  def __init__ (self, message):
+    gException.__init__ (self, message)
+    self.exType = "System"
+
+
+# =============================================================================
+# Administrative Errors
+# =============================================================================
+
+class AdminError (gException):
+  """
+  This exception class should be used for exceptions indicating a
+  misconfiguration in a widest sense. This could be a missing module for a
+  dbdriver as well as an 'out of disk space' error.
+  """
+  def __init__ (self, message):
+    gException.__init__ (self, message)
+    self.exType = "Admin"
+
+
+# =============================================================================
+# Application Errors
+# =============================================================================
+
+class ApplicationError (gException):
+  """
+  This class should be used for errors caused by applications like a corrupt
+  trigger code, or a misformed xml-file and so on.
+  """
+  def __init__ (self, message):
+    gException.__init__ (self, message)
+    self.exType = "Application"
+
+
+# =============================================================================
+# User Errors
+# =============================================================================
+
+class UserError (gException):
+  """
+  This class should be used for exceptions where a user did something wrong, or
+  a situation has occured which isn't dramatic, but the user has to be informed
+  of. Example: wrong password or the user has entered non-numeric data into a
+  numeric field, and so on
+  """
+  def __init__ (self, message):
+    gException.__init__ (self, message)
+    self.exType = u"User"
+
+
+# =============================================================================
+# Exceptions raised on a remote site/process
+# =============================================================================
+
+class RemoteError (gException):
+  """
+  This class is used for transporting an exception raised at a remote point.
+  Once it has been created it never changes it's contents. A remote error
+  usually contains System-, Admin- or User-Errors.
+  """
+  def __init__ (self, exType, exName, message, exDetail):
+    gException.__init__ (self, message)
+    self.exType   = exType
+    self.exName   = exName
+    self.exDetail = exDetail
+
+
+# -----------------------------------------------------------------------------
+# Get a tuple (type, name, message, detail) for the last exception raised
+# -----------------------------------------------------------------------------
+
+def getException (count = None):
+  """
+  This function creates a tuple (type, name, message, detail) for the last
+  exception raised. The optional parameter determines the number of lines
+  skipped from the detail traceback.
+  @param count: number of lines to skip in the traceback
+  @returns: tuple with type, name, message and detail of the last exception.
+  """
+  (aType, aValue, aTrace) = sys.exc_info ()
+
+  if isinstance (aValue, gException):
+    return (aValue.getType (), aValue.getName (), aValue.getMessage (),
+            aValue.getDetail ())
+  else:
+    # Exception was not a descendant of gException, so we construct the tuple
+    # from the exception information
+    lines = traceback.format_exception (aType, aValue, aTrace)
+    if count is not None:
+      del lines [1:count + 1]
+
+    exName    = unicode (aType)
+    exMessage = unicode (aValue)
+    exDetail  = string.join (lines)
+    if isinstance (exDetail, types.StringType):
+      exDetail = unicode (exDetail, i18n.encoding)
+    return ('System', exName, exMessage, exDetail)
+
+
+# =============================================================================
+# Code executed once per module load
+# =============================================================================
+
+import __builtin__
+__builtin__.__dict__['gException'] = gException


Property changes on: trunk/gnue-common/src/apps/GExceptions.py
___________________________________________________________________
Name: svn:keywords
   + +Id

Modified: trunk/gnue-common/src/apps/__init__.py
===================================================================
--- trunk/gnue-common/src/apps/__init__.py      2004-08-25 09:11:19 UTC (rev 
6202)
+++ trunk/gnue-common/src/apps/__init__.py      2004-08-25 12:30:12 UTC (rev 
6203)
@@ -38,3 +38,4 @@
 import GDebug
 import i18n
 import checktype
+import GExceptions

Modified: trunk/gnue-common/src/apps/i18n.py
===================================================================
--- trunk/gnue-common/src/apps/i18n.py  2004-08-25 09:11:19 UTC (rev 6202)
+++ trunk/gnue-common/src/apps/i18n.py  2004-08-25 12:30:12 UTC (rev 6203)
@@ -145,22 +145,7 @@
   else:
     return message
 
-# -----------------------------------------------------------------------------
-# New basic exception class. Python's standard exception class cannot handle
-# unicode messages.
-# -----------------------------------------------------------------------------
 
-class gException (Exception):
-  """
-  The same as the builtin python Exception, but can handle messages that are
-  unicode strings.  This exception is available as the builtin class
-  "gException".  All other user-defined exceptions should be derived from this
-  class.
-  """
-  def __init__ (self, message):
-    self.message = message
-    exceptions.Exception.__init__ (self, o(message))
-
 # -----------------------------------------------------------------------------
 # Module initialization
 # -----------------------------------------------------------------------------
@@ -179,8 +164,7 @@
   encoding = 'ascii'
 
 # Now define the new builtin stuff
-import __builtin__  
+import __builtin__
 __builtin__.__dict__['u_'] = utranslate
 __builtin__.__dict__['_'] = translate
 __builtin__.__dict__['o'] = outconv
-__builtin__.__dict__['gException'] = gException

Modified: trunk/gnue-common/src/datasources/GDataSource.py
===================================================================
--- trunk/gnue-common/src/datasources/GDataSource.py    2004-08-25 09:11:19 UTC 
(rev 6202)
+++ trunk/gnue-common/src/datasources/GDataSource.py    2004-08-25 12:30:12 UTC 
(rev 6203)
@@ -39,9 +39,7 @@
 from gnue.common.datasources import GConditions, Exceptions
 from gnue.common.definitions.GParserHelpers import GContent
 
-from gnue.common.rpc import client
 
-
 ########################################################################
 #
 # Class that handles DataSources.  This is a subclass of GObj, which
@@ -745,9 +743,6 @@
     try:
       res = rs.current.callFunc ("gnue_%s" % element, paramDict)
 
-    except client.DistantError, distErr:
-      raise Exception, distErr.detail
-
     except Exception, e:
       raise
 

Modified: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py 
2004-08-25 09:11:19 UTC (rev 6202)
+++ trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py 
2004-08-25 12:30:12 UTC (rev 6203)
@@ -31,6 +31,7 @@
 from gnue.common.datasources import Exceptions
 from gnue.common.datasources.drivers import Base
 from gnue.common.rpc import client
+from gnue.common.apps import GExceptions
 
 import DataObject
 
@@ -79,13 +80,15 @@
     try:
       self._sess_id = self._sm.open ({'user': user, 'password': passwd})
 
-    except client.DistantError, e:
-      if e.type == 'AuthError':
-        raise Exceptions.LoginError, e.message
+    except GExceptions.RemoteError, e:
+      if e.getName () == 'AuthError':
+        raise Exceptions.LoginError, e.getMessage ()
       else:
-        raise Exceptions.ConnectionError, e.message
+        raise Exceptions.ConnectionError, e.getMessage ()
+      
     except gException, e:
-      raise Exceptions.ConnectError, e.message  # handle unicode message
+      raise Exceptions.ConnectError, e.getMessage ()
+
     except:
       raise Exceptions.ConnectError, "%s" % sys.exc_info () [1]
 

Modified: trunk/gnue-common/src/logic/GTrigger.py
===================================================================
--- trunk/gnue-common/src/logic/GTrigger.py     2004-08-25 09:11:19 UTC (rev 
6202)
+++ trunk/gnue-common/src/logic/GTrigger.py     2004-08-25 12:30:12 UTC (rev 
6203)
@@ -299,9 +299,6 @@
           except AbortRequest:
             if not ignoreAbort:
               raise
-          except RuntimeError, msg:
-            # call my own exceptionHandler here.
-            print "Runtime Error occured:\n %s" % msg
       else:
         GDebug.printMesg(10, "No triggers to fire")
     else:

Modified: trunk/gnue-common/src/logic/adapters/Base.py
===================================================================
--- trunk/gnue-common/src/logic/adapters/Base.py        2004-08-25 09:11:19 UTC 
(rev 6202)
+++ trunk/gnue-common/src/logic/adapters/Base.py        2004-08-25 12:30:12 UTC 
(rev 6203)
@@ -192,16 +192,3 @@
     """
     pass
 
-
-  # ---------------------------------------------------------------------------
-  # Put info for current exception into a string
-  # ---------------------------------------------------------------------------
-
-  def _traceback (self, count):
-    """
-    Returns the complete traceback of the current exception as a string, where
-    the first @count lines of the traceback are hidden.
-    """
-    lines = traceback.format_exception (*sys.exc_info ())
-    del lines [1:count + 1]
-    return string.join (lines, '')

Modified: trunk/gnue-common/src/logic/adapters/python.py
===================================================================
--- trunk/gnue-common/src/logic/adapters/python.py      2004-08-25 09:11:19 UTC 
(rev 6202)
+++ trunk/gnue-common/src/logic/adapters/python.py      2004-08-25 12:30:12 UTC 
(rev 6203)
@@ -25,6 +25,7 @@
 import re
 import copy
 
+from gnue.common.apps import GExceptions
 from gnue.common.logic import language
 from gnue.common.logic.adapters import Base
 
@@ -148,7 +149,7 @@
     try:
       tabPos = text.find ('\t')
       if tabPos > -1:
-        raise gException, \
+        raise GExceptions.ApplicationError, \
            u_("Sourcecode contains tab character at position %d") % tabPos
 
 
@@ -179,7 +180,8 @@
       self._compiled = compile (revisedCode.encode ('utf-8'),
                      '<%s>' % self._context.shortname.encode ('utf-8'), 'exec')
     except:
-      raise language.CompileError, self._traceback (1)
+      (etype, name, message, detail) = GExceptions.getException (1)
+      raise language.CompileError, ('Application', name, message, detail)
 
 
   # ---------------------------------------------------------------------------
@@ -207,12 +209,15 @@
         return localNS ['__result']
       else:
         return None
+
     except language.AbortRequest:
       # Pass through AbortRequests unchanged
       raise
+
     except:
       # All others raise a RuntimeError
-      raise language.RuntimeError, self._traceback (2)
+      (etype, name, message, detail) = GExceptions.getException (2)
+      raise language.RuntimeError, ('Application', name, message, detail)
 
 
   # ---------------------------------------------------------------------------

Modified: trunk/gnue-common/src/logic/language.py
===================================================================
--- trunk/gnue-common/src/logic/language.py     2004-08-25 09:11:19 UTC (rev 
6202)
+++ trunk/gnue-common/src/logic/language.py     2004-08-25 12:30:12 UTC (rev 
6203)
@@ -21,6 +21,8 @@
 # $Id$
 
 import string
+
+from gnue.common.apps import GExceptions
 from gnue.common.utils.FileUtils import dyn_import
 
 adapters = {}
@@ -40,20 +42,20 @@
 # Python module not available
 # -----------------------------------------------------------------------------
 
-class AdapterNotFoundError (Error):
+class AdapterNotFoundError (GExceptions.AdminError):
   """
   The language adapter for the requested language cannot be imported.
   """
   def __init__ (self, language):
     msg = u_("No adapter available for language '%s'") % language
-    Error.__init__ (self, msg)
+    GExceptions.AdminError.__init__ (self, msg)
 
 
 # -----------------------------------------------------------------------------
 # Abstract method not implemented
 # -----------------------------------------------------------------------------
 
-class ImplementationError (Error):
+class ImplementationError (GExceptions.SystemError):
   """
   Exception raised if an abstract method isn't implemented by a descendant.
   """
@@ -61,49 +63,27 @@
     msg = u_("The class '%(class)s' has no implementation for '%(method)s'") \
            % {"class" : classname,
               "method": method}
-    Error.__init__ (self, msg)
+    GExceptions.SystemError.__init__ (self, msg)
 
 # -----------------------------------------------------------------------------
 # Code failed on compilation
 # -----------------------------------------------------------------------------
 
-class CompileError (Error):
+class CompileError (GExceptions.RemoteError):
   pass
 
 # -----------------------------------------------------------------------------
 # Code failed on execution
 # -----------------------------------------------------------------------------
 
-class RuntimeError (Error):
-  """
-  Indicates an exception that happend on execution of a method/function.
+class RuntimeError (GExceptions.RemoteError):
+  pass
 
-  If e is an exception of this type, then e.message is the message text of the
-  exception that occured, e.type is a string containing the name of the type of
-  the exception, and e.detail is the complete traceback.
-  """
-  def __init__ (self, traceback):
-    self.detail = traceback
-    self.type   = ''
-    message     = ''
-
-    # Search for start of Exception type/value part
-    list = string.split (traceback, '\n')
-    for i in range (1, len (list) - 1):
-      if len (list [i]) > 0 and list [i] [0] != ' ':
-        info = string.split (list [i], ': ', 1)
-        if len (info) == 2:
-          self.type = info [0]
-          message = string.join ([info [1]] + list [i+1:], '\n')
-          break
-    Error.__init__ (self, message)
-
-
 # -----------------------------------------------------------------------------
 # Abort the current execution
 # -----------------------------------------------------------------------------
 
-class AbortRequest (Error):
+class AbortRequest (GExceptions.UserError):
   pass
 
 # -----------------------------------------------------------------------------
@@ -147,7 +127,7 @@
   code = """
 print "Hello World!"
 print "My name is %s." % name
-print fuck
+print foobar
 return value * 2
 """
 

Modified: trunk/gnue-common/src/rpc/client.py
===================================================================
--- trunk/gnue-common/src/rpc/client.py 2004-08-25 09:11:19 UTC (rev 6202)
+++ trunk/gnue-common/src/rpc/client.py 2004-08-25 12:30:12 UTC (rev 6203)
@@ -23,7 +23,7 @@
 
 import string
 
-from gnue.common.apps import GDebug, plugin
+from gnue.common.apps import GExceptions, plugin
 
 # =============================================================================
 # Public functions
@@ -52,7 +52,7 @@
 # Requested adapter does not exist
 # -----------------------------------------------------------------------------
 
-class InvalidAdapter (Error):
+class InvalidAdapter (GExceptions.AdminError):
   pass
 
 # -----------------------------------------------------------------------------
@@ -60,7 +60,7 @@
 # supplied parameters do not point to a valid server, etc.
 # -----------------------------------------------------------------------------
 
-class AdapterInitializationError (Error):
+class AdapterInitializationError (GExceptions.AdminError):
   pass
 
 # -----------------------------------------------------------------------------
@@ -76,7 +76,7 @@
 # Parent for all caller errors
 # -----------------------------------------------------------------------------
 
-class ProgrammingError (Error):
+class ProgrammingError (GExceptions.SystemError):
   pass
 
 # -----------------------------------------------------------------------------
@@ -94,36 +94,7 @@
 class InvalidParameter (ProgrammingError):
   pass
 
-# -----------------------------------------------------------------------------
-# An error which has occured on the server and is raised again on the client
-# -----------------------------------------------------------------------------
 
-class DistantError (Error):
-  """
-  Indicates an exception that happened on the server side.
-
-  If e is an exception of this type, then e.message is the message text of the
-  exception that occured on the server side, e.type is a string containing the
-  name of the type of the server side exception, and e.detail is the complete
-  server side traceback.
-  """
-  def __init__ (self, traceback):
-    self.detail = unicode (traceback, 'utf-8')
-    self.type = ''
-    message = ''
-
-    # Search for start of Exception type/value part
-    list = string.split (self.detail, '\n')
-    for i in range (1, len (list) - 1):
-      if len (list [i]) > 0 and list [i] [0] != ' ':
-        info = string.split (list [i], ': ', 1)
-        if len (info) == 2:
-          self.type = info [0]
-          message = string.join ([info [1]] + list [i+1:], '\n')
-          break
-
-    Error.__init__ (self, message)
-
 # =============================================================================
 # Self test code - requires server.py running
 # =============================================================================
@@ -131,7 +102,7 @@
 if __name__ == '__main__':
 
   import traceback
-  from gnue.common.rpc import client # to recogize DistantError
+  from gnue.common.apps import GExceptions
 
   connection = attach ('xmlrpc', {})
 
@@ -143,27 +114,35 @@
   print 'floattest: 123.45 * 2 =', repr (obj.floattest (123.45))
   print 'datetimetest:', repr (obj.datetimetest ())
   print 'booltest:', repr (obj.booltest ())
-  subobj = obj.objtest ()
-  print 'objtest:', repr (subobj)
+  #subobj = obj.objtest ()
+  #print 'objtest:', repr (subobj)
 # print 'subobj.test'
 # subobj.test ()
-  del subobj
+  #del subobj
 
   print 'testing exception ...'
+
   try:
     obj.exceptiontest ()
-  except client.DistantError, e:
+
+  except Exception, e:
     print "-" * 70
-    print "exception message:", e
+    if isinstance (e, GExceptions.gException):
+      print "Exception Type:", e.getType ()
+      print "Exception Name:", e.getName ()
+      print "Message       :", e.getMessage ()
+    else:
+      print "Exception:", e
+
     print "-" * 70
     print "local traceback:"
     traceback.print_exc ()
-    print "-" * 70
-    print "remote exception type:", e.type
-    print "-" * 70
-    print "remote exception detail:", e.detail
-    print "-" * 70
 
+    if isinstance (e, GExceptions.gException):
+      print "-" * 70
+      print "remote exception detail:", e.getDetail ()
+      print "-" * 70
+
   print 'shutting donwn server ...'
   try:
     # This will raise an exception because the server will not even answer any

Modified: trunk/gnue-common/src/rpc/drivers/Base.py
===================================================================
--- trunk/gnue-common/src/rpc/drivers/Base.py   2004-08-25 09:11:19 UTC (rev 
6202)
+++ trunk/gnue-common/src/rpc/drivers/Base.py   2004-08-25 12:30:12 UTC (rev 
6203)
@@ -285,22 +285,3 @@
 
   def raiseException (self, exception, message, event=None):
     raise exception, message
-
-  # ---------------------------------------------------------------------------
-  # Put info for current exception into a string to transfer it over RPC
-  # ---------------------------------------------------------------------------
-
-  def _traceback (self, count):
-    """
-    Returns the complete traceback of the exception as a string, where the
-    first count lines of the traceback are hidden.
-
-    This method can be used in descendant classes to encapsulate a traceback
-    that happened on the server and send it over to the client.
-    """
-    lines = traceback.format_exception (*sys.exc_info ())
-    del lines [1:count+1]
-    result = string.join (lines, '')
-    if isinstance (result, StringType):
-      result = unicode (result, i18n.encoding)
-    return result

Modified: trunk/gnue-common/src/rpc/drivers/xmlrpc/pw_xmlrpc/ClientAdapter.py
===================================================================
--- trunk/gnue-common/src/rpc/drivers/xmlrpc/pw_xmlrpc/ClientAdapter.py 
2004-08-25 09:11:19 UTC (rev 6202)
+++ trunk/gnue-common/src/rpc/drivers/xmlrpc/pw_xmlrpc/ClientAdapter.py 
2004-08-25 12:30:12 UTC (rev 6203)
@@ -38,6 +38,7 @@
 import string
 import sys
 
+from gnue.common.apps import GExceptions
 from gnue.common.rpc import client
 from gnue.common.rpc.drivers import Base
 
@@ -93,7 +94,9 @@
     try:
       result = to_call (*__args, **params)
     except xmlrpclib.Fault, e:
-      raise client.DistantError, e.faultString
+      (exType, exName, exMessage, exDetail) = string.split (e.faultString,
+                                                            u'\x91')
+      raise GExceptions.RemoteError, (exType, exName, exMessage, exDetail)
 
     # check, if an object handle is sent
     # TODO: make a better check

Modified: trunk/gnue-common/src/rpc/drivers/xmlrpc/pw_xmlrpc/ServerAdapter.py
===================================================================
--- trunk/gnue-common/src/rpc/drivers/xmlrpc/pw_xmlrpc/ServerAdapter.py 
2004-08-25 09:11:19 UTC (rev 6202)
+++ trunk/gnue-common/src/rpc/drivers/xmlrpc/pw_xmlrpc/ServerAdapter.py 
2004-08-25 12:30:12 UTC (rev 6203)
@@ -34,7 +34,7 @@
 #
 
 from gnue.common.rpc import server
-from gnue.common.apps import GDebug
+from gnue.common.apps import GExceptions
 from gnue.common.rpc.drivers._helpers import ObjectLibrarian, DirectoryServer
 
 from BaseHTTPServer import BaseHTTPRequestHandler;
@@ -301,7 +301,9 @@
       try:
         result = server_method(*__params)
       except:
-        return xmlrpclib.Fault (1, self._traceback (1))
+        stack = string.join (GExceptions.getException (1), u'\x91')
+        return xmlrpclib.Fault (1, stack)
+
       else:
         result = typeconv.python_to_rpc (result, server.InvalidParameter)
 
@@ -317,8 +319,7 @@
       mparts.reverse()
       calltype=mparts[0]
       calltype=calltype[:4]
-      GDebug.printMesg(7,'method %s has calling type %s' %\
-                       (method,calltype))
+      gDebug (7, 'method %s has calling type %s' % (method,calltype))
       if calltype=='set_':
         # setAttribut method
         server_attribute=params[0]
@@ -347,7 +348,7 @@
 
     # check for empty results (not allowed for XMLRPC)
     if (result==None) or (result==[None]):
-      GDebug.printMesg(3,'Transform result None into 1')
+      gDebug (3, 'Transform result None into 1')
       result=1
 
     return result
@@ -360,9 +361,8 @@
     for i in self.directory.keys():
       if i[0:tl]==type:
         method="["+objhandle+"]"+i[tl:]
-        GDebug.printMesg(1,'Method %s registered to py-xmlrpc ' \
-                         % method +\
-                         ' internal directory.')
+        gDebug (1, 'Method %s registered to py-xmlrpc internal directory.' \
+                   % method)
  #       self.server.addMethods({method:None})
      
     # add a method to close this object
@@ -378,7 +378,7 @@
     for i in self.directory.keys():
       if i[0:tl]==type:
         method="["+objhandle+"]"+i[tl:]
-        GDebug.printMesg(1,'Method %s is deleted from py-xmlrpc ' \
+        gDebug (1, 'Method %s is deleted from py-xmlrpc ' \
                          % method +\
                          ' internal directory.')
 #        self.server.removeMethods({method:None})
@@ -403,7 +403,7 @@
 class RequestHandler(BaseHTTPRequestHandler):
 
   def log_message (self, format, *args):
-    GDebug.printMesg (1, "%s - - [%s] %s" % \
+    gDebug (1, "%s - - [%s] %s" % \
         (self.address_string(), self.log_date_time_string(), format%args))
 
   # override basic handle to test allowed host condition
@@ -449,9 +449,8 @@
         
     except:
       # internal error, report as HTTP server error
-      GDebug.printMesg(1,
-                       'Unexpected Exception in XML-RPC code: %s:%s' % \
-                       (sys.exc_type, sys.exc_value))
+      gDebug (1, 'Unexpected Exception in XML-RPC code: %s:%s' % \
+                 (sys.exc_type, sys.exc_value))
       # TODO: try to be a bit more informative (on client side)
       self.send_response(500)
       self.end_headers()

Modified: trunk/gnue-common/src/rpc/server.py
===================================================================
--- trunk/gnue-common/src/rpc/server.py 2004-08-25 09:11:19 UTC (rev 6202)
+++ trunk/gnue-common/src/rpc/server.py 2004-08-25 12:30:12 UTC (rev 6203)
@@ -25,7 +25,7 @@
 
 import string
 
-from gnue.common.apps import GDebug, plugin
+from gnue.common.apps import GExceptions, plugin
 from gnue.common.utils.FileUtils import openResource
 
 # =============================================================================
@@ -114,7 +114,7 @@
 # The requested adapter does not exist...
 # -----------------------------------------------------------------------------
 
-class InvalidAdapter (Error):
+class InvalidAdapter (GExceptions.AdminError):
   pass
 
 # -----------------------------------------------------------------------------
@@ -122,7 +122,7 @@
 # supplied parameters do not point to a valid server, etc.
 # -----------------------------------------------------------------------------
 
-class AdapterInitializationError (Error):
+class AdapterInitializationError (GExceptions.AdminError):
   pass
 
 # -----------------------------------------------------------------------------
@@ -138,7 +138,7 @@
 # Parent for all caller errors
 # -----------------------------------------------------------------------------
 
-class ProgrammingError (Error):
+class ProgrammingError (GExceptions.SystemError):
   pass
 
 # -----------------------------------------------------------------------------
@@ -148,6 +148,7 @@
 class InvalidParameter (ProgrammingError):
   pass
 
+
 # =============================================================================
 # Self test code
 # =============================================================================





reply via email to

[Prev in Thread] Current Thread [Next in Thread]