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