def errTraceback(self): res = '<b>uncaught exception while running %s</b><br>\n'\ % self.eng.request.pathInfo res+= '<pre class="traceback">\n' \ + htmlEncode(self.eng.error) + "</pre>\n" res += "<b>script input:</b>\n" res += '<ul>\n' res += '<li>form: %s</li>\n' % self.eng.request.form res += '<li>querystring: %s</li>\n' % self.eng.request.query.string res += '<li>cookie: %s</li>\n' % self.eng.request.cookie res += '</ul>\n' if self.eng.globals.has_key("SESS"): res += '<b>session data:</b><br>\n' res += '<ul>\n' for item in self.eng.globals["SESS"].keys(): res += '<li>%s: ' % item try: res += self.eng.globals["SESS"][item] except: res += '(can\'t unpickle)' res += '</li>\n' res += '</ul>\n' res += "<b>script output:</b>\n" res+= '<pre class="output">\n' + \ htmlEncode(self.eng.response.getHeaders()) + \ htmlEncode(self.eng.response.buffer) + \ "</pre>\n" return res
def _getHidden(self): """ This function builds a string containing hidden form fields. This is because the session could expire while someone is working on a form. If they post the form, they should get a login-box, but we want to remember their data while they're logging back in! """ res = "" for item in self._sess._request.form.keys(): # form should be an IdxDict.. if item[:5] == "auth_": pass # Ignore auth stuff here, too else: # value should either be a string or a tuple # of strings. (for multi-select boxes or whatever) if type(self._sess._request[item]) == type(()): # for tuples, loop through all the values: for subitem in self._sess._request[item]: res = res + '<input type="hidden" name="' + \ weblib.htmlEncode(item) + '" value="' + \ weblib.htmlEncode(subitem) + \ '">\n' elif item != 'weblib.Sess': #@TODO: is this right? # only one value: res += '<input type="hidden" name="' res += weblib.htmlEncode(item) + '" value="' res += weblib.htmlEncode(str(self._sess._request[item])) res += '">\n' else: pass return res
def errTraceback(self): res = '<b>uncaught exception while running %s</b><br>\n'\ % self.eng.request.pathInfo res+= '<pre class="traceback">\n' \ + htmlEncode(self.eng.error) + "</pre>\n" res+= "<b>script input:</b>\n" res+= '<ul>\n' res+= '<li>form: %s</li>\n' % self.eng.request.form res+= '<li>querystring: %s</li>\n' % self.eng.request.query.string res+= '<li>cookie: %s</li>\n' % self.eng.request.cookie res+= '</ul>\n' if self.eng.globals.has_key("SESS"): res+= '<b>session data:</b><br>\n' res+= '<ul>\n' for item in self.eng.globals["SESS"].keys(): res+= '<li>%s: ' % item try: res+= self.eng.globals["SESS"][item] except: res+= '(can\'t unpickle)' res+= '</li>\n' res+= '</ul>\n' res+= "<b>script output:</b>\n" res+= '<pre class="output">\n' + \ htmlEncode(self.eng.response.getHeaders()) + \ htmlEncode(self.eng.response.buffer) + \ "</pre>\n" return res
print '<option%s>%s</option>' % (("", " SELECTED")[tpl == which], tpl) print '</select>' print '<input type="submit" value="go">' print '</form>' if weblib.request.get("action") == "save": contents = weblib.request.get("contents") ## save the template... f = open(tpldir() + "/" + which + ".zb", "wb") # binary more so as not to add extra ^M's on win32 f.write(contents) f.close() elif which: contents = weblib.htmlEncode(open(tpldir() + "/" + which + ".zb").read()) print '<h3>editing %s</h3>' % which print '<form action="templates.py" method="post">' print '<table><tr><td>' print '<textarea cols="70" rows="15" name="contents">%s</textarea>' \ % contents print '</td></tr><tr><td align="right">' print '<input type="hidden" name="which" value="%s">' % which print '<input type="submit" name="action" value="save">' print '</td></tr></table>' print '</form>' zebra.show("dsp_foot")
def handler(req): e=apache.build_cgi_env(req) #req.send_http_header() env = {} for bleh in e.keys(): env[bleh]=e[bleh] #print >> req, bleh, ":", e[bleh], "<br>" #return apache.OK wreq=weblib.Request(content=req.read(), environ=env) eng = ModPythonEngine(request=wreq,script="") eng.start() dir = os.sep.join(req.filename.split(os.sep)[:-1]) + os.sep os.chdir(dir) if os.path.exists(dir + ".weblib.py"): whichfile= dir + ".weblib.py" eng.execute(open(whichfile)) if (eng.result ==eng.SUCCESS) or (eng.result is None): whichfile=req.filename eng.execute(open(whichfile)) eng.stop() if eng.result in (eng.SUCCESS, eng.REDIRECT, eng.EXIT): import string headers = eng.response.getHeaders() for i in string.split(headers, "\n"): if i != "": header = string.split(i, ":") req.headers_out[header[0]] = header[1] if string.lower(header[0]) == 'content-type': req.content_type = header[1] if string.lower(header[0]) == 'status': req.status = int(header[1]) req.send_http_header() req.write(eng.response.buffer) return apache.OK else: ## print debug output print >> req, weblib.trim(""" <html> <head> <title>weblib.cgi exception</title> <style type="text/css"> body, p { background: #cccccc; font-family: verdana, arial; font-size: 75%; } pre { font-size: 120%; } pre.traceback { color: red; } pre.output{ color : green } </style> </head> <body> """) if eng.result == eng.FAILURE: print >> req, "<b>assertion failure:</b>", eng.error print >> req, "</body>\n</html>" elif eng.result == eng.EXCEPTION: ## html error message ################################# print >> req, "<b>uncaught exception while running %s</b><br>" \ % whichfile print >> req, '<pre class="traceback">' \ + weblib.htmlEncode(eng.error) + "</pre>" print >> req, "<b>script input:</b>" print >> req, '<ul>' print >> req, '<li>form: %s</li>' % eng.request.form print >> req, '<li>querystring: %s</li>' % eng.request.querystring print >> req, '<li>cookie: %s</li>' % eng.request.cookie print >> req, '</ul>' print >> req, '<b>session data:</b><br>' print >> req, '<ul>' for item in eng.sess.keys(): print >> req, '<li>', item, ': ' try: print >> req, eng.sess[item] except: print >> req, '(can\'t unpickle)' print >> req, '</li>' print >> req, '</ul>' print >> req, "<b>script output:</b>" print >> req, '<pre class="output">' + \ weblib.htmlEncode(eng.response.getHeaders()) + \ weblib.htmlEncode(eng.response.buffer) + \ "</pre>" print >> req, "<hr>" print >> req, '<a href="http://weblib.sourceforge.net/">weblib</a> ' + \ '(c) copyright 2000-2001 ' + \ '<a href="http://www.zike.net/">Zike Interactive</a>. ' + \ 'All rights reserved.' print >> req, "</body>" print >> req, "</html>" return apache.OK
print '<input type="submit" value="go">' print '</form>' if weblib.request.get("action") == "save": contents = weblib.request.get("contents") ## save the template... f = open(tpldir() + "/" + which + ".zb", "wb") # binary more so as not to add extra ^M's on win32 f.write(contents) f.close() elif which: contents = weblib.htmlEncode( open(tpldir() + "/" + which + ".zb").read()) print '<h3>editing %s</h3>' % which print '<form action="templates.py" method="post">' print '<table><tr><td>' print '<textarea cols="70" rows="15" name="contents">%s</textarea>' \ % contents print '</td></tr><tr><td align="right">' print '<input type="hidden" name="which" value="%s">' % which print '<input type="submit" name="action" value="save">' print '</td></tr></table>' print '</form>' zebra.show("dsp_foot")
def handler(req): e = apache.build_cgi_env(req) #req.send_http_header() env = {} for bleh in e.keys(): env[bleh] = e[bleh] #print >> req, bleh, ":", e[bleh], "<br>" #return apache.OK wreq = weblib.Request(content=req.read(), environ=env) eng = ModPythonEngine(request=wreq, script="") eng.start() dir = os.sep.join(req.filename.split(os.sep)[:-1]) + os.sep os.chdir(dir) if os.path.exists(dir + ".weblib.py"): whichfile = dir + ".weblib.py" eng.execute(open(whichfile)) if (eng.result == eng.SUCCESS) or (eng.result is None): whichfile = req.filename eng.execute(open(whichfile)) eng.stop() if eng.result in (eng.SUCCESS, eng.REDIRECT, eng.EXIT): import string headers = eng.response.getHeaders() for i in string.split(headers, "\n"): if i != "": header = string.split(i, ":") req.headers_out[header[0]] = header[1] if string.lower(header[0]) == 'content-type': req.content_type = header[1] if string.lower(header[0]) == 'status': req.status = int(header[1]) req.send_http_header() req.write(eng.response.buffer) return apache.OK else: ## print debug output print >> req, weblib.trim(""" <html> <head> <title>weblib.cgi exception</title> <style type="text/css"> body, p { background: #cccccc; font-family: verdana, arial; font-size: 75%; } pre { font-size: 120%; } pre.traceback { color: red; } pre.output{ color : green } </style> </head> <body> """) if eng.result == eng.FAILURE: print >> req, "<b>assertion failure:</b>", eng.error print >> req, "</body>\n</html>" elif eng.result == eng.EXCEPTION: ## html error message ################################# print >> req, "<b>uncaught exception while running %s</b><br>" \ % whichfile print >> req, '<pre class="traceback">' \ + weblib.htmlEncode(eng.error) + "</pre>" print >> req, "<b>script input:</b>" print >> req, '<ul>' print >> req, '<li>form: %s</li>' % eng.request.form print >> req, '<li>querystring: %s</li>' % eng.request.querystring print >> req, '<li>cookie: %s</li>' % eng.request.cookie print >> req, '</ul>' print >> req, '<b>session data:</b><br>' print >> req, '<ul>' for item in eng.sess.keys(): print >> req, '<li>', item, ': ' try: print >> req, eng.sess[item] except: print >> req, '(can\'t unpickle)' print >> req, '</li>' print >> req, '</ul>' print >> req, "<b>script output:</b>" print >> req, '<pre class="output">' + \ weblib.htmlEncode(eng.response.getHeaders()) + \ weblib.htmlEncode(eng.response.buffer) + \ "</pre>" print >> req, "<hr>" print >> req, '<a href="http://weblib.sourceforge.net/">weblib</a> ' + \ '(c) copyright 2000-2001 ' + \ '<a href="http://www.zike.net/">Zike Interactive</a>. ' + \ 'All rights reserved.' print >> req, "</body>" print >> req, "</html>" return apache.OK