:mod:`wsgiref` --- WSGI ユーティリティとリファレンス実装
========================================================

.. module:: wsgiref
   :synopsis: WSGI ユーティリティとリファレンス実装
.. moduleauthor:: Phillip J. Eby <pje@telecommunity.com>
.. sectionauthor:: Phillip J. Eby <pje@telecommunity.com>


.. versionadded:: 2.5

.. The Web Server Gateway Interface (WSGI) is a standard interface between web
.. server software and web applications written in Python. Having a standard
.. interface makes it easy to use an application that supports WSGI with a number
.. of different web servers.

Web Server Gateway Interface (WSGI) は、Web サーバソフトウェアと Python で記述された Web
アプリケーションとの標準インターフェースです。標準インターフェースを持つことで、WSGI をサポートするアプリケーションを幾つもの異なる Web
サーバで使うことが容易になります。


.. Only authors of web servers and programming frameworks need to know every detail
.. and corner case of the WSGI design.  You don't need to understand every detail
.. of WSGI just to install a WSGI application or to write a web application using
.. an existing framework.

Web サーバとプログラミングフレームワークの作者だけが、WSGI デザインのあらゆる細部や特例などを知る必要があります。WSGI アプリケーションを
インストールしたり、既存のフレームワークを使ったアプリケーションを記述するだけの皆さんは、全てについて理解する必要はありません。


.. :mod:`wsgiref` is a reference implementation of the WSGI specification that can
.. be used to add WSGI support to a web server or framework.  It provides utilities
.. for manipulating WSGI environment variables and response headers, base classes
.. for implementing WSGI servers, a demo HTTP server that serves WSGI applications,
.. and a validation tool that checks WSGI servers and applications for conformance
.. to the WSGI specification (:pep:`333`).

:mod:`wsgiref` は WSGI 仕様のリファレンス実装で、これは Web サーバやフレームワークに WSGI サポートを加えるのに利用できます。
これは WSGI 環境変数やレスポンスヘッダを操作するユーティリティ、 WSGI サーバ実装時のベースクラス、WSGI アプリケーションを提供する  デモ用
HTTP サーバ、それと WSGI サーバとアプリケーションの WSGI 仕様 (:pep:`333`) 準拠のバリデーションツールを提供します。


.. See http://www.wsgi.org for more information about WSGI, and links to tutorials
   and other resources.

`<http://www.wsgi.org>`_ に、WSGIに関するさらなる情報と、チュートリアルやその他のリソースへのリンクがあります。


.. XXX If you're just trying to write a web application...


:mod:`wsgiref.util` -- WSGI 環境のユーティリティ
------------------------------------------------

.. module:: wsgiref.util
   :synopsis: WSGI 環境のユーティリティ


.. This module provides a variety of utility functions for working with WSGI
.. environments.  A WSGI environment is a dictionary containing HTTP request
.. variables as described in :pep:`333`.  All of the functions taking an *environ*
.. parameter expect a WSGI-compliant dictionary to be supplied; please see
.. :pep:`333` for a detailed specification.

このモジュールは WSGI 環境で使う様々なユーティリティ関数を提供します。 WSGI 環境は :pep:`333` で記述されているような HTTP
リクエスト変数を含む辞書です。全ての *environ* パラメータを取る関数は WSGI 準拠の辞書を与えられることを期待しています；細かい仕様については
:pep:`333` を参照してください。


.. function:: guess_scheme(environ)

   .. Return a guess for whether ``wsgi.url_scheme`` should be "http" or "https", by
   .. checking for a ``HTTPS`` environment variable in the *environ* dictionary.  The
   .. return value is a string.

   *environ* 辞書の ``HTTPS`` 環境変数を調べることで ``wsgi.url_scheme`` が
   "http" か "https" のどちらであるべきか推測し、その結果を返します。
   戻り値は文字列です。


   .. This function is useful when creating a gateway that wraps CGI or a CGI-like
   .. protocol such as FastCGI.  Typically, servers providing such protocols will
   .. include a ``HTTPS`` variable with a value of "1" "yes", or "on" when a request
   .. is received via SSL.  So, this function returns "https" if such a value is
   .. found, and "http" otherwise.

   この関数は、CGI や FastCGI のような CGI に似たプロトコルをラップするゲートウェイを作成する場合に便利です。典型的には、それらのプロトコルを
   提供するサーバが SSL 経由でリクエストを受け取った場合には ``HTTPS`` 変数に値 "1" "yes"、または "on"
   を持つでしょう。そのため、この関数はそのような値が見つかった場合には "https" を返し、そうでなければ "http" を返します。


.. function:: request_uri(environ [, include_query=1])

   .. Return the full request URI, optionally including the query string, using the
   .. algorithm found in the "URL Reconstruction" section of :pep:`333`.  If
   .. *include_query* is false, the query string is not included in the resulting URI.

   リクエスト URI 全体 (オプションでクエリ文字列を含む) を、 :pep:`333` の "URL 再構築(URL Reconstruction)"
   にあるアルゴリズムを使って返します。 *include_query* が false の場合、クエリ文字列は結果となる文字列には含まれません。


.. function:: application_uri(environ)

   .. Similar to :func:`request_uri`, except that the ``PATH_INFO`` and
   .. ``QUERY_STRING`` variables are ignored.  The result is the base URI of the
   .. application object addressed by the request.

   ``PATH_INFO`` と ``QUERY_STRING`` 変数が無視されることを除けば :func:`request_url` に似ています。
   結果はリクエストによって指定されたアプリケーションオブジェクトのベース URI です。


