blob: 37ded9fdaef2f56547b5ef2b8e2d92027d1c6ab6 [file] [log] [blame]
Phillip J. Eby5cf565d2006-06-09 16:40:18 +00001\section{\module{wsgiref} --- WSGI Utilities and Reference
2Implementation}
3\declaremodule{}{wsgiref}
4\moduleauthor{Phillip J. Eby}{pje@telecommunity.com}
5\sectionauthor{Phillip J. Eby}{pje@telecommunity.com}
6\modulesynopsis{WSGI Utilities and Reference Implementation}
7
Neal Norwitza754a222006-06-11 05:45:47 +00008\versionadded{2.5}
9
Phillip J. Eby5cf565d2006-06-09 16:40:18 +000010The Web Server Gateway Interface (WSGI) is a standard interface
11between web server software and web applications written in Python.
12Having a standard interface makes it easy to use an application
13that supports WSGI with a number of different web servers.
14
15Only authors of web servers and programming frameworks need to know
16every detail and corner case of the WSGI design. You don't need to
17understand every detail of WSGI just to install a WSGI application or
18to write a web application using an existing framework.
19
20\module{wsgiref} is a reference implementation of the WSGI specification
21that can be used to add WSGI support to a web server or framework. It
22provides utilities for manipulating WSGI environment variables and
23response headers, base classes for implementing WSGI servers, a demo
24HTTP server that serves WSGI applications, and a validation tool that
25checks WSGI servers and applications for conformance to the
26WSGI specification (\pep{333}).
27
28% XXX If you're just trying to write a web application...
Phillip J. Eby5cf565d2006-06-09 16:40:18 +000029
Andrew M. Kuchling48b10072006-11-10 14:39:01 +000030See \url{http://www.wsgi.org} for more information about WSGI,
31and links to tutorials and other resources.
Phillip J. Eby5cf565d2006-06-09 16:40:18 +000032
33
34
35
36
37
38
39
40
41
42
43
44
45\subsection{\module{wsgiref.util} -- WSGI environment utilities}
46\declaremodule{}{wsgiref.util}
47
48This module provides a variety of utility functions for working with
49WSGI environments. A WSGI environment is a dictionary containing
50HTTP request variables as described in \pep{333}. All of the functions
51taking an \var{environ} parameter expect a WSGI-compliant dictionary to
52be supplied; please see \pep{333} for a detailed specification.
53
54\begin{funcdesc}{guess_scheme}{environ}
55Return a guess for whether \code{wsgi.url_scheme} should be ``http'' or
56``https'', by checking for a \code{HTTPS} environment variable in the
57\var{environ} dictionary. The return value is a string.
58
59This function is useful when creating a gateway that wraps CGI or a
60CGI-like protocol such as FastCGI. Typically, servers providing such
61protocols will include a \code{HTTPS} variable with a value of ``1''
62``yes'', or ``on'' when a request is received via SSL. So, this
63function returns ``https'' if such a value is found, and ``http''
64otherwise.
65\end{funcdesc}
66
67\begin{funcdesc}{request_uri}{environ \optional{, include_query=1}}
68Return the full request URI, optionally including the query string,
69using the algorithm found in the ``URL Reconstruction'' section of
70\pep{333}. If \var{include_query} is false, the query string is
71not included in the resulting URI.
72\end{funcdesc}
73
74\begin{funcdesc}{application_uri}{environ}
75Similar to \function{request_uri}, except that the \code{PATH_INFO} and
76\code{QUERY_STRING} variables are ignored. The result is the base URI
77of the application object addressed by the request.
78\end{funcdesc}
79
80\begin{funcdesc}{shift_path_info}{environ}
81Shift a single name from \code{PATH_INFO} to \code{SCRIPT_NAME} and
82return the name. The \var{environ} dictionary is \emph{modified}
83in-place; use a copy if you need to keep the original \code{PATH_INFO}
84or \code{SCRIPT_NAME} intact.
85
86If there are no remaining path segments in \code{PATH_INFO}, \code{None}
87is returned.
88
89Typically, this routine is used to process each portion of a request
90URI path, for example to treat the path as a series of dictionary keys.
91This routine modifies the passed-in environment to make it suitable for
92invoking another WSGI application that is located at the target URI.
93For example, if there is a WSGI application at \code{/foo}, and the
94request URI path is \code{/foo/bar/baz}, and the WSGI application at
95\code{/foo} calls \function{shift_path_info}, it will receive the string
96``bar'', and the environment will be updated to be suitable for passing
97to a WSGI application at \code{/foo/bar}. That is, \code{SCRIPT_NAME}
98will change from \code{/foo} to \code{/foo/bar}, and \code{PATH_INFO}
99will change from \code{/bar/baz} to \code{/baz}.
100
101When \code{PATH_INFO} is just a ``/'', this routine returns an empty
102string and appends a trailing slash to \code{SCRIPT_NAME}, even though
103empty path segments are normally ignored, and \code{SCRIPT_NAME} doesn't
104normally end in a slash. This is intentional behavior, to ensure that
105an application can tell the difference between URIs ending in \code{/x}
106from ones ending in \code{/x/} when using this routine to do object
107traversal.
108
109\end{funcdesc}
110
111\begin{funcdesc}{setup_testing_defaults}{environ}
112Update \var{environ} with trivial defaults for testing purposes.
113
114This routine adds various parameters required for WSGI, including
115\code{HTTP_HOST}, \code{SERVER_NAME}, \code{SERVER_PORT},
116\code{REQUEST_METHOD}, \code{SCRIPT_NAME}, \code{PATH_INFO}, and all of
117the \pep{333}-defined \code{wsgi.*} variables. It only supplies default
118values, and does not replace any existing settings for these variables.
119
120This routine is intended to make it easier for unit tests of WSGI
121servers and applications to set up dummy environments. It should NOT
122be used by actual WSGI servers or applications, since the data is fake!
123\end{funcdesc}
124
125
126
127In addition to the environment functions above, the
128\module{wsgiref.util} module also provides these miscellaneous
129utilities:
130
131\begin{funcdesc}{is_hop_by_hop}{header_name}
132Return true if 'header_name' is an HTTP/1.1 ``Hop-by-Hop'' header, as
133defined by \rfc{2616}.
134\end{funcdesc}
135
136\begin{classdesc}{FileWrapper}{filelike \optional{, blksize=8192}}
137A wrapper to convert a file-like object to an iterator. The resulting
138objects support both \method{__getitem__} and \method{__iter__}
139iteration styles, for compatibility with Python 2.1 and Jython.
140As the object is iterated over, the optional \var{blksize} parameter
141will be repeatedly passed to the \var{filelike} object's \method{read()}
142method to obtain strings to yield. When \method{read()} returns an
143empty string, iteration is ended and is not resumable.
144
145If \var{filelike} has a \method{close()} method, the returned object
146will also have a \method{close()} method, and it will invoke the
147\var{filelike} object's \method{close()} method when called.
148\end{classdesc}
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168\subsection{\module{wsgiref.headers} -- WSGI response header tools}
169\declaremodule{}{wsgiref.headers}
170
171This module provides a single class, \class{Headers}, for convenient
172manipulation of WSGI response headers using a mapping-like interface.
173
174\begin{classdesc}{Headers}{headers}
175Create a mapping-like object wrapping \var{headers}, which must be a
176list of header name/value tuples as described in \pep{333}. Any changes
177made to the new \class{Headers} object will directly update the
178\var{headers} list it was created with.
179
180\class{Headers} objects support typical mapping operations including
181\method{__getitem__}, \method{get}, \method{__setitem__},
182\method{setdefault}, \method{__delitem__}, \method{__contains__} and
183\method{has_key}. For each of these methods, the key is the header name
184(treated case-insensitively), and the value is the first value
185associated with that header name. Setting a header deletes any existing
186values for that header, then adds a new value at the end of the wrapped
187header list. Headers' existing order is generally maintained, with new
188headers added to the end of the wrapped list.
189
190Unlike a dictionary, \class{Headers} objects do not raise an error when
191you try to get or delete a key that isn't in the wrapped header list.
192Getting a nonexistent header just returns \code{None}, and deleting
193a nonexistent header does nothing.
194
195\class{Headers} objects also support \method{keys()}, \method{values()},
196and \method{items()} methods. The lists returned by \method{keys()}
197and \method{items()} can include the same key more than once if there
198is a multi-valued header. The \code{len()} of a \class{Headers} object
199is the same as the length of its \method{items()}, which is the same
200as the length of the wrapped header list. In fact, the \method{items()}
201method just returns a copy of the wrapped header list.
202
203Calling \code{str()} on a \class{Headers} object returns a formatted
204string suitable for transmission as HTTP response headers. Each header
205is placed on a line with its value, separated by a colon and a space.
206Each line is terminated by a carriage return and line feed, and the
207string is terminated with a blank line.
208
209In addition to their mapping interface and formatting features,
210\class{Headers} objects also have the following methods for querying
211and adding multi-valued headers, and for adding headers with MIME
212parameters:
213
214\begin{methoddesc}{get_all}{name}
215Return a list of all the values for the named header.
216
217The returned list will be sorted in the order they appeared in the
218original header list or were added to this instance, and may contain
219duplicates. Any fields deleted and re-inserted are always appended to
220the header list. If no fields exist with the given name, returns an
221empty list.
222\end{methoddesc}
223
224
225\begin{methoddesc}{add_header}{name, value, **_params}
226Add a (possibly multi-valued) header, with optional MIME parameters
227specified via keyword arguments.
228
229\var{name} is the header field to add. Keyword arguments can be used to
230set MIME parameters for the header field. Each parameter must be a
231string or \code{None}. Underscores in parameter names are converted to
232dashes, since dashes are illegal in Python identifiers, but many MIME
233parameter names include dashes. If the parameter value is a string, it
234is added to the header value parameters in the form \code{name="value"}.
235If it is \code{None}, only the parameter name is added. (This is used
236for MIME parameters without a value.) Example usage:
237
238\begin{verbatim}
239h.add_header('content-disposition', 'attachment', filename='bud.gif')
240\end{verbatim}
241
242The above will add a header that looks like this:
243
244\begin{verbatim}
245Content-Disposition: attachment; filename="bud.gif"
246\end{verbatim}
247\end{methoddesc}
248\end{classdesc}
249
250\subsection{\module{wsgiref.simple_server} -- a simple WSGI HTTP server}
251\declaremodule[wsgiref.simpleserver]{}{wsgiref.simple_server}
252
253This module implements a simple HTTP server (based on
254\module{BaseHTTPServer}) that serves WSGI applications. Each server
255instance serves a single WSGI application on a given host and port. If
256you want to serve multiple applications on a single host and port, you
257should create a WSGI application that parses \code{PATH_INFO} to select
258which application to invoke for each request. (E.g., using the
259\function{shift_path_info()} function from \module{wsgiref.util}.)
260
261
262\begin{funcdesc}{make_server}{host, port, app
263\optional{, server_class=\class{WSGIServer} \optional{,
264handler_class=\class{WSGIRequestHandler}}}}
265Create a new WSGI server listening on \var{host} and \var{port},
266accepting connections for \var{app}. The return value is an instance of
267the supplied \var{server_class}, and will process requests using the
268specified \var{handler_class}. \var{app} must be a WSGI application
269object, as defined by \pep{333}.
270
271Example usage:
272\begin{verbatim}from wsgiref.simple_server import make_server, demo_app
273
274httpd = make_server('', 8000, demo_app)
275print "Serving HTTP on port 8000..."
276
277# Respond to requests until process is killed
278httpd.serve_forever()
279
280# Alternative: serve one request, then exit
281##httpd.handle_request()
282\end{verbatim}
283
284\end{funcdesc}
285
286
287
288
289
290
291\begin{funcdesc}{demo_app}{environ, start_response}
292This function is a small but complete WSGI application that
293returns a text page containing the message ``Hello world!''
294and a list of the key/value pairs provided in the
295\var{environ} parameter. It's useful for verifying that a WSGI server
296(such as \module{wsgiref.simple_server}) is able to run a simple WSGI
297application correctly.
298\end{funcdesc}
299
300
301\begin{classdesc}{WSGIServer}{server_address, RequestHandlerClass}
302Create a \class{WSGIServer} instance. \var{server_address} should be
303a \code{(host,port)} tuple, and \var{RequestHandlerClass} should be
304the subclass of \class{BaseHTTPServer.BaseHTTPRequestHandler} that will
305be used to process requests.
306
307You do not normally need to call this constructor, as the
308\function{make_server()} function can handle all the details for you.
309
310\class{WSGIServer} is a subclass
311of \class{BaseHTTPServer.HTTPServer}, so all of its methods (such as
312\method{serve_forever()} and \method{handle_request()}) are available.
313\class{WSGIServer} also provides these WSGI-specific methods:
314
315\begin{methoddesc}{set_app}{application}
316Sets the callable \var{application} as the WSGI application that will
317receive requests.
318\end{methoddesc}
319
320\begin{methoddesc}{get_app}{}
321Returns the currently-set application callable.
322\end{methoddesc}
323
324Normally, however, you do not need to use these additional methods, as
325\method{set_app()} is normally called by \function{make_server()}, and
326the \method{get_app()} exists mainly for the benefit of request handler
327instances.
328\end{classdesc}
329
330
331
332\begin{classdesc}{WSGIRequestHandler}{request, client_address, server}
333Create an HTTP handler for the given \var{request} (i.e. a socket),
334\var{client_address} (a \code{(\var{host},\var{port})} tuple), and
335\var{server} (\class{WSGIServer} instance).
336
337You do not need to create instances of this class directly; they are
338automatically created as needed by \class{WSGIServer} objects. You
339can, however, subclass this class and supply it as a \var{handler_class}
340to the \function{make_server()} function. Some possibly relevant
341methods for overriding in subclasses:
342
343\begin{methoddesc}{get_environ}{}
344Returns a dictionary containing the WSGI environment for a request. The
345default implementation copies the contents of the \class{WSGIServer}
346object's \member{base_environ} dictionary attribute and then adds
347various headers derived from the HTTP request. Each call to this method
348should return a new dictionary containing all of the relevant CGI
349environment variables as specified in \pep{333}.
350\end{methoddesc}
351
352\begin{methoddesc}{get_stderr}{}
353Return the object that should be used as the \code{wsgi.errors} stream.
354The default implementation just returns \code{sys.stderr}.
355\end{methoddesc}
356
357\begin{methoddesc}{handle}{}
358Process the HTTP request. The default implementation creates a handler
359instance using a \module{wsgiref.handlers} class to implement the actual
360WSGI application interface.
361\end{methoddesc}
362
363\end{classdesc}
364
365
366
367
368
369
370
371
372
373\subsection{\module{wsgiref.validate} -- WSGI conformance checker}
374\declaremodule{}{wsgiref.validate}
375When creating new WSGI application objects, frameworks, servers, or
376middleware, it can be useful to validate the new code's conformance
377using \module{wsgiref.validate}. This module provides a function that
378creates WSGI application objects that validate communications between
379a WSGI server or gateway and a WSGI application object, to check both
380sides for protocol conformance.
381
382Note that this utility does not guarantee complete \pep{333} compliance;
383an absence of errors from this module does not necessarily mean that
384errors do not exist. However, if this module does produce an error,
385then it is virtually certain that either the server or application is
386not 100\% compliant.
387
388This module is based on the \module{paste.lint} module from Ian
389Bicking's ``Python Paste'' library.
390
391\begin{funcdesc}{validator}{application}
392Wrap \var{application} and return a new WSGI application object. The
393returned application will forward all requests to the original
394\var{application}, and will check that both the \var{application} and
395the server invoking it are conforming to the WSGI specification and to
396RFC 2616.
397
398Any detected nonconformance results in an \exception{AssertionError}
399being raised; note, however, that how these errors are handled is
400server-dependent. For example, \module{wsgiref.simple_server} and other
401servers based on \module{wsgiref.handlers} (that don't override the
402error handling methods to do something else) will simply output a
403message that an error has occurred, and dump the traceback to
404\code{sys.stderr} or some other error stream.
405
406This wrapper may also generate output using the \module{warnings} module
407to indicate behaviors that are questionable but which may not actually
408be prohibited by \pep{333}. Unless they are suppressed using Python
409command-line options or the \module{warnings} API, any such warnings
410will be written to \code{sys.stderr} (\emph{not} \code{wsgi.errors},
411unless they happen to be the same object).
412\end{funcdesc}
413
414\subsection{\module{wsgiref.handlers} -- server/gateway base classes}
415\declaremodule{}{wsgiref.handlers}
416
417This module provides base handler classes for implementing WSGI servers
418and gateways. These base classes handle most of the work of
419communicating with a WSGI application, as long as they are given a
420CGI-like environment, along with input, output, and error streams.
421
422
423\begin{classdesc}{CGIHandler}{}
424CGI-based invocation via \code{sys.stdin}, \code{sys.stdout},
425\code{sys.stderr} and \code{os.environ}. This is useful when you have
426a WSGI application and want to run it as a CGI script. Simply invoke
427\code{CGIHandler().run(app)}, where \code{app} is the WSGI application
428object you wish to invoke.
429
430This class is a subclass of \class{BaseCGIHandler} that sets
431\code{wsgi.run_once} to true, \code{wsgi.multithread} to false, and
432\code{wsgi.multiprocess} to true, and always uses \module{sys} and
433\module{os} to obtain the necessary CGI streams and environment.
434\end{classdesc}
435
436
437\begin{classdesc}{BaseCGIHandler}{stdin, stdout, stderr, environ
438\optional{, multithread=True \optional{, multiprocess=False}}}
439
440Similar to \class{CGIHandler}, but instead of using the \module{sys} and
441\module{os} modules, the CGI environment and I/O streams are specified
442explicitly. The \var{multithread} and \var{multiprocess} values are
443used to set the \code{wsgi.multithread} and \code{wsgi.multiprocess}
444flags for any applications run by the handler instance.
445
446This class is a subclass of \class{SimpleHandler} intended for use with
447software other than HTTP ``origin servers''. If you are writing a
448gateway protocol implementation (such as CGI, FastCGI, SCGI, etc.) that
449uses a \code{Status:} header to send an HTTP status, you probably want
450to subclass this instead of \class{SimpleHandler}.
451\end{classdesc}
452
453
454
455\begin{classdesc}{SimpleHandler}{stdin, stdout, stderr, environ
456\optional{,multithread=True \optional{, multiprocess=False}}}
457
458Similar to \class{BaseCGIHandler}, but designed for use with HTTP origin
459servers. If you are writing an HTTP server implementation, you will
460probably want to subclass this instead of \class{BaseCGIHandler}
461
462This class is a subclass of \class{BaseHandler}. It overrides the
463\method{__init__()}, \method{get_stdin()}, \method{get_stderr()},
464\method{add_cgi_vars()}, \method{_write()}, and \method{_flush()}
465methods to support explicitly setting the environment and streams via
466the constructor. The supplied environment and streams are stored in
467the \member{stdin}, \member{stdout}, \member{stderr}, and
468\member{environ} attributes.
469\end{classdesc}
470
471\begin{classdesc}{BaseHandler}{}
472This is an abstract base class for running WSGI applications. Each
473instance will handle a single HTTP request, although in principle you
474could create a subclass that was reusable for multiple requests.
475
476\class{BaseHandler} instances have only one method intended for external
477use:
478
479\begin{methoddesc}{run}{app}
480Run the specified WSGI application, \var{app}.
481\end{methoddesc}
482
483All of the other \class{BaseHandler} methods are invoked by this method
484in the process of running the application, and thus exist primarily to
485allow customizing the process.
486
487The following methods MUST be overridden in a subclass:
488
489\begin{methoddesc}{_write}{data}
490Buffer the string \var{data} for transmission to the client. It's okay
491if this method actually transmits the data; \class{BaseHandler}
492just separates write and flush operations for greater efficiency
493when the underlying system actually has such a distinction.
494\end{methoddesc}
495
496\begin{methoddesc}{_flush}{}
497Force buffered data to be transmitted to the client. It's okay if this
498method is a no-op (i.e., if \method{_write()} actually sends the data).
499\end{methoddesc}
500
501\begin{methoddesc}{get_stdin}{}
502Return an input stream object suitable for use as the \code{wsgi.input}
503of the request currently being processed.
504\end{methoddesc}
505
506\begin{methoddesc}{get_stderr}{}
507Return an output stream object suitable for use as the
508\code{wsgi.errors} of the request currently being processed.
509\end{methoddesc}
510
511\begin{methoddesc}{add_cgi_vars}{}
512Insert CGI variables for the current request into the \member{environ}
513attribute.
514\end{methoddesc}
515
516Here are some other methods and attributes you may wish to override.
517This list is only a summary, however, and does not include every method
518that can be overridden. You should consult the docstrings and source
519code for additional information before attempting to create a customized
520\class{BaseHandler} subclass.
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537Attributes and methods for customizing the WSGI environment:
538
539\begin{memberdesc}{wsgi_multithread}
540The value to be used for the \code{wsgi.multithread} environment
541variable. It defaults to true in \class{BaseHandler}, but may have
542a different default (or be set by the constructor) in the other
543subclasses.
544\end{memberdesc}
545
546\begin{memberdesc}{wsgi_multiprocess}
547The value to be used for the \code{wsgi.multiprocess} environment
548variable. It defaults to true in \class{BaseHandler}, but may have
549a different default (or be set by the constructor) in the other
550subclasses.
551\end{memberdesc}
552
553\begin{memberdesc}{wsgi_run_once}
554The value to be used for the \code{wsgi.run_once} environment
555variable. It defaults to false in \class{BaseHandler}, but
556\class{CGIHandler} sets it to true by default.
557\end{memberdesc}
558
559\begin{memberdesc}{os_environ}
560The default environment variables to be included in every request's
561WSGI environment. By default, this is a copy of \code{os.environ} at
562the time that \module{wsgiref.handlers} was imported, but subclasses can
563either create their own at the class or instance level. Note that the
564dictionary should be considered read-only, since the default value is
565shared between multiple classes and instances.
566\end{memberdesc}
567
568\begin{memberdesc}{server_software}
569If the \member{origin_server} attribute is set, this attribute's value
570is used to set the default \code{SERVER_SOFTWARE} WSGI environment
571variable, and also to set a default \code{Server:} header in HTTP
572responses. It is ignored for handlers (such as \class{BaseCGIHandler}
573and \class{CGIHandler}) that are not HTTP origin servers.
574\end{memberdesc}
575
576
577
578\begin{methoddesc}{get_scheme}{}
579Return the URL scheme being used for the current request. The default
580implementation uses the \function{guess_scheme()} function from
581\module{wsgiref.util} to guess whether the scheme should be ``http'' or
582``https'', based on the current request's \member{environ} variables.
583\end{methoddesc}
584
585\begin{methoddesc}{setup_environ}{}
586Set the \member{environ} attribute to a fully-populated WSGI
587environment. The default implementation uses all of the above methods
588and attributes, plus the \method{get_stdin()}, \method{get_stderr()},
589and \method{add_cgi_vars()} methods and the \member{wsgi_file_wrapper}
590attribute. It also inserts a \code{SERVER_SOFTWARE} key if not present,
591as long as the \member{origin_server} attribute is a true value and the
592\member{server_software} attribute is set.
593\end{methoddesc}
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619Methods and attributes for customizing exception handling:
620
621\begin{methoddesc}{log_exception}{exc_info}
622Log the \var{exc_info} tuple in the server log. \var{exc_info} is a
623\code{(\var{type}, \var{value}, \var{traceback})} tuple. The default
624implementation simply writes the traceback to the request's
625\code{wsgi.errors} stream and flushes it. Subclasses can override this
626method to change the format or retarget the output, mail the traceback
627to an administrator, or whatever other action may be deemed suitable.
628\end{methoddesc}
629
630\begin{memberdesc}{traceback_limit}
631The maximum number of frames to include in tracebacks output by the
632default \method{log_exception()} method. If \code{None}, all frames
633are included.
634\end{memberdesc}
635
636\begin{methoddesc}{error_output}{environ, start_response}
637This method is a WSGI application to generate an error page for the
638user. It is only invoked if an error occurs before headers are sent
639to the client.
640
641This method can access the current error information using
642\code{sys.exc_info()}, and should pass that information to
643\var{start_response} when calling it (as described in the ``Error
644Handling'' section of \pep{333}).
645
646The default implementation just uses the \member{error_status},
647\member{error_headers}, and \member{error_body} attributes to generate
648an output page. Subclasses can override this to produce more dynamic
649error output.
650
651Note, however, that it's not recommended from a security perspective to
652spit out diagnostics to any old user; ideally, you should have to do
653something special to enable diagnostic output, which is why the default
654implementation doesn't include any.
655\end{methoddesc}
656
657
658
659
660\begin{memberdesc}{error_status}
661The HTTP status used for error responses. This should be a status
662string as defined in \pep{333}; it defaults to a 500 code and message.
663\end{memberdesc}
664
665\begin{memberdesc}{error_headers}
666The HTTP headers used for error responses. This should be a list of
667WSGI response headers (\code{(\var{name}, \var{value})} tuples), as
668described in \pep{333}. The default list just sets the content type
669to \code{text/plain}.
670\end{memberdesc}
671
672\begin{memberdesc}{error_body}
673The error response body. This should be an HTTP response body string.
674It defaults to the plain text, ``A server error occurred. Please
675contact the administrator.''
676\end{memberdesc}
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701Methods and attributes for \pep{333}'s ``Optional Platform-Specific File
702Handling'' feature:
703
704\begin{memberdesc}{wsgi_file_wrapper}
705A \code{wsgi.file_wrapper} factory, or \code{None}. The default value
706of this attribute is the \class{FileWrapper} class from
707\module{wsgiref.util}.
708\end{memberdesc}
709
710\begin{methoddesc}{sendfile}{}
711Override to implement platform-specific file transmission. This method
712is called only if the application's return value is an instance of
713the class specified by the \member{wsgi_file_wrapper} attribute. It
714should return a true value if it was able to successfully transmit the
715file, so that the default transmission code will not be executed.
716The default implementation of this method just returns a false value.
717\end{methoddesc}
718
719
720Miscellaneous methods and attributes:
721
722\begin{memberdesc}{origin_server}
723This attribute should be set to a true value if the handler's
724\method{_write()} and \method{_flush()} are being used to communicate
725directly to the client, rather than via a CGI-like gateway protocol that
726wants the HTTP status in a special \code{Status:} header.
727
728This attribute's default value is true in \class{BaseHandler}, but
729false in \class{BaseCGIHandler} and \class{CGIHandler}.
730\end{memberdesc}
731
732\begin{memberdesc}{http_version}
733If \member{origin_server} is true, this string attribute is used to
734set the HTTP version of the response set to the client. It defaults to
735\code{"1.0"}.
736\end{memberdesc}
737
738
739
740
741
742\end{classdesc}
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782