34 request[
'status'] = str(status)
40 def __init__(self, context, pagename=None,readDefaultHDF=1,israwpage=0,
41 parseCGI=1, makePUT=0, **parms):
42 if pagename
is None: pagename = self.
_pagename 43 if not pagename:
raise NoPageName(
"missing pagename")
55 context.environ[
'REQUEST_METHOD'] =
'PUT' 57 neo_cgi.cgiWrap(context.stdin, context.stdout, context.environ)
58 neo_cgi.IgnoreEmptyFormVars(1)
65 domain = self.ncgi.hdf.getValue(
"CGI.ServerName",
"")
66 domain = self.ncgi.hdf.getValue(
"HTTP.Host", domain)
69 self.
setPaths([self.ncgi.hdf.getValue(
"CGI.DocumentRoot",
"")])
75 if self.ncgi.hdf.getValue(
"CGI.HTTPS",
""):
87 handle_error.handleException(
"Display Failed!")
88 ERROR_MESSAGE = handle_error.exceptionString()
93 self.ncgi.hdf.setValue(
"cgiout.other.%s" % key,
"%s: %s" % (key, value))
99 return self._reply_headers.has_key(string.lower(key))
105 self.ncgi.hdf.removeTree(
"hdf.loadpaths")
109 self.ncgi.hdf.setValue(
"hdf.loadpaths.%d" % self.
_path_num, path)
114 if ncgi.hdf.getIntValue(
"Cookie.debug",0) == 1:
115 ncgi.hdf.setValue(
"CGI.REDIRECT_TO",redirectTo)
118 cs = neo_cs.CS(ncgi.hdf)
119 self[
'Content-Type'] =
"text/html" 123 <a href="<?cs var:CGI.REDIRECT_TO ?>"><?cs var:CGI.REDIRECT_TO ?></a> 125 cs.parseStr(template)
131 self.
push(neo_cgi.htmlEscape(ncgi.hdf.dump()) +
"\n")
132 self.
push(
"</PRE>\n")
135 self.context.setStatus(self, 302)
136 self.ncgi.redirectUri(redirectTo)
137 raise Redirected(
"redirected To: %s" % redirectTo)
146 raise NoDisplayMethod(
"no display method present in %s" % repr(self))
152 if method.im_func.func_code.co_argcount == 2:
168 hdfobj = hdf.getObj(
"Query.Action")
170 firstchild = hdfobj.child()
172 action = firstchild.name()
173 if firstchild.next():
176 method_name =
"Action_%s" % action
177 method = getattr(self,method_name)
178 if method.im_func.func_code.co_argcount == 2:
193 ncgi.hdf.readFile(
"%s.hdf" % self.
pagename)
207 except DisplayError, num:
208 ncgi.hdf.setValue(
"Query.error", str(num))
218 handle_error.handleException(
"Display Failed!")
219 ERROR_MESSAGE = handle_error.exceptionString()
226 self[
'Content-Type'] =
"text/html" 231 <script type="text/javascript"> 232 function toggleDebugInfo() { 233 var tb = document.getElementById('%s'); 234 if (tb == null) return; 235 tb.style.display = tb.style.display ? '' : 'none'; 238 <style type="text/css"> 239 .cgitb {background: #E6EAF0; border: 1px solid #4D6180; direction: ltr;} 240 .cgitb p {margin: 0.5em 0; padding: 5px 10px; text-align: left;} 241 .cgitb ol {margin: 0} 242 .cgitb li {margin: 0.25em 0;} 243 .cgitb h1, .cgitb h2, .cgitb h3 {padding: 5px 10px; margin: 0; background: #4D6180; color: white;} 244 .cgitb h1 {font-size: 1.3em;} 245 .cgitb h2 {font-size: 1em; margin-top: 1em;} 246 .cgitb h3 {font-size: 1em;} 247 .cgitb .frames {margin: 0; padding: 0; color: #606060} 248 .cgitb .frames li {display: block;} 249 .cgitb .call {padding: 5px 10px; background: #A3B4CC; color: black} 250 .cgitb .context {padding: 0; font-family: monospace; } 251 .cgitb .context li {display: block; white-space: pre;} 252 .cgitb .context li.highlight {background: #C0D3F0; color: black} 253 .cgitb .variables {padding: 5px 10px; font-family: monospace;} 254 .cgitb .variables li {display: inline;} 255 .cgitb .variables li:after {content: ", ";} 256 .cgitb .variables li:last-child:after {content: "";} 257 .cgitb .exception {border: 1px solid #4D6180; margin: 10px} 258 .cgitb .exception h3 {background: #4D6180; color: white;} 259 .cgitb .exception p {color: black;} 260 .cgitb .exception ul {padding: 0 10px; font-family: monospace;} 261 .cgitb .exception li {display: block;} 263 .cgitb .buttons {margin: 0.5em 0; padding: 5px 10px;} 264 .cgitb .buttons li {display: inline; margin: 0; padding: 0 0.25em;} 270 self.
push(
"<H1> Error in Page </H1>\n")
271 self.
push(
"A copy of this error report has been submitted to the developers. ")
272 self.
push(
"The details of the error report are below.")
274 self.
push(handle_error.exceptionString())
279 self.
push(neo_cgi.htmlEscape(ncgi.hdf.dump()))
284 ncgi.hdf.setValue(
"CGI.debug.execute_time",
"%f" % (etime))
287 if SHOULD_DISPLAY
and self.
pagename:
288 debug_output = ncgi.hdf.getIntValue(
"page.debug",ncgi.hdf.getIntValue(
"Cookie.debug",0))
291 if ncgi.hdf.getValue(
"Query.debug",
"") == ncgi.hdf.getValue(
"Config.DebugPassword",
"1"):
292 ncgi.hdf.setValue(
"Config.DebugPassword",
"CSPage.py DEBUG hijack (%s)" %
293 ncgi.hdf.getValue(
"Config.DebugPassword",
""))
297 ncgi.hdf.setValue(
"Config.CompressionEnabled",
"1")
299 ncgi.hdf.setValue(
"Config.CompressionEnabled",
"0")
302 template_name = ncgi.hdf.getValue(
"Content",
"%s.cs" % self.
pagename)
306 self.context.setStatus(self, 200)
307 ncgi.display(template_name)
310 self[
'Content-Type'] =
'text/html' 311 self.
push(
"CSPage: Error occured\n")
313 self.
push(
"<pre>" + handle_error.exceptionString() +
"</pre>")
320 self.
push(
"Execution Time: %5.3f<BR><HR>" % (etime))
322 self.
push(neo_cgi.htmlEscape(ncgi.hdf.dump()))
327 script_name = ncgi.hdf.getValue(
"CGI.ScriptName",
"")
329 script_name = string.split(script_name,
"/")[-1]
341 fp = cStringIO.StringIO(str)
343 data = fp.read(8196*8)
345 self.context.stdout.write(data)
347 self.context.stdout.write(str)
348 except IOError, reason:
349 log(
"IOError: %s" % (repr(reason)))
361 self.
output(headerdata + data)
376 self[
'connection'] =
'close' 380 for (key, value)
in self._reply_headers.items():
381 headers.append(
'%s: %s' % (key, value))
382 headers.append(
'\r\n')
385 self.
push(string.join(headers,
'\r\n'))
387 return string.join(headers,
'\r\n')
392 if self.ncgi.hdf.getValue (
"Query.%s.0" % s,
""):
393 obj = self.ncgi.hdf.getChild (
"Query.%s" % s)
395 l.append(obj.value())
398 t = self.ncgi.hdf.getValue (
"Query.%s" % s,
"")
405 message = gHTTPResponses[code]
406 s = DEFAULT_ERROR_MESSAGE % {
407 'code': code,
'message': message,
'reason': reason
414 self.context.stdout.write(
"Content-Type: text/html\n")
415 self.context.setStatus(self, code)
416 self.context.stdout.write(
"Status: %s\n" % code)
417 self.context.stdout.write(s)
426 101:
"Switching Protocols",
430 203:
"Non-Authoritative Information",
432 205:
"Reset Content",
433 206:
"Partial Content",
434 300:
"Multiple Choices",
435 301:
"Moved Permanently",
436 302:
"Moved Temporarily",
442 402:
"Payment Required",
445 405:
"Method Not Allowed",
446 406:
"Not Acceptable",
447 407:
"Proxy Authentication Required",
448 408:
"Request Time-out",
451 411:
"Length Required",
452 412:
"Precondition Failed",
453 413:
"Request Entity Too Large",
454 414:
"Request-URI Too Large",
455 415:
"Unsupported Media Type",
456 500:
"Internal Server Error",
457 501:
"Not Implemented",
459 503:
"Service Unavailable",
460 504:
"Gateway Time-out",
461 505:
"HTTP Version not supported" 465 DEFAULT_ERROR_MESSAGE = string.join(
468 '<title>%(code)d %(message)s</title>',
471 '<h1>%(message)s</h1>',
472 '<p>Error code %(code)d.',
473 '<p>Message: %(message)s.',
474 '<p>Reason:\n <pre>%(reason)s</pre>',
def __setitem__(self, key, value)
def send_headers(self, dont_send=0)
def error(self, code, reason=None)
def __getitem__(self, key)
def redirectUri(self, redirectTo)
def setup(self)
methods to be overridden in subclass when necessary:
def setPaths(self, paths)
def __init__(self, context, pagename=None, readDefaultHDF=1, israwpage=0, parseCGI=1, makePUT=0, parms)
def setStatus(self, request, status)