Home | Trees | Index | Help |
|
---|
Package glass :: Module HTTPHandler :: Class HTTPHandler |
|
BaseRequestHandler
--+ |StreamRequestHandler
--+ |BaseHTTPRequestHandler
--+ | HTTPHandler
This class understands Aquarium, pyscripts, and server contexts.
It is based on SimpleHTTPServer and CGIHTTPServer from the Python standard library. It subclasses BaseHTTPServer.BaseHTTPRequestHandler also from the Python standard library. It adds the concept of a server context which is used to set things such as the document root. It also adds support for Aquarium. Last of all, it adds support for pyscripts. A pyscripts is a script that is executed via exec. It is given the following globals: stdin, stdout, env (from create_cgi_env), and the bound method send_response. The support for Aquarium is just a slight addition to the support for pyscripts. When using Glass, configure Aquarium to use the GlassAdaptor Web server adaptor. This code acts in place of the normal Aquarium index.py entry point.
The following attributes are added in this subclass:
The following class attributes are added in this subclass:
Method Summary | |
---|---|
Override, not extend, BaseRequestHandler.__init__ for coro. | |
Call setup, handle, and finish. | |
Set self.content_type for self.path_translated. | |
Create a dict containing a CGI environment. | |
Create the dictionary of globals passed to pyscripts or Aquarium. | |
Intercept do_(GET|HEAD|POST) and call the correct handler. | |
Intercept do_(GET|HEAD|POST) and call the correct handler. | |
Intercept do_(GET|HEAD|POST) and call the correct handler. | |
Intercept do_(GET|HEAD|POST) and call the correct handler. | |
Forward a request to Aquarium. | |
Pass a request on to a pyscript. | |
Handle a request for static content. | |
Actually launch Aquarium. | |
Normalize self.url_path. | |
Set server_name and server_port. | |
Do an HTTP redirect. | |
Do an URL rewriting necessary. | |
Search for self.url_path in each of the mounts. | |
Forbid access to certain places by regular expressions. | |
Can we handle this request via a simple redirect? | |
Can we return NOT_MODIFIED for a If-Modified-Since header? | |
Inherited from BaseHTTPRequestHandler | |
Return the client address formatted for logging. | |
Return the current date and time formatted for a message header. | |
Send the blank line ending the MIME headers. | |
Handle multiple requests if necessary. | |
Handle a single HTTP request. | |
Return the current time formatted for logging. | |
Log an error. | |
Log an arbitrary message. | |
Log an accepted request. | |
Parse a request (internal). | |
Send and log an error reply. | |
Send a MIME header. | |
Send the response header and log the response code. | |
Return the server software version string. | |
Inherited from StreamRequestHandler | |
| |
|
Class Variable Summary | |
---|---|
str |
error_message_format = '<!DOCTYPE HTML PUBLIC "-//W3C//D...
|
list |
index_files = ['index.html', 'index.py']
|
list |
pyscript_extensions = ['.py']
|
str |
server_version = 'glass/1.0'
|
Inherited from BaseHTTPRequestHandler | |
list |
monthname = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'J...
|
str |
protocol_version = 'HTTP/1.0'
|
dict |
responses = {400: ('Bad request', 'Bad request syntax or...
|
str |
sys_version = 'Python/2.4.4c1'
|
list |
weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat',...
|
Inherited from StreamRequestHandler | |
int |
rbufsize = -1 |
int |
wbufsize = 0 |
Method Details |
---|
__init__(self,
request,
client_address,
server,
server_ctx)
|
__call__(self)
|
choose_content_type(self)Set self.content_type for self.path_translated. This code uses mimetypes.types_map and defaults to "text/plain". |
create_cgi_env(self)Create a dict containing a CGI environment. I do not support the following:
Per the following, I also set HTTPS="on" if SSL is being used. Reverse DNS lookups are turned off, so REMOTE_HOST = REMOTE_ADDR. Subclasses are welcome to use self.address_string() if they so desire. |
create_pyscript_globals(self)Create the dictionary of globals passed to pyscripts or Aquarium. |
do_ALL(self)Intercept do_(GET|HEAD|POST) and call the correct handler. This method forwards the request to the correct handler: handle_static, handle_aquarium, or handle_pyscript. This code also supports index files. Things that can't be handled here such as directory listings and 404's are passed to Aquarium so that it can produce pretty error pages. |
do_GET(self)Intercept do_(GET|HEAD|POST) and call the correct handler. This method forwards the request to the correct handler: handle_static, handle_aquarium, or handle_pyscript. This code also supports index files. Things that can't be handled here such as directory listings and 404's are passed to Aquarium so that it can produce pretty error pages. |
do_HEAD(self)Intercept do_(GET|HEAD|POST) and call the correct handler. This method forwards the request to the correct handler: handle_static, handle_aquarium, or handle_pyscript. This code also supports index files. Things that can't be handled here such as directory listings and 404's are passed to Aquarium so that it can produce pretty error pages. |
do_POST(self)Intercept do_(GET|HEAD|POST) and call the correct handler. This method forwards the request to the correct handler: handle_static, handle_aquarium, or handle_pyscript. This code also supports index files. Things that can't be handled here such as directory listings and 404's are passed to Aquarium so that it can produce pretty error pages. |
handle_aquarium(self)Forward a request to Aquarium. Call self.launch_aquarium. I will try to catch any exceptions that Aquarium lets through, but it might have already set the response and generated some output. After catching the exception and sending an error message, I will reraise it so that it'll end up in the logs. Oh well, it's better than nothing. Note that HEAD is not supported. |
handle_pyscript(self)Pass a request on to a pyscript. The script will be executed via exec. The application should deal with its own exceptions. I will try to catch exceptions raised in exec, but the script might have already set the response and generated some output. After catching the exception and sending an error message, I will reraise it so that it'll end up in the logs. Oh well, it's better than nothing. PATH_INFO is not supported. It would be difficult to handle the Aquarium case as well as the PATH_INFO case. HEAD is not supported. Last of all, do not use pyscripts if you are using coro since you'll probably end up doing a context switch, which isn't allowed in an exec. |
handle_static(self)Handle a request for static content. POST is not supported. |
launch_aquarium(self)Actually launch Aquarium. Launch the self.server_ctx.aquarium_entry_point. Set aquarium. |
normalize_url_path(self)Normalize self.url_path. This calls urllib.unquote and posixpath.normpath. |
parse_host_header(self)Set server_name and server_port. HACK: For MSIE, ignore the port from the Host header; just use the port the server is actually using. This is to work around a known bug in MSIE. |
redirect(self, url, httpResponse=307)Do an HTTP redirect.
|
rewrite_path(self)Do an URL rewriting necessary. This is called after self.url_path and self.query_string are set. Update self.url_path in any way you wish. This class does nothing, but it provides a hook for subclasses. |
translate_path(self)Search for self.url_path in each of the mounts. Set self.vfs and self.path_translated. Components that mean special things to the vfs (e.g. drive or directory names) are stripped here. |
try_handle_forbidden(self)Forbid access to certain places by regular expressions. This is called after try_handle_redirect is called. If appropriate, call send_error with HTTPResponses.FORBIDDEN or perhaps HTTPResponses.NOT_FOUND and return 1. Otherwise, return 0. This class forbids access to "/CVS/", but you may want to override it and do more. |
try_handle_redirect(self)Can we handle this request via a simple redirect? This is called after self.url_path and self.query_string are set. If appropriate, call redirect and return 1. Otherwise, return 0. This class does nothing but return 0. However, it can be overriden by subclasses. |
try_if_modified_since(self)Can we return NOT_MODIFIED for a If-Modified-Since header? If this is possible, handle the request, and return 1. Otherwise, return 0. |
Class Variable Details |
---|
index_files
|
pyscript_extensions
|
server_version
|
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Mon Jan 1 16:36:34 2007 | http://epydoc.sf.net |