Author: chrisz
Date: Sun Nov 26 01:19:50 2006
New Revision: 5935
Modified:
Webware/trunk/WebKit/Adapters/Adapter.py
Webware/trunk/WebKit/Adapters/FCGIAdapter.py
Webware/trunk/WebKit/Adapters/HTTPAdapter.py
Webware/trunk/WebKit/Adapters/LRWPAdapter.py
Webware/trunk/WebKit/Adapters/OneShot.cgi
Log:
Some more adapter cleanup.
Modified: Webware/trunk/WebKit/Adapters/Adapter.py
==============================================================================
--- Webware/trunk/WebKit/Adapters/Adapter.py (original)
+++ Webware/trunk/WebKit/Adapters/Adapter.py Sun Nov 26 01:19:50 2006
@@ -4,6 +4,7 @@
from MiscUtils.Configurable import Configurable
import struct
+
class Adapter(Configurable, Object):
def __init__(self, webKitDir):
Modified: Webware/trunk/WebKit/Adapters/FCGIAdapter.py
==============================================================================
--- Webware/trunk/WebKit/Adapters/FCGIAdapter.py (original)
+++ Webware/trunk/WebKit/Adapters/FCGIAdapter.py Sun Nov 26 01:19:50 2006
@@ -25,8 +25,8 @@
For Apache, you'll need to add the following lines to your httpd.conf file, or
put them in another file and include that file in httpd.conf
-#I have the file in my cgi-bin directory, but you might as well put it in html.
-#the -host is the port it communicates on
+# I have the file in my cgi-bin directory, but you might as well put it in html.
+# the -host is the port it communicates on
FastCgiExternalServer ../cgi-bin/FCGIWebKit.py -host localhost:33333 # the path is from the SERVER ROOT
<Location /FCGIWebKit.py> #or whatever name you chose for the file above
@@ -77,58 +77,19 @@
"""
-# Set WebKitDir to the directory where WebKit is located
-WebKitDir = '/usr/local/Webware/WebKit'
+# If the Webware installation is located somewhere else,
+# then set the webwareDir variable to point to it here:
+webwareDir = None
-import fcgi, time
-from marshal import dumps, loads
-from socket import *
-import os
-import sys
-
-timestamp = time.time()
-
-_AddressFile='address.text'
-
-HTMLCodes = [
- ['&', '&'],
- ['<', '<'],
- ['>', '>'],
- ['"', '"'],
-]
-
-def HTMLEncode(s, codes=HTMLCodes):
- """Return the HTML encoded version of the given string.
-
- This is useful to display a plain ASCII text string on a web page.
- (We could get this from WebUtils, but we're keeping CGIAdapter
- independent of everything but standard Python.)
-
- """
- for code in codes:
- s = s.replace(code[0], code[1])
- return s
-
-if os.name != 'posix':
- print "This adapter is only available on UNIX"
- sys.exit(1)
-
-fcgi._startup()
-if not fcgi.isFCGI():
- print "No FCGI Environment Available"
- print "This module cannot be run from the command line"
- sys.exit(1)
-
-addrfile=os.path.join(WebKitDir, _AddressFile)
-(host, port) = open(addrfile).read().split(':')
-port = int(port)
-
-os.chdir(WebKitDir)
-sys.path.append(os.path.abspath(os.path.join(WebKitDir, "..")))
+import sys, os, time
+from socket import *
+import fcgi
from Adapter import Adapter
+
class FCGIAdapter(Adapter):
+
def run(self):
"""Block waiting for new request."""
while fcgi.isFCGI():
@@ -137,18 +98,14 @@
def FCGICallback(self,req):
"""This function is called whenever a request comes in."""
- import sys
-
try:
# Transact with the app server
response = self.transactWithAppServer(req.env, req.inp.read(), host, port)
-
# deliver it!
req.out.write(response)
req.out.flush()
except:
import traceback
-
# Log the problem to stderr
stderr = req.err
stderr.write('[%s] [error] WebKit.FCGIAdapter:'
@@ -156,33 +113,67 @@
% (time.asctime(time.localtime(time.time()))))
stderr.write('Python exception:\n')
traceback.print_exc(file=stderr)
-
# Report the problem to the browser
- output = apply(traceback.format_exception, sys.exc_info())
- output = ''.join(output)
+ output = ''.join(traceback.format_exception(*sys.exc_info()))
output = HTMLEncode(output)
- self.pr('''Content-type: text/html
-
-<html><body>
-<p><pre>ERROR
-
-%s</pre>
+ sys.pr('''Content-type: text/html\n
+<html><head><title>WebKit CGI Error</title><body>
+<h3>WebKit CGI Error</h3>
+%s
</body></html>\n''' % output)
req.Finish()
return
- #easy print function
- def pr(self,*args):
+ def pr(self, *args):
"""Just a quick and easy print function."""
try:
req=self.req
- s=''
- for i in args: s=s+str(i)
- req.out.write(s+'\n')
+ req.out.write(''.join(map(str, args)) + '\n')
req.out.flush()
except:
pass
-#print "Starting"
-fcgiloop = FCGIAdapter(WebKitDir)
+
+HTMLCodes = [
+ ['&', '&'],
+ ['<', '<'],
+ ['>', '>'],
+ ['"', '"'],
+]
+
+def HTMLEncode(s, codes=HTMLCodes):
+ """Return the HTML encoded version of the given string.
+
+ This is useful to display a plain ASCII text string on a web page.
+ (We could get this from WebUtils, but we're keeping CGIAdapter
+ independent of everything but standard Python.)
+
+ """
+ for code in codes:
+ s = s.replace(code[0], code[1])
+ return s
+
+
+# Start FCGI Adapter
+
+if os.name != 'posix':
+ print "This adapter is only available on UNIX"
+ sys.exit(1)
+
+fcgi._startup()
+if not fcgi.isFCGI():
+ print "No FCGI Environment Available"
+ print "This module cannot be run from the command line"
+ sys.exit(1)
+
+if not webwareDir:
+ webwareDir = os.path.dirname(os.path.dirname(os.getcwd()))
+sys.path.insert(1, webwareDir)
+webKitDir = os.path.join(webwareDir, 'WebKit')
+os.chdir(webKitDir)
+
+host, port = open(os.path.join(webKitDir, 'address.text')).read().split(':', 1)
+port = int(port)
+
+fcgiloop = FCGIAdapter(webKitDir)
fcgiloop.run()
Modified: Webware/trunk/WebKit/Adapters/HTTPAdapter.py
==============================================================================
--- Webware/trunk/WebKit/Adapters/HTTPAdapter.py (original)
+++ Webware/trunk/WebKit/Adapters/HTTPAdapter.py Sun Nov 26 01:19:50 2006
@@ -1,41 +1,41 @@
#!/usr/bin/env python
-# If the Webware installation is located somewhere else,
-# then set the WebwareDir variable to point to it.
-# For example, WebwareDir = '/Servers/Webware'
-WebwareDir = None
# If you used the MakeAppWorkDir.py script to make a separate
-# application working directory, specify it here.
-AppWorkDir = None
+# application working directory, specify it here:
+workDir = None
+
+# If the Webware installation is located somewhere else,
+# then set the webwareDir variable to point to it here:
+webwareDir = None
+
+
+import sys, os
+import BaseHTTPServer, threading, socket
## Path setup ##
try:
- import os, sys
- if not WebwareDir:
- WebwareDir = os.path.dirname(os.path.dirname(os.getcwd()))
- sys.path.insert(0, WebwareDir)
- webKitDir = os.path.join(WebwareDir, 'WebKit')
- if AppWorkDir is None:
- AppWorkDir = webKitDir
+ if not webwareDir:
+ webwareDir = os.path.dirname(os.path.dirname(os.getcwd()))
+ sys.path.insert(0, webwareDir)
+ webKitDir = os.path.join(webwareDir, 'WebKit')
+ if workDir is None:
+ workDir = webKitDir
else:
- sys.path.insert(0, AppWorkDir)
-
+ sys.path.insert(0, workDir)
from WebKit.Adapters.Adapter import Adapter
- (host, port) = open(os.path.join(webKitDir, 'address.text')).read().split(':')
- if os.name=='nt' and host=='':
+ host, port = open(os.path.join(webKitDir, 'address.text')).read().split(':')
+ if os.name == 'nt' and host == '':
# MS Windows doesn't like a blank host name
host = 'localhost'
port = int(port)
-except 0:
+except:
# @@: Is there something we should do with exceptions here?
# I'm apt to just let them print to stderr and quit like normal,
# but I'm not sure.
pass
-import BaseHTTPServer, threading, socket
-
## HTTP Server ##
@@ -69,7 +69,7 @@
except socket.error:
return
t = threading.Thread(target=self.handle_request_body,
- args=(request, client_address, self._threadID))
+ args=(request, client_address, self._threadID))
t.start()
self._threads[self._threadID] = t
self._threadID += 1
@@ -118,8 +118,8 @@
def main():
import getopt
try:
- opts, args = getopt.getopt(sys.argv[1:], 'p:h:d',
- ['port=', 'host=', 'daemon'])
+ opts, args = getopt.getopt(sys.argv[1:],
+ 'p:h:d', ['port=', 'host=', 'daemon'])
except getopt.GetoptError:
print usage
sys.exit(2)
@@ -140,10 +140,8 @@
run((host, port))
def shutDown(arg1, arg2):
- """
- We have to have a shutdown handler, because ThreadedAppServer
- installs one that we have to overwrite.
- """
+ # We have to have a shutdown handler, because ThreadedAppServer
+ # installs one that we have to overwrite.
import sys
print 'Shutting down.'
sys.exit()
Modified: Webware/trunk/WebKit/Adapters/LRWPAdapter.py
==============================================================================
--- Webware/trunk/WebKit/Adapters/LRWPAdapter.py (original)
+++ Webware/trunk/WebKit/Adapters/LRWPAdapter.py Sun Nov 26 01:19:50 2006
@@ -13,7 +13,7 @@
# Set Program Parameters
-webKitDir = None
+webwareDir = None
LRWPappName = 'testing'
@@ -24,14 +24,14 @@
#-----------------------------------------------------------------------------
import os, sys
+from lrwplib import LRWP
+from Adapter import Adapter
-if webKitDir is None:
- webKitDir = os.path.dirname(os.getcwd())
-webwareDir = os.path.dirname(webKitDir)
-sys.path.insert(1, webwareDir)
-from Adapter import Adapter
-from lrwplib import LRWP
+if not webwareDir:
+ webwareDir = os.path.dirname(os.path.dirname(os.getcwd()))
+sys.path.insert(1, webwareDir)
+webKitDir = os.path.join(webwareDir, 'WebKit')
class LRWPAdapter(Adapter):
Modified: Webware/trunk/WebKit/Adapters/OneShot.cgi
==============================================================================
--- Webware/trunk/WebKit/Adapters/OneShot.cgi (original)
+++ Webware/trunk/WebKit/Adapters/OneShot.cgi Sun Nov 26 01:19:50 2006
@@ -2,7 +2,7 @@
# If the Webware installation is located somewhere else,
# then set the webwareDir variable to point to it here:
-WebwareDir = None
+webwareDir = None
# If you used the MakeAppWorkDir.py script to make a separate
# application working directory, specify it here:
@@ -10,10 +10,10 @@
try:
import os, sys
- if not WebwareDir:
- WebwareDir = os.path.dirname(os.path.dirname(os.getcwd()))
- sys.path.insert(1, WebwareDir)
- webKitDir = os.path.join(WebwareDir, 'WebKit')
+ if not webwareDir:
+ webwareDir = os.path.dirname(os.path.dirname(os.getcwd()))
+ sys.path.insert(1, webwareDir)
+ webKitDir = os.path.join(webwareDir, 'WebKit')
if workDir is None:
workDir = webKitDir
else:
|