.. function:: shift_path_info(environ)

   .. Shift a single name from ``PATH_INFO`` to ``SCRIPT_NAME`` and return the name.
   .. The *environ* dictionary is *modified* in-place; use a copy if you need to keep
   .. the original ``PATH_INFO`` or ``SCRIPT_NAME`` intact.

   ``PATH_INFO`` から ``SCRIPT_NAME`` に一つの名前をシフトしてその名前を返します。 *environ*
   辞書は *変更されます* \ 。 ``PATH_INFO`` や ``SCRIPT_NAME`` のオリジナルをそのまま残したい場合にはコピーを使ってください。


   .. If there are no remaining path segments in ``PATH_INFO``, ``None`` is returned.

   ``PATH_INFO`` にパスセグメントが何も残っていなければ、 ``None`` が返されます。


   .. Typically, this routine is used to process each portion of a request URI path,
   .. for example to treat the path as a series of dictionary keys. This routine
   .. modifies the passed-in environment to make it suitable for invoking another WSGI
   .. application that is located at the target URI. For example, if there is a WSGI
   .. application at ``/foo``, and the request URI path is ``/foo/bar/baz``, and the
   .. WSGI application at ``/foo`` calls :func:`shift_path_info`, it will receive the
   .. string "bar", and the environment will be updated to be suitable for passing to
   .. a WSGI application at ``/foo/bar``.  That is, ``SCRIPT_NAME`` will change from
   .. ``/foo`` to ``/foo/bar``, and ``PATH_INFO`` will change from ``/bar/baz`` to
   .. ``/baz``.

   典型的なこのルーチンの使い方はリクエスト URI のそれぞれの要素の処理で、例えばパスを一連の辞書のキーとして取り扱う場合です。
   このルーチンは、渡された環境を、ターゲット URL で示される別の WSGI アプリケーションの呼び出しに合うように調整します。例えば、 ``/foo`` に
   WSGI アプリケーションがあったとして、そしてリクエスト URL パスが ``/foo/bar/baz`` で、 ``/foo`` の WSGI
   アプリケーションが :func:`shift_path_info` を呼んだ場合、これは "bar" 文字列を受け取り、 environ は ``/foo/bar`` の
   WSGI アプリケーションへの受け渡しに適するように更新されます。つまり、 ``SCRIPT_NAME`` は ``/foo`` から ``/foo/bar``
   に変わって、 ``PATH_INFO`` は ``/bar/baz`` から ``/baz`` に変化するのです。


   .. When ``PATH_INFO`` is just a "/", this routine returns an empty string and
   .. appends a trailing slash to ``SCRIPT_NAME``, even though empty path segments are
   .. normally ignored, and ``SCRIPT_NAME`` doesn't normally end in a slash.  This is
   .. intentional behavior, to ensure that an application can tell the difference
   .. between URIs ending in ``/x`` from ones ending in ``/x/`` when using this
   .. routine to do object traversal.

   ``PATH_INFO`` が単に "/" の場合、このルーチンは空の文字列を返し、 ``SCRIPT_NAME`` の末尾にスラッシュを加えます、これはたとえ
   空のパスセグメントが通常は無視され、そして ``SCRIPT_NAME`` は通常スラッシュで終わる事が無かったとしてもです。これは意図的な振る舞いで、
   このルーチンでオブジェクト巡回(object traversal) をした場合に ``/x`` で終わる URI と ``/x/`` で終わるものを
   アプリケーションが識別できることを保証するためのものです。


.. function:: setup_testing_defaults(environ)

   .. Update *environ* with trivial defaults for testing purposes.

   *environ* をテスト用に自明なデフォルト値で更新します。


   .. This routine adds various parameters required for WSGI, including ``HTTP_HOST``,
   .. ``SERVER_NAME``, ``SERVER_PORT``, ``REQUEST_METHOD``, ``SCRIPT_NAME``,
   .. ``PATH_INFO``, and all of the :pep:`333`\ -defined ``wsgi.*`` variables.  It
   .. only supplies default values, and does not replace any existing settings for
   .. these variables.

   このルーチンは WSGI に必要な様々なパラメータを追加します。そのようなパラメータとして ``HTTP_HOST`` 、 ``SERVER_NAME`` 、 ``SERVER_PORT`` 、
   ``REQUEST_METHOD`` 、 ``SCRIPT_NAME`` 、 ``PATH_INFO`` 、そして :pep:`333` で定義されている
   ``wsgi.*`` 変数群が含まれます。このルーチンはデフォルト値を提供するだけで、これらの変数の既存設定は一切置きかえません。


   .. This routine is intended to make it easier for unit tests of WSGI servers and
   .. applications to set up dummy environments.  It should NOT be used by actual WSGI
   .. servers or applications, since the data is fake!

   このルーチンは、ダミー環境をセットアップすることによって WSGI サーバとアプリケーションのユニットテストを容易にすることを意図しています。これは実際の
   WSGI サーバやアプリケーションで使うべきではありません。なぜならこのデータは偽物なのです！


   .. Example usage:

   利用例:


   ::

      from wsgiref.util import setup_testing_defaults
      from wsgiref.simple_server import make_server

      # 比較的シンプルなWSGIアプリケーション。 setup_testing_defaults に
      # よって更新されたあとの environment 辞書を表示する
      def simple_app(environ, start_response):
          setup_testing_defaults(environ)

          status = '200 OK'
          headers = [('Content-type', 'text/plain')]

          start_response(status, headers)

          ret = ["%s: %s\n" % (key, value)
                 for key, value in environ.iteritems()]
          return ret

      httpd = make_server('', 8000, simple_app)
      print "Serving on port 8000..."
      httpd.serve_forever()


.. In addition to the environment functions above, the :mod:`wsgiref.util` module
.. also provides these miscellaneous utilities:

上記の環境用関数に加えて、 :mod:`wsgiref.util` モジュールも以下のようなその他のユーティリティを提供します：


.. function:: is_hop_by_hop(header_name)

   .. Return true if 'header_name' is an HTTP/1.1 "Hop-by-Hop" header, as defined by
   .. :rfc:`2616`.

   'header_name' が :rfc:`2616` で定義されている HTTP/1.1 の "Hop-by-Hop" ヘッダの場合に true
   を返します。


.. class:: FileWrapper(filelike [, blksize=8192])

   .. A wrapper to convert a file-like object to an :term:`iterator`.  The resulting objects
   .. support both :meth:`__getitem__` and :meth:`__iter__` iteration styles, for
   .. compatibility with Python 2.1 and Jython. As the object is iterated over, the
   .. optional *blksize* parameter will be repeatedly passed to the *filelike*
   .. object's :meth:`read` method to obtain strings to yield.  When :meth:`read`
   .. returns an empty string, iteration is ended and is not resumable.

   ファイル風オブジェクトをイテレータ(:term:`iterator`)に変換するラッパです。結果のオブジェクトは :meth:`__getitem__` と :meth:`__iter__`
   両方をサポートしますが、これは Python 2.1 と Jython の互換性のためです。オブジェクトがイテレートされる間、オプションの
   *blksize* パラメータがくり返し *filelike* オブジェクトの :meth:`read` メソッドに渡されて
   受け渡す文字列を取得します。 :meth:`read` が空文字列を返した場合、イテレーションは終了して再開されることはありません。


   .. If *filelike* has a :meth:`close` method, the returned object will also have a
   .. :meth:`close` method, and it will invoke the *filelike* object's :meth:`close`
   .. method when called.

   *filelike* に :meth:`close` メソッドがある場合、返されたオブジェクトも :meth:`close`
   メソッドを持ち、これが呼ばれた場合には *filelike* オブジェクトの :meth:`close` メソッドを呼び出します。


   .. Example usage:

   利用例:


   ::

      from StringIO import StringIO
      from wsgiref.util import FileWrapper

      # ファイル風オブジェクトとして StringIO バッファを使用しています
      filelike = StringIO("This is an example file-like object"*10)
      wrapper = FileWrapper(filelike, blksize=5)

      for chunk in wrapper:
          print chunk



:mod:`wsgiref.headers` -- WSGI レスポンスヘッダツール群
-------------------------------------------------------

.. module:: wsgiref.headers
   :synopsis: WSGI レスポンスヘッダツール群


.. This module provides a single class, :class:`Headers`, for convenient
.. manipulation of WSGI response headers using a mapping-like interface.

