| | |
- BaseHandler
-
- SimpleHandler
-
- BaseCGIHandler
-
- CGIHandler
class BaseCGIHandler(SimpleHandler) |
| |
CGI-like systems using input/output/error streams and environ mapping
Usage::
handler = BaseCGIHandler(inp,out,err,env)
handler.run(app)
This handler class is useful for gateway protocols like ReadyExec and
FastCGI, that have usable input/output/error streams and an environment
mapping. It's also the base class for CGIHandler, which just uses
sys.stdin, os.environ, and so on.
The constructor also takes keyword arguments 'multithread' and
'multiprocess' (defaulting to 'True' and 'False' respectively) to control
the configuration sent to the application. It sets 'origin_server' to
False (to enable CGI-like output), and assumes that 'wsgi.run_once' is
False. |
| |
- Method resolution order:
- BaseCGIHandler
- SimpleHandler
- BaseHandler
Data and other attributes defined here:
- origin_server = False
Methods inherited from SimpleHandler:
- __init__(self, stdin, stdout, stderr, environ, multithread=True, multiprocess=False)
- add_cgi_vars(self)
- get_stderr(self)
- get_stdin(self)
Methods inherited from BaseHandler:
- cleanup_headers(self)
- Make any necessary header changes or defaults
Subclasses can extend this to add other defaults.
- client_is_modern(self)
- True if client can accept status and headers
- close(self)
- Close the iterable (if needed) and reset all instance vars
Subclasses may want to also drop the client connection.
- 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!
- finish_content(self)
- Ensure headers and content have both been sent
- 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
'close()' once the response is finished.
- get_scheme(self)
- Return the URL scheme being used
- handle_error(self)
- Log current error, and send error output to client if possible
- 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.
- result_is_file(self)
- True if 'self.result' is an instance of 'self.wsgi_file_wrapper'
- run(self, application)
- Invoke the application
- send_headers(self)
- Transmit headers to the client, via _write()
- send_preamble(self)
- Transmit version/status/date/server, via _write()
- 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 'send_headers()' if
'self.headers_sent' is false and it is going to attempt direct
transmission of the file.
- set_content_length(self)
- Compute Content-Length or switch to chunked encoding if possible
- setup_environ(self)
- Set up the environment for one request
- start_response(self, status, headers, exc_info=None)
- 'start_response()' callable as specified by PEP 333
- write(self, data)
- 'write()' callable as specified by PEP 333
Data and other attributes inherited from BaseHandler:
- bytes_sent = 0
- error_body = 'A server error occurred. Please contact the administrator.'
- error_headers = [('Content-Type', 'text/plain')]
- error_status = '500 Dude, this is whack!'
- headers = None
- headers_class = <class wsgiref.headers.Headers at 0xb6171b9c>
- Manage a collection of HTTP response headers
- headers_sent = False
- http_version = '1.0'
- os_environ = {'CVSROOT': '/home/cvs', 'CVS_RSH': 'ssh', 'DISPLAY': 'localhost:10.0', 'G_BROKEN_FILENAMES': '1', 'HISTSIZE': '1000', 'HOME': '/home/ping', 'HOSTNAME': 'server1.LFW.org', 'INPUTRC': '/etc/inputrc', 'LANG': 'en_US.UTF-8', 'LESSOPEN': '|/usr/bin/lesspipe.sh %s', ...}
- result = None
- server_software = None
- status = None
- traceback_limit = None
- wsgi_file_wrapper = <class wsgiref.util.FileWrapper at 0xb6171adc>
- Wrapper to convert file-like objects to iterables
- wsgi_multiprocess = True
- wsgi_multithread = True
- wsgi_run_once = False
- wsgi_version = (1, 0)
|
class BaseHandler |
| |
Manage the invocation of a WSGI application |
| |
Methods defined here:
- add_cgi_vars(self)
- Override in subclass to insert CGI variables in 'self.environ'
- cleanup_headers(self)
- Make any necessary header changes or defaults
Subclasses can extend this to add other defaults.
- client_is_modern(self)
- True if client can accept status and headers
- close(self)
- Close the iterable (if needed) and reset all instance vars
Subclasses may want to also drop the client connection.
- 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!
- finish_content(self)
- Ensure headers and content have both been sent
- 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
'close()' once the response is finished.
- get_scheme(self)
- Return the URL scheme being used
- get_stderr(self)
- Override in subclass to return suitable 'wsgi.errors'
- get_stdin(self)
- Override in subclass to return suitable 'wsgi.input'
- handle_error(self)
- Log current error, and send error output to client if possible
- 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.
- result_is_file(self)
- True if 'self.result' is an instance of 'self.wsgi_file_wrapper'
- run(self, application)
- Invoke the application
- send_headers(self)
- Transmit headers to the client, via _write()
- send_preamble(self)
- Transmit version/status/date/server, via _write()
- 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 'send_headers()' if
'self.headers_sent' is false and it is going to attempt direct
transmission of the file.
- set_content_length(self)
- Compute Content-Length or switch to chunked encoding if possible
- setup_environ(self)
- Set up the environment for one request
- start_response(self, status, headers, exc_info=None)
- 'start_response()' callable as specified by PEP 333
- write(self, data)
- 'write()' callable as specified by PEP 333
Data and other attributes defined here:
- bytes_sent = 0
- error_body = 'A server error occurred. Please contact the administrator.'
- error_headers = [('Content-Type', 'text/plain')]
- error_status = '500 Dude, this is whack!'
- headers = None
- headers_class = <class wsgiref.headers.Headers at 0xb6171b9c>
- Manage a collection of HTTP response headers
- headers_sent = False
- http_version = '1.0'
- origin_server = True
- os_environ = {'CVSROOT': '/home/cvs', 'CVS_RSH': 'ssh', 'DISPLAY': 'localhost:10.0', 'G_BROKEN_FILENAMES': '1', 'HISTSIZE': '1000', 'HOME': '/home/ping', 'HOSTNAME': 'server1.LFW.org', 'INPUTRC': '/etc/inputrc', 'LANG': 'en_US.UTF-8', 'LESSOPEN': '|/usr/bin/lesspipe.sh %s', ...}
- result = None
- server_software = None
- status = None
- traceback_limit = None
- wsgi_file_wrapper = <class wsgiref.util.FileWrapper at 0xb6171adc>
- Wrapper to convert file-like objects to iterables
- wsgi_multiprocess = True
- wsgi_multithread = True
- wsgi_run_once = False
- wsgi_version = (1, 0)
|
class CGIHandler(BaseCGIHandler) |
| |
CGI-based invocation via sys.stdin/stdout/stderr and os.environ
Usage::
CGIHandler().run(app)
The difference between this class and BaseCGIHandler is that it always
uses 'wsgi.run_once' of 'True', 'wsgi.multithread' of 'False', and
'wsgi.multiprocess' of 'True'. It does not take any initialization
parameters, but always uses 'sys.stdin', 'os.environ', and friends.
If you need to override any of these parameters, use BaseCGIHandler
instead. |
| |
- Method resolution order:
- CGIHandler
- BaseCGIHandler
- SimpleHandler
- BaseHandler
Methods defined here:
- __init__(self)
Data and other attributes defined here:
- wsgi_run_once = True
Data and other attributes inherited from BaseCGIHandler:
- origin_server = False
Methods inherited from SimpleHandler:
- add_cgi_vars(self)
- get_stderr(self)
- get_stdin(self)
Methods inherited from BaseHandler:
- cleanup_headers(self)
- Make any necessary header changes or defaults
Subclasses can extend this to add other defaults.
- client_is_modern(self)
- True if client can accept status and headers
- close(self)
- Close the iterable (if needed) and reset all instance vars
Subclasses may want to also drop the client connection.
- 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!
- finish_content(self)
- Ensure headers and content have both been sent
- 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
'close()' once the response is finished.
- get_scheme(self)
- Return the URL scheme being used
- handle_error(self)
- Log current error, and send error output to client if possible
- 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.
- result_is_file(self)
- True if 'self.result' is an instance of 'self.wsgi_file_wrapper'
- run(self, application)
- Invoke the application
- send_headers(self)
- Transmit headers to the client, via _write()
- send_preamble(self)
- Transmit version/status/date/server, via _write()
- 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 'send_headers()' if
'self.headers_sent' is false and it is going to attempt direct
transmission of the file.
- set_content_length(self)
- Compute Content-Length or switch to chunked encoding if possible
- setup_environ(self)
- Set up the environment for one request
- start_response(self, status, headers, exc_info=None)
- 'start_response()' callable as specified by PEP 333
- write(self, data)
- 'write()' callable as specified by PEP 333
Data and other attributes inherited from BaseHandler:
- bytes_sent = 0
- error_body = 'A server error occurred. Please contact the administrator.'
- error_headers = [('Content-Type', 'text/plain')]
- error_status = '500 Dude, this is whack!'
- headers = None
- headers_class = <class wsgiref.headers.Headers at 0xb6171b9c>
- Manage a collection of HTTP response headers
- headers_sent = False
- http_version = '1.0'
- os_environ = {'CVSROOT': '/home/cvs', 'CVS_RSH': 'ssh', 'DISPLAY': 'localhost:10.0', 'G_BROKEN_FILENAMES': '1', 'HISTSIZE': '1000', 'HOME': '/home/ping', 'HOSTNAME': 'server1.LFW.org', 'INPUTRC': '/etc/inputrc', 'LANG': 'en_US.UTF-8', 'LESSOPEN': '|/usr/bin/lesspipe.sh %s', ...}
- result = None
- server_software = None
- status = None
- traceback_limit = None
- wsgi_file_wrapper = <class wsgiref.util.FileWrapper at 0xb6171adc>
- Wrapper to convert file-like objects to iterables
- wsgi_multiprocess = True
- wsgi_multithread = True
- wsgi_version = (1, 0)
|
class SimpleHandler(BaseHandler) |
| |
Handler that's just initialized with streams, environment, etc.
This handler subclass is intended for synchronous HTTP/1.0 origin servers,
and handles sending the entire response output, given the correct inputs.
Usage::
handler = SimpleHandler(
inp,out,err,env, multithread=False, multiprocess=True
)
handler.run(app) |
| |
Methods defined here:
- __init__(self, stdin, stdout, stderr, environ, multithread=True, multiprocess=False)
- add_cgi_vars(self)
- get_stderr(self)
- get_stdin(self)
Methods inherited from BaseHandler:
- cleanup_headers(self)
- Make any necessary header changes or defaults
Subclasses can extend this to add other defaults.
- client_is_modern(self)
- True if client can accept status and headers
- close(self)
- Close the iterable (if needed) and reset all instance vars
Subclasses may want to also drop the client connection.
- 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!
- finish_content(self)
- Ensure headers and content have both been sent
- 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
'close()' once the response is finished.
- get_scheme(self)
- Return the URL scheme being used
- handle_error(self)
- Log current error, and send error output to client if possible
- 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.
- result_is_file(self)
- True if 'self.result' is an instance of 'self.wsgi_file_wrapper'
- run(self, application)
- Invoke the application
- send_headers(self)
- Transmit headers to the client, via _write()
- send_preamble(self)
- Transmit version/status/date/server, via _write()
- 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 'send_headers()' if
'self.headers_sent' is false and it is going to attempt direct
transmission of the file.
- set_content_length(self)
- Compute Content-Length or switch to chunked encoding if possible
- setup_environ(self)
- Set up the environment for one request
- start_response(self, status, headers, exc_info=None)
- 'start_response()' callable as specified by PEP 333
- write(self, data)
- 'write()' callable as specified by PEP 333
Data and other attributes inherited from BaseHandler:
- bytes_sent = 0
- error_body = 'A server error occurred. Please contact the administrator.'
- error_headers = [('Content-Type', 'text/plain')]
- error_status = '500 Dude, this is whack!'
- headers = None
- headers_class = <class wsgiref.headers.Headers at 0xb6171b9c>
- Manage a collection of HTTP response headers
- headers_sent = False
- http_version = '1.0'
- origin_server = True
- os_environ = {'CVSROOT': '/home/cvs', 'CVS_RSH': 'ssh', 'DISPLAY': 'localhost:10.0', 'G_BROKEN_FILENAMES': '1', 'HISTSIZE': '1000', 'HOME': '/home/ping', 'HOSTNAME': 'server1.LFW.org', 'INPUTRC': '/etc/inputrc', 'LANG': 'en_US.UTF-8', 'LESSOPEN': '|/usr/bin/lesspipe.sh %s', ...}
- result = None
- server_software = None
- status = None
- traceback_limit = None
- wsgi_file_wrapper = <class wsgiref.util.FileWrapper at 0xb6171adc>
- Wrapper to convert file-like objects to iterables
- wsgi_multiprocess = True
- wsgi_multithread = True
- wsgi_run_once = False
- wsgi_version = (1, 0)
| |