[Pythonmac-SIG] Re: PythonCGISlave update

Noboru Yamamoto noboru.yamamoto@kek.jp
Sat, 01 Apr 2000 09:00:57 +0900


This is a multi-part message in MIME format.
--------------CA10A109DB2D26C11AC6F3DD
Content-Type: text/plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit

Hi, 

Just van Rossum wrote:
> 
> At 10:37 PM +0900 28-03-2000, Noboru Yamamoto wrote:
> >Thanks for a PythonCGIServer.py program. That is a program I wanted for
> >a while.
> >I added a little enhancement to the program. It now can send back data
> >longer than
> >32 KB to WebStar server. It uses  a <SEND_PARTIAL> mechanism to send
> >back data to the WWW server.
> 
> Very cool! Thanks.
> 
> >I have tested it with WebStar 4.0(demo version) and it should work with
> >WebStar 3.x.
> 
> I would like to incorporate the enhancements into PythonCGISlave, but I
> wonder: do other web servers support the same mechanism? In other words,
> can we turn this into something independant from WebStar? As it is now it
> would blow up if the CGI would try send >32k of data under *any* other
> server, since it explicitly start an AE connection with WebStar. I think
> the incoming AE contains info about the web server, so I think we should
> try and use that.

Enclosed is a  PythonCGISlave_WebStar.py which defines
PythonCGISlave_WebStar class. PythonCGISlave_WebStar class is a
decendent of PythonCGISlave class defined in PythonCGISlav.py.
PythonCGISlave_WebStar class can send back longer 32KB responce to
a WebStar.

It requires modules,WebSTAR_Suite,  Miscellaneous_Standards , and W_2a_API_Suite.
You can obtain these module applying  gensuitemodule.py  to WebStar
program. 

You also needs to add "if __name__  == '__main__':" clause in PythonCGISlave.py
so that a import statemnet in PythonCGISlave_WebStar.py will not start
PythonCGISlave 
class.

> 
> I've appended my latest working copy, which besides PythonCGISlave now also
> contains BuildCGIApplet, which does what I've described earlier: it
> converts a CGI script to an applet, but wrapped in PythonCGISlave's
> compatibility layer.
> 
> Just
> 

Noboru
--------------CA10A109DB2D26C11AC6F3DD
Content-Type: text/plain; charset=iso-2022-jp; x-mac-type="54455854"; x-mac-creator="4D4F5353";
 name="PythonCGISlave_WebStar.py"
Content-Transfer-Encoding: 8bit
Content-Description: Unknown ドキュメント
Content-Disposition: inline;
 filename="PythonCGISlave_WebStar.py"

"""PythonCGISlave.py -- Python script server enabling Python CGI under WebStar.
#
# Written by Just van Rossum, but largely stolen from example code by Jack.
#
Modification by N. Yamamoto	support loger(>32K) data sending back to WebSter
"""
import PythonCGISlave

import MacOS
MacOS.SchedParams(0, 0)

import WebSTAR_Suite, Standard_Suite, Required_Suite, Miscellaneous_Standards
import aetools, W_2a_API_Suite
from aetools import *
import aetypes

class WebStar(WebSTAR_Suite.WebSTAR_Suite, Required_Suite.Required_Suite, \
				Standard_Suite.Standard_Suite, W_2a_API_Suite.W_2a_API_Suite,
				aetools.TalkTo):
	pass
	
SIGNATURE="WWW$B%9(B"
SEND_PARTIAL = "<SEND_PARTIAL>"
RECL=16*1024

class PythonCGISlave_WebStar(PythonCGISlave.PythonCGISlave):

	def Push(self, kcid, buffer, **args):
		while buffer:
			_talker=WebStar(SIGNATURE, start=1)
			data, buffer=buffer[:RECL], buffer[RECL:]
			if len(buffer)>0:
				more=aetypes.Boolean(1)
			else:
				more=aetypes.Boolean(0)
			try:
				_talker.send_partial(data, more=more, connection=kcid)
			except:
				print "Error!", buffer
				pass

	def cgihandler(self, pathargs, **args):
 		rv = apply(PythonCGISlave.PythonCGISlave.cgihandler, (self,pathargs), args)
		if len(rv) < RECL:		
			if not self.long_running:
				# quit after each request
				self.quitting = 1
			return rv
		else:
			self.quitting=0
			self.Push(args["Kcid"], rv)  
			if not self.long_running:
				# quit after each request
				self.quitting = 1
			return SEND_PARTIAL

PythonCGISlave_WebStar()

--------------CA10A109DB2D26C11AC6F3DD--