このモジュールは単一のクラス、 :class:`Headers` を提供し、WSGI レスポンスヘッダの操作をマップに似たインターフェースで便利にします。


.. class:: Headers(headers)

   .. Create a mapping-like object wrapping *headers*, which must be a list of header
   .. name/value tuples as described in :pep:`333`.  Any changes made to the new
   .. :class:`Headers` object will directly update the *headers* list it was created
   .. with.

   *headers* をラップするマップ風オブジェクトを生成します。これは :pep:`333` に定義されるようなヘッダの名前／値のタプルのリストです。
   新しい :class:`Headers` オブジェクトに与えられた変更は、一緒に作成された *headers* リストを直接更新します。


   .. :class:`Headers` objects support typical mapping operations including
   .. :meth:`__getitem__`, :meth:`get`, :meth:`__setitem__`, :meth:`setdefault`,
   .. :meth:`__delitem__`, :meth:`__contains__` and :meth:`has_key`.  For each of
   .. these methods, the key is the header name (treated case-insensitively), and the
   .. value is the first value associated with that header name.  Setting a header
   .. deletes any existing values for that header, then adds a new value at the end of
   .. the wrapped header list.  Headers' existing order is generally maintained, with
   .. new headers added to the end of the wrapped list.

   :class:`Headers` オブジェクトは典型的なマッピング操作をサポートし、これには
   :meth:`__getitem__` 、 :meth:`get` 、 :meth:`__setitem__` 、
   :meth:`setdefault` 、 :meth:`__delitem__` 、 :meth:`__contains__` と :meth:`has_key`
   を含みます。これらメソッドのそれぞれにおいて、キーはヘッダ名で（大文字小文字は区別しません）、値はそのヘッダ名に関連づけられた
   最初の値です。ヘッダを設定すると既存のヘッダ値は削除され、ラップされたヘッダのリストの末尾に新しい値が加えられます。既存のヘッダの順番は
   一般に維持され、ラップされたリストの最後に新しいヘッダが追加されます。


   .. Unlike a dictionary, :class:`Headers` objects do not raise an error when you try
   .. to get or delete a key that isn't in the wrapped header list. Getting a
   .. nonexistent header just returns ``None``, and deleting a nonexistent header does
   .. nothing.

   辞書とは違って、 :class:`Headers` オブジェクトはラップされたヘッダリストに
   存在しないキーを取得または削除しようとした場合にもエラーを発生しません。単に、存在しないヘッダの取得は ``None`` を返し、存在しないヘッダの削除は
   何もしません。


   .. :class:`Headers` objects also support :meth:`keys`, :meth:`values`, and
   .. :meth:`items` methods.  The lists returned by :meth:`keys` and :meth:`items` can
   .. include the same key more than once if there is a multi-valued header.  The
   .. ``len()`` of a :class:`Headers` object is the same as the length of its
   .. :meth:`items`, which is the same as the length of the wrapped header list.  In
   .. fact, the :meth:`items` method just returns a copy of the wrapped header list.

   :class:`Headers` オブジェクトは :meth:`keys` 、 :meth:`values` 、 :meth:`items` メソッドもサポートします。
   複数の値を持つヘッダがある場合には、 :meth:`keys` と :meth:`items` で返されるリストは同じキーを一つ以上含むことがあります。
   :class:`Header` オブジェクトの ``len()`` は、その :meth:`items` の長さと同じであり、ラップされたヘッダリストの長さと同じです。
   実際、 :meth:`items` メソッドは単にラップされたヘッダリストのコピーを返しているだけです。


   .. Calling ``str()`` on a :class:`Headers` object returns a formatted string
   .. suitable for transmission as HTTP response headers.  Each header is placed on a
   .. line with its value, separated by a colon and a space. Each line is terminated
   .. by a carriage return and line feed, and the string is terminated with a blank
   .. line.

   :class:`Headers` オブジェクトに対して ``str()`` を呼ぶと、HTTP レスポンスヘッダとして
   送信するのに適した形に整形された文字列を返します。それぞれのヘッダはコロンとスペースで区切られた値と共に一列に並んでいます。
   それぞれの行はキャリッジリターンとラインフィードで終了し、文字列は空行で終了しています。


   .. In addition to their mapping interface and formatting features, :class:`Headers`
   .. objects also have the following methods for querying and adding multi-valued
   .. headers, and for adding headers with MIME parameters:

   これらのマッピングインターフェースと整形機能に加えて、 :class:`Headers` オブジェクトは複数の値を持つヘッダの取得と追加、MIME
   パラメータでヘッダを追加するための以下のようなメソッド群も持っています：


   .. method:: Headers.get_all(name)

      .. Return a list of all the values for the named header.

      指定されたヘッダの全ての値のリストを返します。


      .. The returned list will be sorted in the order they appeared in the original
      .. header list or were added to this instance, and may contain duplicates.  Any
      .. fields deleted and re-inserted are always appended to the header list.  If no
      .. fields exist with the given name, returns an empty list.

      返されるリストは、元々のヘッダリストに現れる順、またはこのインスタンスに追加された順に並んでいて、重複を含む場合があります。削除されて加えられた
      フィールドは全てヘッダリストの末尾に付きます。与えられた name に対するフィールドが何もなければ、空のリストが返ります。


   .. method:: Headers.add_header(name, value, **_params)

      .. Add a (possibly multi-valued) header, with optional MIME parameters specified
      .. via keyword arguments.

      (複数の値を持つ可能性のある) ヘッダを、キーワード引数を通じて指定するオプションの MIME パラメータと共に追加します。

      .. *name* is the header field to add.  Keyword arguments can be used to set MIME
      .. parameters for the header field.  Each parameter must be a string or ``None``.
      .. Underscores in parameter names are converted to dashes, since dashes are illegal
      .. in Python identifiers, but many MIME parameter names include dashes.  If the
      .. parameter value is a string, it is added to the header value parameters in the
      .. form ``name="value"``. If it is ``None``, only the parameter name is added.
      .. (This is used for MIME parameters without a value.)  Example usage:

      *name* は追加するヘッダフィールドです。このヘッダフィールドに MIME パラメータを設定するために
      キーワード引数を使うことができます。それぞれのパラメータは文字列か ``None`` でなければいけません。
      パラメータ中のアンダースコアはダッシュ (-) に変換されます。
      これは、ダッシュが Python の識別子としては不正なのですが、多くの MIME パラメータはダッシュを含むためです。
      パラメータ値が文字列の場合、これはヘッダ値のパラメータに ``name="value"`` の形で追加されます。
      この値がもし ``None`` の場合、パラメータ名だけが追加されます。
      （これは値なしの MIME パラメータの場合に使われます。）使い方の例は、


      ::

         h.add_header('content-disposition', 'attachment', filename='bud.gif')


      .. The above will add a header that looks like this:

      上記はこのようなヘッダを追加します


      ::

         Content-Disposition: attachment; filename="bud.gif"


