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