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