Author: chrisz
Date: Sat Apr 21 19:15:25 2007
New Revision: 6495
Modified:
Webware/trunk/COMKit/Examples/ADOSample.py
Webware/trunk/COMKit/__init__.py
Log:
COMKit seems to be the only place where nested scopes are used. Changed this so that Python < 2.2 does not complain about this any more. (We decided to require newer Python versions only after Webware 1.0.) Checked that everything works fine using the ADOSample with ODBC and a PostgreSQL database.
Modified: Webware/trunk/COMKit/Examples/ADOSample.py
==============================================================================
--- Webware/trunk/COMKit/Examples/ADOSample.py (original)
+++ Webware/trunk/COMKit/Examples/ADOSample.py Sat Apr 21 19:15:25 2007
@@ -7,10 +7,9 @@
# AppServer.config file; you'll have to create a database with a table
# called Customers that has a CustomerName field; and you'll
# have to create a System DSN called MyDataSource that points to
-# that database. Then, install this file in the Examples
+# that database. Then, install this file in the WebKit/Examples
# directory and try it out. It ought to work with any database
-# accessible through ODBC and/or ADO, but I've only tested it with
-# SQL Server.
+# accessible through ODBC and/or ADO.
#
# The recordset function below should go into a base class so it
# can be shared among many servlets.
@@ -41,6 +40,10 @@
def writeContent(self):
# Grab some data from the database and display it
rs = self.recordset('SELECT CustomerName FROM Customers ORDER BY CustomerName')
+ self.writeln('<h1>ADO Sample</h1>')
+ self.writeln('<h3>Your Customers are:</h3>')
+ self.writeln('<ul>')
while not rs.EOF:
- self.writeln('<p>%s' % rs.Fields('CustomerName').Value)
+ self.writeln('<li>%s</li>' % rs.Fields('CustomerName').Value)
rs.MoveNext()
+ self.writeln('</ul>')
Modified: Webware/trunk/COMKit/__init__.py
==============================================================================
--- Webware/trunk/COMKit/__init__.py (original)
+++ Webware/trunk/COMKit/__init__.py Sat Apr 21 19:15:25 2007
@@ -8,6 +8,7 @@
To use COM, simply set EnableCOM to 1 in your AppServer.config file.
This causes the app server threads to be configured properly for
COM free-threading. Then go ahead and use win32com inside your servlets.
+
"""
__all__ = []
@@ -25,33 +26,35 @@
# Get the win32 extensions
import pythoncom
+ # Set references to the COM initialize and uninitialize functions
+ appServer._initCOM = pythoncom.COINIT_MULTITHREADED
+ appServer.initCOM = pythoncom.CoInitializeEx
+ appServer.closeCOM = pythoncom.CoUninitialize
+
# Grab references to the original initThread and delThread bound
# methods, which we will replace
- original_initThread = appServer.initThread
- original_delThread = appServer.delThread
+ appServer.originalInitThread = appServer.initThread
+ appServer.originalDelThread = appServer.delThread
# Create new versions of initThread and delThread which will call the
# old versions
- def new_initThread(self):
- # This must be called at the beginning of any thread that uses COM
- pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)
+ def newInitThread(self):
+ # This must be called at the beginning of any thread that uses COM
+ self.initCOM(self._initCOM)
# Call the original initThread
- original_initThread()
+ self.originalInitThread()
- def new_delThread(self):
+ def newDelThread(self):
# Call the original delThread
- original_delThread()
-
+ self.originalDelThread()
# Uninitialize COM
- pythoncom.CoUninitialize()
+ self.closeCOM()
# Replace the initThread and delThread with our new versions, for
# this instance of the appserver only
import new
- appServer.initThread = new.instancemethod(new_initThread, appServer, appServer.__class__)
- appServer.delThread = new.instancemethod(new_delThread, appServer, appServer.__class__)
+ appServer.initThread = new.instancemethod(newInitThread, appServer, appServer.__class__)
+ appServer.delThread = new.instancemethod(newDelThread, appServer, appServer.__class__)
print 'COM has been enabled.'
-
-
|