:mod:`wsgiref.simple_server` -- シンプルな WSGI HTTP サーバ
-----------------------------------------------------------

.. module:: wsgiref.simple_server
   :synopsis: シンプルな WSGI HTTP サーバ


.. This module implements a simple HTTP server (based on :mod:`BaseHTTPServer`)
.. that serves WSGI applications.  Each server instance serves a single WSGI
.. application on a given host and port.  If you want to serve multiple
.. applications on a single host and port, you should create a WSGI application
.. that parses ``PATH_INFO`` to select which application to invoke for each
.. request.  (E.g., using the :func:`shift_path_info` function from
.. :mod:`wsgiref.util`.)

このモジュールは WSGI アプリケーションを提供するシンプルな HTTP サーバです (:mod:`BaseHTTPServer` がベースです)。
個々のサーバインスタンスは単一の WSGI アプリケーションを、特定のホストとポート上で
提供します。もし一つのホストとポート上で複数のアプリケーションを提供したいならば、 ``PATH_INFO``
をパースして個々のリクエストでどのアプリケーションを呼び出すか選択するような WSGI アプリケーションを作る必要があります。
（例えば、 :mod:`wsgiref.util` から :func:`shift_path_info` を利用します。）


.. function:: make_server(host, port, app [, server_class=WSGIServer [, handler_class=WSGIRequestHandler]])

   .. Create a new WSGI server listening on *host* and *port*, accepting connections
   .. for *app*.  The return value is an instance of the supplied *server_class*, and
   .. will process requests using the specified *handler_class*.  *app* must be a WSGI
   .. application object, as defined by :pep:`333`.

   *host* と *port* 上で待機し、 *app* へのコネクションを受け付ける  WSGI サーバを作成します。戻り値は与えられた
   *server_class* のインスタンスで、指定された *handler_class* を使ってリクエストを処理します。 *app* は
   :pep:`333` で定義されるところの WSGI アプリケーションでなければいけません。


   .. Example usage:

   使用例：


   ::

      from wsgiref.simple_server import make_server, demo_app

      httpd = make_server('', 8000, demo_app)
      print "Serving HTTP on port 8000..."

      # プロセスが kill されるまでリクエストに応える
      httpd.serve_forever()

      # 代替：１つのリクエストを受けて終了する
      httpd.handle_request()


.. function:: demo_app(environ, start_response)

   .. This function is a small but complete WSGI application that returns a text page
   .. containing the message "Hello world!" and a list of the key/value pairs provided
   .. in the *environ* parameter.  It's useful for verifying that a WSGI server (such
   .. as :mod:`wsgiref.simple_server`) is able to run a simple WSGI application
   .. correctly.

   この関数は小規模ながら完全な WSGI アプリケーションで、 "Hello world!" メッセージと、 *environ* パラメータに提供されている
   キー／値のペアを含むテキストページを返します。これは WSGI サーバ (:mod:`wsgiref.simple_server` のような) がシンプルな
   WSGI アプリケーションを正しく実行できるかを確かめるのに便利です。


.. class:: WSGIServer(server_address, RequestHandlerClass)

   .. Create a :class:`WSGIServer` instance.  *server_address* should be a
   .. ``(host,port)`` tuple, and *RequestHandlerClass* should be the subclass of
   .. :class:`BaseHTTPServer.BaseHTTPRequestHandler` that will be used to process
   .. requests.

   :class:`WSGIServer` インスタンスを作成します。 *server_address* は ``(host,port)`` のタプル、そして
   *RequesthandlerClass* はリクエストの処理に使われる
   :class:`BaseHTTPServer.BaseHTTPRequestHandler` のサブクラスでなければいけません。


   .. You do not normally need to call this constructor, as the :func:`make_server`
   .. function can handle all the details for you.

   :func:`make_server` が細かい調整をやってくれるので、通常はこのコンストラクタを呼ぶ必要はありません。


   .. :class:`WSGIServer` is a subclass of :class:`BaseHTTPServer.HTTPServer`, so all
   .. of its methods (such as :meth:`serve_forever` and :meth:`handle_request`) are
   .. available. :class:`WSGIServer` also provides these WSGI-specific methods:

   :class:`WSGIServer` は :class:`BaseHTTPServer.HTTPServer` のサブクラスなので、
   その全てのメソッド (:meth:`serve_forever` や :meth:`handle_request` のような) が利用できます。
   :class:`WSGIServer` も以下のような WSGI 固有メソッドを提供します：


   .. method:: WSGIServer.set_app(application)

      .. Sets the callable *application* as the WSGI application that will receive
      .. requests.

      呼び出し可能 (callable) な *application* をリクエストを受け取る WSGI アプリケーションとして設定します。


   .. method:: WSGIServer.get_app()

      .. Returns the currently-set application callable.

      現在設定されている呼び出し可能 (callable) アプリケーションを返します。


   .. Normally, however, you do not need to use these additional methods, as
   .. :meth:`set_app` is normally called by :func:`make_server`, and the
   .. :meth:`get_app` exists mainly for the benefit of request handler instances.

   しかしながら、通常はこれらの追加されたメソッドを使う必要はありません。 :meth:`set_app` は普通は :func:`make_server`
   によって呼ばれ、 :meth:`get_app` は主にリクエストハンドラインスタンスの便宜上存在するからです。


.. class:: WSGIRequestHandler(request, client_address, server)

   .. Create an HTTP handler for the given *request* (i.e. a socket), *client_address*
   .. (a ``(host,port)`` tuple), and *server* (:class:`WSGIServer` instance).

   与えられた *request* （すなわちソケット）の HTTP ハンドラ、 *client_address*  (``(host,port)`` のタプル)、
   *server*  (:class:`WSGIServer` インスタンス) の HTTP ハンドラを作成します。


   .. You do not need to create instances of this class directly; they are
   .. automatically created as needed by :class:`WSGIServer` objects.  You can,
   .. however, subclass this class and supply it as a *handler_class* to the
   .. :func:`make_server` function.  Some possibly relevant methods for overriding in
   .. subclasses:

   このクラスのインスタンスを直接生成する必要はありません；これらは必要に応じて :class:`WSGIServer`
   オブジェクトによって自動的に生成されます。しかしながら、このクラスをサブクラス化し、 :func:`make_server` 関数に
   *handler_class* として与えることは可能でしょう。サブクラスにおいてオーバーライドする意味のありそうなものは：


   .. method:: WSGIRequestHandler.get_environ()

      .. Returns a dictionary containing the WSGI environment for a request.  The default
      .. implementation copies the contents of the :class:`WSGIServer` object's
      .. :attr:`base_environ` dictionary attribute and then adds various headers derived
      .. from the HTTP request.  Each call to this method should return a new dictionary
      .. containing all of the relevant CGI environment variables as specified in
      .. :pep:`333`.

      リクエストに対する WSGI 環境を含む辞書を返します。デフォルト実装では :class:`WSGIServer` オブジェクトの
      :attr:`base_environ` 辞書属性のコンテンツをコピーし、それから HTTP リクエスト由来の様々なヘッダを追加しています。
      このメソッド呼び出し毎に、 :pep:`333` に指定されている関連する CGI 環境変数を全て含む新規の辞書を返さなければいけません。


   .. method:: WSGIRequestHandler.get_stderr()

      .. Return the object that should be used as the ``wsgi.errors`` stream. The default
      .. implementation just returns ``sys.stderr``.

      ``wsgi.errors`` ストリームとして使われるオブジェクトを返します。デフォルト実装では単に ``sys.stderr`` を返します。


   .. method:: WSGIRequestHandler.handle()

      .. Process the HTTP request.  The default implementation creates a handler instance
      .. using a :mod:`wsgiref.handlers` class to implement the actual WSGI application
      .. interface.

      HTTP リクエストを処理します。デフォルト実装では実際の WGI アプリケーションインターフェースを実装するのに
      :mod:`wsgiref.handlers` クラスを使ってハンドラインスタンスを作成します。


