Package wsgiref :: Module handlers :: Class BaseHandler
[hide private]
[frames] | no frames]

Class BaseHandler

Known Subclasses:

Manage the invocation of a WSGI application

Nested Classes [hide private]
  wsgi_file_wrapper
Wrapper to convert file-like objects to iterables
  headers_class
Manage a collection of HTTP response headers
Instance Methods [hide private]
 
run(self, application)
Invoke the application
 
setup_environ(self)
Set up the environment for one request
 
finish_response(self)
Send any iterable data, then close self and the iterable
 
get_scheme(self)
Return the URL scheme being used
 
set_content_length(self)
Compute Content-Length or switch to chunked encoding if possible
 
cleanup_headers(self)
Make any necessary header changes or defaults
 
start_response(self, status, headers, exc_info=None)
'start_response()' callable as specified by PEP 333
 
send_preamble(self)
Transmit version/status/date/server, via self._write()
 
write(self, data)
'write()' callable as specified by PEP 333
 
sendfile(self)
Platform-specific file transmission
 
finish_content(self)
Ensure headers and content have both been sent
 
close(self)
Close the iterable (if needed) and reset all instance vars
 
send_headers(self)
Transmit headers to the client, via self._write()
 
result_is_file(self)
True if 'self.result' is an instance of 'self.wsgi_file_wrapper'
 
client_is_modern(self)
True if client can accept status and headers
 
log_exception(self, exc_info)
Log the 'exc_info' tuple in the server log
 
handle_error(self)
Log current error, and send error output to client if possible
 
error_output(self, environ, start_response)
WSGI mini-app to create error output
 
_write(self, data)
Override in subclass to buffer data for send to client
 
_flush(self)
Override in subclass to force sending of recent '_write()' calls
 
get_stdin(self)
Override in subclass to return suitable 'wsgi.input'
 
get_stderr(self)
Override in subclass to return suitable 'wsgi.errors'
 
add_cgi_vars(self)
Override in subclass to insert CGI variables in 'self.environ'
Class Variables [hide private]
  wsgi_version = (1, 0)
  wsgi_multithread = True
  wsgi_multiprocess = True
  wsgi_run_once = False
  origin_server = True
  http_version = '1.0'
  server_software = None
  os_environ = {'BASH_ENV': '/home/edloper/.bashrc', 'CONSOLE': ...
  traceback_limit = None
  error_status = '500 Dude, this is whack!'
  error_headers = [('Content-Type', 'text/plain')]
  error_body = 'A server error occurred. Please contact the adm...
  result = None
  status = None
  headers_sent = False
  headers = None
  bytes_sent = 0
Method Details [hide private]

finish_response(self)

 

Send any iterable data, then close self and the iterable

Subclasses intended for use in asynchronous servers will want to redefine this method, such that it sets up callbacks in the event loop to iterate over the data, and to call 'self.close()' once the response is finished.

cleanup_headers(self)

 

Make any necessary header changes or defaults

Subclasses can extend this to add other defaults.

sendfile(self)

 

Platform-specific file transmission

Override this method in subclasses to support platform-specific file transmission. It is only called if the application's return iterable ('self.result') is an instance of 'self.wsgi_file_wrapper'.

This method should return a true value if it was able to actually transmit the wrapped file-like object using a platform-specific approach. It should return a false value if normal iteration should be used instead. An exception can be raised to indicate that transmission was attempted, but failed.

NOTE: this method should call 'self.send_headers()' if 'self.headers_sent' is false and it is going to attempt direct transmission of the file.

close(self)

 

Close the iterable (if needed) and reset all instance vars

Subclasses may want to also drop the client connection.

log_exception(self, exc_info)

 

Log the 'exc_info' tuple in the server log

Subclasses may override to retarget the output or change its format.

error_output(self, environ, start_response)

 

WSGI mini-app to create error output

By default, this just uses the 'error_status', 'error_headers', and 'error_body' attributes to generate an output page. It can be overridden in a subclass to dynamically generate diagnostics, choose an appropriate message for the user's preferred language, etc.

Note, however, that it's not recommended from a security perspective to spit out diagnostics to any old user; ideally, you should have to do something special to enable diagnostic output, which is why we don't include any here!

_write(self, data)

 

Override in subclass to buffer data for send to client

It's okay if this method actually transmits the data; BaseHandler just separates write and flush operations for greater efficiency when the underlying system actually has such a distinction.

_flush(self)

 

Override in subclass to force sending of recent '_write()' calls

It's okay if this method is a no-op (i.e., if '_write()' actually sends the data.


Class Variable Details [hide private]

os_environ

Value:
{'BASH_ENV': '/home/edloper/.bashrc',
 'CONSOLE': '/dev/console',
 'CVSROOT': '/home/edloper/cvs',
 'DISPLAY': ':1.0',
 'DPKG_ARCH': 'i386',
 'EDITOR': 'emacs',
 'FONT_PATH': '/home/edloper/.afterstep/desktop/fonts/:/usr/share/afte\
rstep/desktop/fonts/:/usr/share/fonts/default/TrueType/:/usr/share/fon\
...

error_body

Value:
'A server error occurred.  Please contact the administrator.'