[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
r6145 - in trunk/gnue-common/src/datasources: . drivers/appserver/appser
From: |
johannes |
Subject: |
r6145 - in trunk/gnue-common/src/datasources: . drivers/appserver/appserver |
Date: |
Thu, 5 Aug 2004 07:17:01 -0500 (CDT) |
Author: johannes
Date: 2004-08-05 07:17:00 -0500 (Thu, 05 Aug 2004)
New Revision: 6145
Modified:
trunk/gnue-common/src/datasources/GDataSource.py
trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
Log:
Added method to load appserver resources
Modified: trunk/gnue-common/src/datasources/GDataSource.py
===================================================================
--- trunk/gnue-common/src/datasources/GDataSource.py 2004-08-05 12:00:31 UTC
(rev 6144)
+++ trunk/gnue-common/src/datasources/GDataSource.py 2004-08-05 12:17:00 UTC
(rev 6145)
@@ -33,7 +33,7 @@
from gnue.common.apps import GDebug
from gnue.common.datasources import GDataObjects
from gnue.common.definitions import GObjects
-import sys, string, types
+import sys, string, types, cStringIO
from gnue.common.datasources import GConnections
from gnue.common.formatting import GTypecast
from gnue.common.datasources import GConditions, Exceptions
@@ -640,3 +640,78 @@
def getSchemaCreator (self):
return self._dataObject._connection.schemaCreator
+
+
+# =============================================================================
+# Load AppServer specific resources
+# =============================================================================
+
+class AppServerResourceError (Exceptions.Error):
+ pass
+
+class InvalidURLError (AppServerResourceError):
+ def __init__ (self, url):
+ msg = u_("The URL '%s' is not a valid application server resource "
+ "locator") % url
+ AppServerResourceError.__init__ (self, msg)
+
+class InvalidResourceTypeError (AppServerResourceError):
+ def __init__ (self, resourceType):
+ msg = u_("Resource type '%s' is not supported") % resourceType
+ AppServerResourceError.__init__ (self, msg)
+
+class ResourceNotFoundError (AppServerResourceError):
+ def __init__ (self, resType, resName):
+ msg = u_("Resource '%(name)s' of type '%(type)s' not found") \
+ % {'type': resType,
+ 'name': resName}
+ AppServerResourceError.__init__ (self, msg)
+
+# -----------------------------------------------------------------------------
+# Load a resource from appserver and return it as a file-like object
+# -----------------------------------------------------------------------------
+
+def getAppserverResource (url, paramDict, connections):
+ if url [:12].lower () != 'appserver://':
+ raise InvalidURLError, url
+
+ parts = url [12:].split ('/')
+ if len (parts) != 3:
+ raise InvalidURLError, url
+ (connection, element, elementName) = parts [:3]
+
+ if not len (connection) or not len (element) or not len (elementName):
+ raise InvalidURLError, url
+
+ if not element in ['form']:
+ raise InvalidResourceTypeError, element
+
+ attrs = {'name' : 'dtsClass',
+ 'database': connection,
+ 'table' : 'gnue_class'}
+ fieldList = ['gnue_id', 'gnue_name', 'gnue_module']
+
+ dts = DataSourceWrapper (
+ connections = connections,
+ attributes = attrs,
+ fields = fieldList,
+ unicodeMode = True)
+
+ parts = elementName.split ('_')
+ if len (parts) != 2:
+ raise ResourceNotFoundError, (element, elementName)
+
+ (moduleName, className) = parts
+ mc = GConditions.buildConditionFromDict ({'gnue_name': className,
+ 'gnue_module.gnue_name': moduleName})
+
+ rs = dts.createResultSet (mc)
+ if rs.firstRecord ():
+ paramDict ['connection'] = connection
+ res = rs.current.callFunc ("gnue_%s" % element, paramDict)
+
+ return cStringIO.StringIO (res.encode ('utf-8'))
+
+ else:
+ raise ResourceNotFoundError, (element, elementName)
+
Modified:
trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
2004-08-05 12:00:31 UTC (rev 6144)
+++ trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
2004-08-05 12:17:00 UTC (rev 6145)
@@ -78,6 +78,7 @@
try:
self._sess_id = self._sm.open ({'user': user, 'password': passwd})
+
except client.DistantError, e:
if e.type == 'AuthError':
raise Exceptions.LoginError, e.message
@@ -86,7 +87,7 @@
except gException, e:
raise Exceptions.ConnectError, e.message # handle unicode message
except:
- raise Exceptions.ConnectError, str (sys.exc_info () [1])
+ raise Exceptions.ConnectError, "%s" % sys.exc_info () [1]
# Can be removed after the call to _dataConnection.cursor() is removed from
# the Base driver
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- r6145 - in trunk/gnue-common/src/datasources: . drivers/appserver/appserver,
johannes <=