:mod:`wsgiref.validate` --- WSGI 準拠チェッカー
------------------------------------------------

.. module:: wsgiref.validate
   :synopsis: WSGI 準拠チェッカー


.. When creating new WSGI application objects, frameworks, servers, or middleware,
.. it can be useful to validate the new code's conformance using
.. :mod:`wsgiref.validate`.  This module provides a function that creates WSGI
.. application objects that validate communications between a WSGI server or
.. gateway and a WSGI application object, to check both sides for protocol
.. conformance.

WSGI アプリケーションのオブジェクト、フレームワーク、サーバまたはミドルウェアの作成時には、その新規のコードを
:mod:`wsgiref.validate` を使って準拠の検証をすると便利です。このモジュールは WSGI サーバやゲートウェイと WSGI
アプリケーションオブジェクト間の通信を検証する WSGI アプリケーションオブジェクトを作成する関数を提供し、双方のプロトコル準拠をチェックします。


.. Note that this utility does not guarantee complete :pep:`333` compliance; an
.. absence of errors from this module does not necessarily mean that errors do not
.. exist.  However, if this module does produce an error, then it is virtually
.. certain that either the server or application is not 100% compliant.

このユーティリティは完全な :pep:`333` 準拠を保証するものでないことは注意してください；
このモジュールでエラーが出ないことは必ずしもエラーが存在しないことを意味しません。
しかしこのモジュールがエラーを出したならば、ほぼ確実にサーバかアプリケーションのどちらかが 100% 準拠ではありません。


.. This module is based on the :mod:`paste.lint` module from Ian Bicking's "Python
.. Paste" library.

このモジュールは lan Bicking の "Python Paste" ライブラリの  :mod:`paste.lint`
モジュールをベースにしています。


.. function:: validator(application)

   .. Wrap *application* and return a new WSGI application object.  The returned
   .. application will forward all requests to the original *application*, and will
   .. check that both the *application* and the server invoking it are conforming to
   .. the WSGI specification and to RFC 2616.

   *application* をラップし、新しい WSGI アプリケーションオブジェクトを返します。返されたアプリケーションは全てのリクエストを元々の
   *application* に転送し、 *application* とそれを呼び出すサーバの両方が WSGI 仕様と RFC 2616
   の両方に準拠しているかをチェックします。


   .. Any detected nonconformance results in an :exc:`AssertionError` being raised;
   .. note, however, that how these errors are handled is server-dependent.  For
   .. example, :mod:`wsgiref.simple_server` and other servers based on
   .. :mod:`wsgiref.handlers` (that don't override the error handling methods to do
   .. something else) will simply output a message that an error has occurred, and
   .. dump the traceback to ``sys.stderr`` or some other error stream.

   何らかの非準拠が検出されると、 :exc:`AssertionError` 例外が送出されます；
   しかし、このエラーがどう扱われるかはサーバ依存であることに注意してください。例えば、 :mod:`wsgiref.simple_server` とその他
   :mod:`wsgiref.handlers` ベースのサーバ（エラー処理メソッドが他のことをするようにオーバライドしていないもの）は
   単純にエラーが発生したというメッセージとトレースバックのダンプを ``sys.stderr`` やその他のエラーストリームに出力します。


   .. This wrapper may also generate output using the :mod:`warnings` module to
   .. indicate behaviors that are questionable but which may not actually be
   .. prohibited by :pep:`333`.  Unless they are suppressed using Python command-line
   .. options or the :mod:`warnings` API, any such warnings will be written to
   .. ``sys.stderr`` (*not* ``wsgi.errors``, unless they happen to be the same
   .. object).

   このラッパは、疑わしいものの実際には :pep:`333` で禁止されていないかもしれない挙動を指摘するために
   :mod:`warnings` モジュールを使って出力を生成します。
   これらは Python のコマンドラインオプションや :mod:`warnings` API で抑制されなければ、
   ``sys.stderr`` (``wsgi.errors`` では *ありません* 。ただし、たまたま同一のオブジェクトだった場合を除く)に書き出されます。


   .. Example usage:

   利用例:


   ::

      from wsgiref.validate import validator
      from wsgiref.simple_server import make_server

      # 意図的に規格に準拠していない callable
      # バリデーションは失敗する
      def simple_app(environ, start_response):
          status = '200 OK' # HTTP Status
          headers = [('Content-type', 'text/plain')] # HTTP Headers
          start_response(status, headers)

          # リストを返す必要があるので、これは規格違反です。
          # バリデータはそれを教えてくれるでしょう。
          return "Hello World"

      # これはバリデータでラップされたアプリケーションです
      validator_app = validator(simple_app)

      httpd = make_server('', 8000, validator_app)
      print "Listening on port 8000...."
      httpd.serve_forever()


:mod:`wsgiref.handlers` -- サーバ／ゲートウェイのベースクラス
-------------------------------------------------------------

.. module:: wsgiref.handlers
   :synopsis: WSGI サーバ／ゲートウェイのベースクラス


.. This module provides base handler classes for implementing WSGI servers and
.. gateways.  These base classes handle most of the work of communicating with a
.. WSGI application, as long as they are given a CGI-like environment, along with
.. input, output, and error streams.

このモジュールは WSGI サーバとゲートウェイ実装のベースハンドラクラスを提供します。
これらのベースクラスは、 CGI 風の環境と、それに加えて入力、出力そしてエラーストリームが与えられることで、
WSGI アプリケーションとの通信の大部分を処理します。


