Update of /cvsroot/pywin32/pywin32/isapi/samples
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv25911/samples
Modified Files:
redirector.py
Log Message:
make one of the isapi samples py3k-friendly
Index: redirector.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/isapi/samples/redirector.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** redirector.py 1 Jan 2009 22:38:46 -0000 1.4
--- redirector.py 3 Feb 2009 00:52:28 -0000 1.5
***************
*** 20,24 ****
import sys
import traceback
! import urllib
import win32api
--- 20,28 ----
import sys
import traceback
! try:
! from urllib import urlopen
! except ImportError:
! # py3k spelling...
! from urllib.request import urlopen
import win32api
***************
*** 52,62 ****
# That is perfect for this sample, so we don't catch our own.
#print 'IIS dispatching "%s"' % (ecb.GetServerVariable("URL"),)
! url = ecb.GetServerVariable("URL")
! if ecb.Version < 0x60000:
! print "IIS5 or earlier - can't do 'excludes'"
! else:
! for exclude in excludes:
! if url.lower().startswith(exclude):
! print "excluding %s" % url
ecb.IOCompletion(io_callback, url)
ecb.ExecURL(None, None, None, None, None, isapicon.HSE_EXEC_URL_IGNORE_CURRENT_INTERCEPTOR)
--- 56,66 ----
# That is perfect for this sample, so we don't catch our own.
#print 'IIS dispatching "%s"' % (ecb.GetServerVariable("URL"),)
! url = ecb.GetServerVariable("URL").decode("ascii")
! for exclude in excludes:
! if url.lower().startswith(exclude):
! print "excluding %s" % url
! if ecb.Version < 0x60000:
! print "(but this is IIS5 or earlier - can't do 'excludes')"
! else:
ecb.IOCompletion(io_callback, url)
ecb.ExecURL(None, None, None, None, None, isapicon.HSE_EXEC_URL_IGNORE_CURRENT_INTERCEPTOR)
***************
*** 65,74 ****
new_url = proxy + url
print "Opening %s" % new_url
! fp = urllib.urlopen(new_url)
headers = fp.info()
! ecb.SendResponseHeaders("200 OK", str(headers) + "\r\n", False)
ecb.WriteClient(fp.read())
ecb.DoneWithSession()
! print "Returned data from '%s'!" % (new_url,)
return isapicon.HSE_STATUS_SUCCESS
--- 69,87 ----
new_url = proxy + url
print "Opening %s" % new_url
! fp = urlopen(new_url)
headers = fp.info()
! # subtle py3k breakage: in py3k, str(headers) has normalized \r\n
! # back to \n and also stuck an extra \n term. py2k leaves the
! # \r\n from the server in tact and finishes with a single term.
! if sys.version_info < (3,0):
! header_text = str(headers) + "\r\n"
! else:
! # take *all* trailing \n off, replace remaining with
! # \r\n, then add the 2 trailing \r\n.
! header_text = str(headers).rstrip('\n').replace('\n', '\r\n') + '\r\n\r\n'
! ecb.SendResponseHeaders("200 OK", header_text, False)
ecb.WriteClient(fp.read())
ecb.DoneWithSession()
! print "Returned data from '%s'" % (new_url,)
return isapicon.HSE_STATUS_SUCCESS
|