We need schemas to provide a regression testing pool: if you're
willing for a copy of your input to be logged and copied offline,
please give us permission to do so.
report problems (and sucesses!) to xmlschema-dev (archive)
Schema validator by Henry S. Thompson and Richard Tobin.
Web interface by Dan Connolly
script $Revision: 1.16 $ of $Date: 2000/06/20 15:47:56 $
""" # '
sys.path.append("/export/home/ht/lib/xmlschema")
import applyschema
from PyXML import error
def serveRequest():
tempfile.tempdir="/export/home/ht/xsvlog"
logFile=None
fields = cgi.FieldStorage()
if not (fields.has_key('docAddrs') or fields.has_key('docFile')):
print "Content-Type: text/html"
print
print Page
else:
timeString=time.asctime(time.gmtime(time.time()))
ss=None
stemplate='../style/%s'
style = fields['style'].value
if style=='text':
mime='text/plain'
elif style=='offline':
mime='text/html'
else:
mime='text/xml'
if style=='msxsl':
ss=stemplate%'xsv.msxsl'
else:
ss=stemplate%'xsv.xsl'
if fields.has_key('docFile'):
data = fields['docFile'].file.read()
# print "writing %d bytes of uploaded data ..." \
# %(len(data), )
uploadTmp = tempfile.mktemp("uploaded") #@@hmm... when to delete these?
# print "... to %s" % (uploadTmp,)
fp = open(uploadTmp, "w")
fp.write(data)
fp.close()
target = 'file:' + uploadTmp
args = [target,]
schemas = [] #@@hmm... allow both upload and schemas?
else:
addrs = fields['docAddrs'].value
if "'" in addrs:
print """Content-Type: text/plain
sorry, I can't handle addresses with ' in them"""
return
args=string.split(addrs)
for fn in args:
if not urlparse.urlparse(fn)[0]:
print """Content-Type: text/plain
sorry, I can't handle relative addresses: %s"""%fn
return
target=args[0]
schemas=args[1:]
if fields.has_key('keepGoing'):
keep='on'
else:
keep='off'
if fields.has_key('logOK'):
logFile=tempfile.mktemp()
log = open(logFile,"a+")
log.write("\n"%
(timeString,
args,keep,applyschema.vs))
log.close()
print "Content-Type: %s"%mime
print
sys.stdout.flush()
if style=='offline':
outFile=tempfile.mktemp("xsvout")
outf=open(outFile,"w+")
sys.stderr.flush()
savestderr=os.dup(2) # save stderr
os.dup2(outf.fileno(),2) # capture all output
else:
os.dup2(1, 2) # send stderr to stdout
sys.stdout.flush()
try:
applyschema.runitAndShow(target,schemas,keep=='on',ss)
except error:
# IO Error in PyXML
pass
except:
if style=='offline':
os.dup2(savestderr,2) # put it back
print 'XSV Crash
'
print "Schema validator crashed:"
print '-'*60
traceback.print_exc(file=sys.stdout)
print '-'*60
print """The maintainers of XSV will be notified, you don't need to
send mail about this unless you have extra information to provide.
If there are Schema errors reported before the crash, try correcting
them and re-running the validation."""
if style=='offline':
print '
'
if not logFile:
logFile=tempfile.mktemp()
log = open(logFile,"a+")
log.write(""%
(time.asctime(time.gmtime(time.time())),
args,keep,applyschema.vs))
log.write("\n")
log.write("\n")
log.close()
return
if style=='offline':
sys.stderr.flush()
os.dup2(savestderr,2) # put it back
outf.close()
os.system("/export/home/ht/bin/doxt %s /usr/local/Jigsaw/Jigsaw/WWW/style/xsv.xsl"%outFile)
if __name__ == '__main__':
#sys.stderr = open("/tmp/cgi-write/xmlschema-log", "w+")
#sys.stderr.write(str(os.environ))
if os.environ.has_key('SCRIPT_NAME'):
try:
serveRequest()
except:
print "Content-Type: text/plain"
print
traceback.print_exc(file=sys.stdout)