.. class:: CGIHandler()

   .. CGI-based invocation via ``sys.stdin``, ``sys.stdout``, ``sys.stderr`` and
   .. ``os.environ``.  This is useful when you have a WSGI application and want to run
   .. it as a CGI script.  Simply invoke ``CGIHandler().run(app)``, where ``app`` is
   .. the WSGI application object you wish to invoke.

   ``sys.stdin`` 、 ``sys.stdout`` 、 ``stderr`` そして ``os.environ`` 経由での CGI
   ベースの呼び出しです。これは、もしあなたが WSGI アプリケーションを持っていて、これを CGI スクリプトとして実行したい場合に有用です。単に
   ``CGIHandler().run(app)`` を起動してください。 ``app`` はあなたが起動したい WSGI アプリケーションオブジェクトです。


   .. This class is a subclass of :class:`BaseCGIHandler` that sets ``wsgi.run_once``
   .. to true, ``wsgi.multithread`` to false, and ``wsgi.multiprocess`` to true, and
   .. always uses :mod:`sys` and :mod:`os` to obtain the necessary CGI streams and
   .. environment.

   このクラスは :class:`BaseCGIHandler` のサブクラスで、これは ``wsgi.run_once`` を true、
   ``wsgi.multithread`` を false、そして ``wsgi.multiprocess`` を true にセットし、常に
   :mod:`sys` と :mod:`os` を、必要な CGI ストリームと環境を取得するために使用します。


.. class:: BaseCGIHandler(stdin, stdout, stderr, environ [, multithread=True [, multiprocess=False]])

   .. Similar to :class:`CGIHandler`, but instead of using the :mod:`sys` and
   .. :mod:`os` modules, the CGI environment and I/O streams are specified explicitly.
   .. The *multithread* and *multiprocess* values are used to set the
   .. ``wsgi.multithread`` and ``wsgi.multiprocess`` flags for any applications run by
   .. the handler instance.

   :class:`CGIHandler` に似ていますが、 :mod:`sys` と :mod:`os` モジュールを使う代わりに CGI 環境と I/O
   ストリームを明示的に指定します。 *multithread* と *multiprocess* の値は、ハンドラインスタンスにより実行されるアプリケーションの
   ``wsgi.multithread`` と ``wsgi.multiprocess`` フラグの設定に使われます。


   .. This class is a subclass of :class:`SimpleHandler` intended for use with
   .. software other than HTTP "origin servers".  If you are writing a gateway
   .. protocol implementation (such as CGI, FastCGI, SCGI, etc.) that uses a
   .. ``Status:`` header to send an HTTP status, you probably want to subclass this
   .. instead of :class:`SimpleHandler`.

   このクラスは :class:`SimpleHandler` のサブクラスで、HTTP の "本サーバ" でない
   ソフトウェアと使うことを意図しています。もしあなたが ``Status:`` ヘッダを HTTP ステータスを送信するのに使うような
   ゲートウェイプロトコルの実装（CGI、FastCGI、SCGIなど）を書いている場合、おそらく :class:`SimpleHandler`
   ではなくこのクラスをサブクラス化するとよいでしょう。


.. class:: SimpleHandler(stdin, stdout, stderr, environ [,multithread=True [, multiprocess=False]])

   .. Similar to :class:`BaseCGIHandler`, but designed for use with HTTP origin
   .. servers.  If you are writing an HTTP server implementation, you will probably
   .. want to subclass this instead of :class:`BaseCGIHandler`

   :class:`BaseCGIHandler` と似ていますが、HTTP の本サーバと使うためにデザインされています。もしあなたが HTTP
   サーバ実装を書いている場合、おそらく :class:`BaseCGIHandler` ではなくこのクラスをサブクラス化するとよいでしょう。


   .. This class is a subclass of :class:`BaseHandler`.  It overrides the
   .. :meth:`__init__`, :meth:`get_stdin`, :meth:`get_stderr`, :meth:`add_cgi_vars`,
   .. :meth:`_write`, and :meth:`_flush` methods to support explicitly setting the
   .. environment and streams via the constructor.  The supplied environment and
   .. streams are stored in the :attr:`stdin`, :attr:`stdout`, :attr:`stderr`, and
   .. :attr:`environ` attributes.

   このクラスは :class:`BaseHandler` のサブクラスです。これは :meth:`__init__` 、
   :meth:`get_stdin` 、 :meth:`get_stderr` 、 :meth:`add_cgi_vars` 、 :meth:`_write` 、
   :meth:`_flush` をオーバーライドして、コンストラクタから明示的に環境とストリームを設定するようにしています。与えられた環境とストリームは
   :attr:`stdin` 、 :attr:`stdout` 、 :attr:`stderr` それに :attr:`environ` 属性に保存されています。


.. class:: BaseHandler()

   .. This is an abstract base class for running WSGI applications.  Each instance
   .. will handle a single HTTP request, although in principle you could create a
   .. subclass that was reusable for multiple requests.

   これは WSGI アプリケーションを実行するための抽象ベースクラスです。
   それぞれのインスタンスは一つの HTTP リクエストを処理します。
   しかし原理上は複数のリクエスト用に再利用可能なサブクラスを作成することができます。


   .. :class:`BaseHandler` instances have only one method intended for external use:

   :class:`BaseHandler` インスタンスは外部から利用されるたった一つのメソッドを持ちます：


   .. method:: BaseHandler.run(app)

      .. Run the specified WSGI application, *app*.

      指定された WSGI アプリケーション、 *app* を実行します。


   .. All of the other :class:`BaseHandler` methods are invoked by this method in the
   .. process of running the application, and thus exist primarily to allow
   .. customizing the process.

   その他の全ての :class:`BaseHandler` のメソッドはアプリケーション実行プロセスで
   このメソッドから呼ばれます。したがって、それらは主にそのプロセスのカスタマイズのために存在しています。


   .. The following methods MUST be overridden in a subclass:

   以下のメソッドはサブクラスでオーバーライドされなければいけません：


   .. method:: BaseHandler._write(data)

      .. Buffer the string *data* for transmission to the client.  It's okay if this
      .. method actually transmits the data; :class:`BaseHandler` just separates write
      .. and flush operations for greater efficiency when the underlying system actually
      .. has such a distinction.

      文字列の *data* をクライアントへの転送用にバッファします。このメソッドが実際にデータを転送しても OK です：
      下部システムが実際にそのような区別をしている場合に効率をより良くするために、 :class:`BaseHandler`
      は書き出しとフラッシュ操作を分けているからです。


   .. method:: BaseHandler._flush()

      .. Force buffered data to be transmitted to the client.  It's okay if this method
      .. is a no-op (i.e., if :meth:`_write` actually sends the data).

      バッファされたデータをクライアントに強制的に転送します。このメソッドは何もしなくても OK です（すなわち、 :meth:`_write`
      が実際にデータを送る場合）。


   .. method:: BaseHandler.get_stdin()

      .. Return an input stream object suitable for use as the ``wsgi.input`` of the
      .. request currently being processed.

      現在処理中のリクエストの ``wsgi.input`` としての利用に適当な入力ストリームオブジェクトを返します。


   .. method:: BaseHandler.get_stderr()

      .. Return an output stream object suitable for use as the ``wsgi.errors`` of the
      .. request currently being processed.

      現在処理中のリクエストの ``wsgi.errors`` としての利用に適当な出力ストリームオブジェクトを返します。


   .. method:: BaseHandler.add_cgi_vars()

      .. Insert CGI variables for the current request into the :attr:`environ` attribute.

      現在のリクエストの CGI 変数を :attr:`environ` 属性に追加します。


   .. Here are some other methods and attributes you may wish to override. This list
   .. is only a summary, however, and does not include every method that can be
   .. overridden.  You should consult the docstrings and source code for additional
   .. information before attempting to create a customized :class:`BaseHandler`
   .. subclass.

   オーバーライドされることの多いメソッド及び属性を以下に挙げます。
   しかし、このリストは単にサマリであり、オーバーライド可能な全てのメソッドは含んでいません。
   カスタマイズした :class:`BaseHandler` サブクラスを作成しようとする前に docstring やソースコードでさらなる情報を調べてください。


   .. Attributes and methods for customizing the WSGI environment:

   WSGI 環境のカスタマイズのための属性とメソッド：


   .. attribute:: BaseHandler.wsgi_multithread

      .. The value to be used for the ``wsgi.multithread`` environment variable.  It
      .. defaults to true in :class:`BaseHandler`, but may have a different default (or
      .. be set by the constructor) in the other subclasses.

      ``wsgi.multithread`` 環境変数で使われる値。 :class:`BaseHandler` ではデフォルトが true
      ですが、別のサブクラスではデフォルトで（またはコンストラクタによって設定されて）異なる値を持つことがあります。


   .. attribute:: BaseHandler.wsgi_multiprocess

      .. The value to be used for the ``wsgi.multiprocess`` environment variable.  It
      .. defaults to true in :class:`BaseHandler`, but may have a different default (or
      .. be set by the constructor) in the other subclasses.

      ``wsgi.multiprocess`` 環境変数で使われる値。 :class:`BaseHandler` ではデフォルトが true
      ですが、別のサブクラスではデフォルトで（またはコンストラクタによって設定されて）異なる値を持つことがあります。


   .. attribute:: BaseHandler.wsgi_run_once

      .. The value to be used for the ``wsgi.run_once`` environment variable.  It
      .. defaults to false in :class:`BaseHandler`, but :class:`CGIHandler` sets it to
      .. true by default.

      ``wsgi.run_once`` 環境変数で使われる値。 :class:`BaseHandler` ではデフォルトが false
      ですが、 :class:`CGIHandler` はデフォルトでこれを true に設定します。


   .. attribute:: BaseHandler.os_environ

      .. The default environment variables to be included in every request's WSGI
      .. environment.  By default, this is a copy of ``os.environ`` at the time that
      .. :mod:`wsgiref.handlers` was imported, but subclasses can either create their own
      .. at the class or instance level.  Note that the dictionary should be considered
      .. read-only, since the default value is shared between multiple classes and
      .. instances.

      全てのリクエストの WSGI 環境に含まれるデフォルトの環境変数。デフォルトでは :mod:`wsgiref.handlers` がインポートされた時点の
      ``os.environ`` のコピーですが、サブクラスはクラスまたはインスタンスレベルでそれら自身のものを作ることができます。
      デフォルト値は複数のクラスとインスタンスで共有されるため、この辞書は読み取り専用と考えるべきだという点に注意してください。


   .. attribute:: BaseHandler.server_software

      .. If the :attr:`origin_server` attribute is set, this attribute's value is used to
      .. set the default ``SERVER_SOFTWARE`` WSGI environment variable, and also to set a
      .. default ``Server:`` header in HTTP responses.  It is ignored for handlers (such
      .. as :class:`BaseCGIHandler` and :class:`CGIHandler`) that are not HTTP origin
      .. servers.

      :attr:`origin_server` 属性が設定されている場合、この属性の値がデフォルトの ``SERVER_SOFTWARE`` WSGI
      環境変数の設定や HTTP レスポンス中のデフォルトの ``Server:``
      ヘッダの設定に使われます。これは (:class:`BaseCGIHandler` や :class:`CGIHandler` のような) HTTP
      オリジンサーバでないハンドラでは無視されます。


   .. method:: BaseHandler.get_scheme()

      .. Return the URL scheme being used for the current request.  The default
      .. implementation uses the :func:`guess_scheme` function from :mod:`wsgiref.util`
      .. to guess whether the scheme should be "http" or "https", based on the current
      .. request's :attr:`environ` variables.

      現在のリクエストで使われている URL スキームを返します。デフォルト実装は :mod:`wsgiref.util` の
      :func:`guess_scheme` を使い、現在のリクエストの :attr:`envion` 変数に基づいてスキームが"http" か "https"
      かを推測します。


   .. method:: BaseHandler.setup_environ()

      .. Set the :attr:`environ` attribute to a fully-populated WSGI environment.  The
      .. default implementation uses all of the above methods and attributes, plus the
      .. :meth:`get_stdin`, :meth:`get_stderr`, and :meth:`add_cgi_vars` methods and the
      .. :attr:`wsgi_file_wrapper` attribute.  It also inserts a ``SERVER_SOFTWARE`` key
      .. if not present, as long as the :attr:`origin_server` attribute is a true value
      .. and the :attr:`server_software` attribute is set.

      :attr:`environ` 属性を、フル実装 (fully-populated) の WSGI 環境に設定します。デフォルトの実装は、上記全てのメソッドと属性、加えて
      :meth:`get_stdin` 、 :meth:`get_stderr` 、 :meth:`add_cgi_vars` メソッドと
      :attr:`wsgi_file_wrapper` 属性を利用します。これは、キーが存在せず、 :attr:`origin_server` 属性が true
      値で :attr:`server_software` 属性も設定されている場合に ``SERVER_SOFTWARE`` を挿入します。


   .. Methods and attributes for customizing exception handling:

   例外処理のカスタマイズのためのメソッドと属性：


   .. method:: BaseHandler.log_exception(exc_info)

      .. Log the *exc_info* tuple in the server log.  *exc_info* is a ``(type, value,
      .. traceback)`` tuple.  The default implementation simply writes the traceback to
      .. the request's ``wsgi.errors`` stream and flushes it.  Subclasses can override
      .. this method to change the format or retarget the output, mail the traceback to
      .. an administrator, or whatever other action may be deemed suitable.

      *exec_info* タプルをサーバログに記録します。 *exc_info* は ``(type, value, traceback)`` のタプルです。
      デフォルトの実装は単純にトレースバックをリクエストの ``wsgi.errors`` ストリームに
      書き出してフラッシュします。サブクラスはこのメソッドをオーバーライドしてフォーマットを変更したり出力先の変更、トレースバックを管理者にメールしたり
      その他適切と思われるいかなるアクションも取ることができます。


   .. attribute:: BaseHandler.traceback_limit

      .. The maximum number of frames to include in tracebacks output by the default
      .. :meth:`log_exception` method.  If ``None``, all frames are included.

      デフォルトの :meth:`log_exception` メソッドで出力されるトレースバック出力に含まれる最大のフレーム数です。 ``None`` ならば、
      全てのフレームが含まれます。


   .. method:: BaseHandler.error_output(environ, start_response)

      .. This method is a WSGI application to generate an error page for the user.  It is
      .. only invoked if an error occurs before headers are sent to the client.

      このメソッドは、ユーザに対してエラーページを出力する WSGI アプリケーションです。これはクライアントにヘッダが送出される前にエラーが発生した場合にのみ
      呼び出されます。


      .. This method can access the current error information using ``sys.exc_info()``,
      .. and should pass that information to *start_response* when calling it (as
      .. described in the "Error Handling" section of :pep:`333`).

      このメソッドは ``sys.exc_info()`` を使って現在のエラー情報にアクセスでき、その情報はこれを呼ぶときに *start_response* に
      渡すべきです (:pep:`333` の "Error Handling" セクションに記述があります)。


      .. The default implementation just uses the :attr:`error_status`,
      .. :attr:`error_headers`, and :attr:`error_body` attributes to generate an output
      .. page.  Subclasses can override this to produce more dynamic error output.

      デフォルト実装は単に :attr:`error_status` 、 :attr:`error_headers` 、 :attr:`error_body`
      属性を出力ページの生成に使います。サブクラスではこれをオーバーライドしてもっと動的なエラー出力をすることができます。


      .. Note, however, that it's not recommended from a security perspective to spit out
      .. diagnostics to any old user; ideally, you should have to do something special to
      .. enable diagnostic output, which is why the default implementation doesn't
      .. include any.

      しかし、セキュリティの観点からは診断をあらゆるユーザに吐き出すことは推奨されないことに気をつけてください；理想的には、診断的な出力を有効に
      するには何らかの特別なことをする必要があるようにすべきで、これがデフォルト実装では何も含まれていない理由です。


   .. attribute:: BaseHandler.error_status

      .. The HTTP status used for error responses.  This should be a status string as
      .. defined in :pep:`333`; it defaults to a 500 code and message.

      エラーレスポンスで使われる HTTP ステータスです。これは :pep:`333` で定義されているステータス文字列です；デフォルトは 500
      コードとメッセージです。


   .. attribute:: BaseHandler.error_headers

      .. The HTTP headers used for error responses.  This should be a list of WSGI
      .. response headers (``(name, value)`` tuples), as described in :pep:`333`.  The
      .. default list just sets the content type to ``text/plain``.

      エラーレスポンスで使われる HTTP ヘッダです。これは :pep:`333` で述べられているような、 WSGI レスポンスヘッダ (``(name,
      value)`` タプル) のリストであるべきです。デフォルトのリストはコンテントタイプを ``text/plain`` にセットしているだけです。


   .. attribute:: BaseHandler.error_body

      .. The error response body.  This should be an HTTP response body string. It
      .. defaults to the plain text, "A server error occurred.  Please contact the
      .. administrator."

      エラーレスポンスボディ。これは HTTP レスポンスのボディ文字列であるべきです。これはデフォルトではプレーンテキストで "A server error
      occurred.  Please contact the administrator." です。


   .. Methods and attributes for :pep:`333`'s "Optional Platform-Specific File
   .. Handling" feature:

   :pep:`333` の "オプションのプラットフォーム固有のファイルハンドリング" 機能のためのメソッドと属性：


   .. attribute:: BaseHandler.wsgi_file_wrapper

      .. A ``wsgi.file_wrapper`` factory, or ``None``.  The default value of this
      .. attribute is the :class:`FileWrapper` class from :mod:`wsgiref.util`.

      ``wsgi.file_wrapper`` ファクトリ、または ``None`` です。この属性のデフォルト値は :mod:`wsgiref.util` の
      :class:`FileWrapper` クラスです。


   .. method:: BaseHandler.sendfile()

      .. Override to implement platform-specific file transmission.  This method is
      .. called only if the application's return value is an instance of the class
      .. specified by the :attr:`wsgi_file_wrapper` attribute.  It should return a true
      .. value if it was able to successfully transmit the file, so that the default
      .. transmission code will not be executed. The default implementation of this
      .. method just returns a false value.

      オーバーライドしてプラットフォーム固有のファイル転送を実装します。このメソッドはアプリケーションの戻り値が :attr:`wsgi_file_wrapper`
      属性で指定されたクラスのインスタンスの場合にのみ呼ばれます。これはファイルの転送が成功できた場合には true を返して、デフォルトの転送コードが
      実行されないようにするべきです。このデフォルトの実装は単に false 値を返します。


   .. Miscellaneous methods and attributes:

   その他のメソッドと属性：


   .. attribute:: BaseHandler.origin_server

      .. This attribute should be set to a true value if the handler's :meth:`_write` and
      .. :meth:`_flush` are being used to communicate directly to the client, rather than
      .. via a CGI-like gateway protocol that wants the HTTP status in a special
      .. ``Status:`` header.

      この属性はハンドラの :meth:`_write` と :meth:`_flush` が、特別に ``Status:`` ヘッダに HTTP
      ステータスを求めるような CGI 風のゲートウェイプロトコル経由でなく、クライアントと直接通信をするような場合には true 値に設定されているべきです。


      .. This attribute's default value is true in :class:`BaseHandler`, but false in
      .. :class:`BaseCGIHandler` and :class:`CGIHandler`.

      この属性のデフォルト値は :class:`BaseHandler` では true ですが、 :class:`BaseCGIHandler` と
      :class:`CGIHandler` では false です。


   .. attribute:: BaseHandler.http_version

      .. If :attr:`origin_server` is true, this string attribute is used to set the HTTP
      .. version of the response set to the client.  It defaults to ``"1.0"``.

      :attr:`origin_server` が true の場合、この文字列属性はクライアントへのレスポンスセットの HTTP
      バージョンの設定に使われます。デフォルトは ``"1.0"`` です。


例
--------

.. This is a working "Hello World" WSGI application:

これは動作する "Hello World" WSGIアプリケーションです。


::

   from wsgiref.simple_server import make_server

   # 全ての WSGI アプリケーションには application オブジェクト - 2つの
   # 引数を受け取る callable オブジェクトが必要です。この目的のために、
   # ここでは関数を使用しています (関数に限らず、例えばクラスを使用できる
   # ことに注意してください)。関数に渡された最初の引数は CGI スタイルの
   # 環境変数を含む辞書であり、 2 番目の変数は callable オブジェクトです
   # (:pep:`333` を見てください)。
   def hello_world_app(environ, start_response):
       status = '200 OK' # HTTP Status
       headers = [('Content-type', 'text/plain')] # HTTP Headers
       start_response(status, headers)

       # 返されたオブジェクトは表示されます
       return ["Hello World"]

   httpd = make_server('', 8000, hello_world_app)
   print "Serving on port 8000..."

   # プロセスが kill されるまで実行する
   httpd.serve_forever()
