[Pythonjp-checkins] [python-doc-ja] push by anywa****@gmail***** - 訳文の修正 on 2011-05-20 11:13 GMT

Back to archive index

pytho****@googl***** pytho****@googl*****
2011年 5月 20日 (金) 20:14:31 JST


Revision: f9e491f1506c
Author:   Akihiro Uchida <uchid****@ike-d*****>
Date:     Fri May 20 00:15:12 2011
Log:      訳文の修正
http://code.google.com/p/python-doc-ja/source/detail?r=f9e491f1506c

Modified:
  /howto/curses.rst
  /howto/regex.rst
  /howto/unicode.rst
  /howto/urllib2.rst
  /howto/webservers.rst

=======================================
--- /howto/curses.rst	Sat Dec  4 02:43:38 2010
+++ /howto/curses.rst	Fri May 20 00:15:12 2011
@@ -426,7 +426,7 @@
  Because the curses API is so large, some functions aren't supported in the
  Python interface, not because they're difficult to implement, but because  
no one
  has needed them yet.  Feel free to add them and then submit a patch.   
Also, we
-don't yet have support for the menus or panels libraries associated with
+don't yet have support for the menu library associated with
  ncurses; feel free to add that.

  If you write an interesting little program, feel free to contribute it as
=======================================
--- /howto/regex.rst	Sat Dec  4 02:43:38 2010
+++ /howto/regex.rst	Fri May 20 00:15:12 2011
@@ -1,8 +1,13 @@
  .. _regex-howto:

-***********************************
-  Regular Expression HOWTO (英語)
-***********************************
+..
+  ****************************
+    Regular Expression HOWTO
+  ****************************
+
+******************
+  正規表現 HOWTO
+******************

  :Author: A.M. Kuchling
  :Release: 0.05
@@ -14,24 +19,52 @@
     Unicode (at least a reference)


-.. topic:: Abstract
-
-   This document is an introductory tutorial to using regular expressions  
in Python
-   with the :mod:`re` module.  It provides a gentler introduction than the
-   corresponding section in the Library Reference.
-
-
-Introduction
-============
-
-The :mod:`re` module was added in Python 1.5, and provides Perl-style  
regular
-expression patterns.  Earlier versions of Python came with the :mod:`regex`
-module, which provided Emacs-style patterns.  The :mod:`regex` module was
-removed completely in Python 2.5.
-
-Regular expressions (called REs, or regexes, or regex patterns) are  
essentially
-a tiny, highly specialized programming language embedded inside Python and  
made
-available through the :mod:`re` module. Using this little language, you  
specify
+
+..
+  .. topic:: Abstract
+
+     This document is an introductory tutorial to using regular  
expressions in Python
+     with the :mod:`re` module.  It provides a gentler introduction than  
the
+     corresponding section in the Library Reference.
+
+.. topic:: 概要
+
+   このドキュメントは :mod:`re` モジュールを使って Python で正規表現を扱う 
ための
+   導入のチュートリアルです。
+   ライブラリレファレンスの正規表現の節よりもやさしい入門ドキュメントを容易 
しています。
+
+..
+  Introduction
+  ============
+
+導入
+====
+
+..
+  The :mod:`re` module was added in Python 1.5, and provides Perl-style  
regular
+  expression patterns.  Earlier versions of Python came with  
the :mod:`regex`
+  module, which provided Emacs-style patterns.  The :mod:`regex` module was
+  removed completely in Python 2.5.
+
+:mod:`re` モジュール Python 1.5 で追加され、Perl スタイルの正規表現パターン 
を提供します。
+それ以前の Python では :mod:`regex` モジュールが Emacs スタイルのパターンを 
提供していました。
+:mod:`regex` モジュールは Python 2.5 で完全に削除されました。
+
+..
+  Regular expressions (called REs, or regexes, or regex patterns) are  
essentially
+  a tiny, highly specialized programming language embedded inside Python  
and made
+  available through the :mod:`re` module. Using this little language, you  
specify
+  the rules for the set of possible strings that you want to match; this  
set might
+  contain English sentences, or e-mail addresses, or TeX commands, or  
anything you
+  like.  You can then ask questions such as "Does this string match the  
pattern?",
+  or "Is there a match for the pattern anywhere in this string?".  You can  
also
+  use REs to modify a string or to split it apart in various ways.
+
+正規表現 regular expressions (REs や regexes または regex patterns と呼ばれ 
ます) は
+本質的に小さく、Python 内部に埋め込まれた高度に特化したプログラミング言語で
+:mod:`re` モジュールから利用可能です。
+この小さな言語を利用することで、
+you specify
  the rules for the set of possible strings that you want to match; this set  
might
  contain English sentences, or e-mail addresses, or TeX commands, or  
anything you
  like.  You can then ask questions such as "Does this string match the  
pattern?",
@@ -257,14 +290,14 @@
  Compiling Regular Expressions
  -----------------------------

-Regular expressions are compiled into :class:`RegexObject` instances,  
which have
+Regular expressions are compiled into pattern objects, which have
  methods for various operations such as searching for pattern matches or
  performing string substitutions. ::

     >>> import re
     >>> p = re.compile('ab*')
     >>> print p
-   <re.RegexObject instance at 80b4150>
+   <_sre.SRE_Pattern object at 80b4150>

  :func:`re.compile` also accepts an optional *flags* argument, used to  
enable
  various special features and syntax variations.  We'll go over the  
available
@@ -336,7 +369,7 @@
  ------------------

  Once you have an object representing a compiled regular expression, what  
do you
-do with it?  :class:`RegexObject` instances have several methods and  
attributes.
+do with it?  Pattern objects have several methods and attributes.
  Only the most significant ones will be covered here; consult the :mod:`re`  
docs
  for a complete listing.

@@ -427,8 +460,8 @@
  and :meth:`end` return the starting and ending index of the  
match. :meth:`span`
  returns both start and end indexes in a single tuple.  Since  
the :meth:`match`
  method only checks if the RE matches at the start of a  
string, :meth:`start`
-will always be zero.  However, the :meth:`search` method  
of :class:`RegexObject`
-instances scans through the string, so  the match may not start at zero in  
that
+will always be zero.  However, the :meth:`search` method of patterns
+scans through the string, so  the match may not start at zero in that
  case. ::

     >>> print p.match('::: message')
@@ -450,7 +483,7 @@
     else:
         print 'No match'

-Two :class:`RegexObject` methods return all of the matches for a pattern.
+Two pattern methods return all of the matches for a pattern.
  :meth:`findall` returns a list of matching strings::

     >>> p = re.compile('\d+')
@@ -475,10 +508,10 @@
  Module-Level Functions
  ----------------------

-You don't have to create a :class:`RegexObject` and call its methods; the
+You don't have to create a pattern object and call its methods; the
  :mod:`re` module also provides top-level functions called :func:`match`,
  :func:`search`, :func:`findall`, :func:`sub`, and so forth.  These  
functions
-take the same arguments as the corresponding :class:`RegexObject` method,  
with
+take the same arguments as the corresponding pattern method, with
  the RE string added as the first argument, and still return either  
``None`` or a
  :class:`MatchObject` instance. ::

@@ -487,12 +520,12 @@
     >>> re.match(r'From\s+', 'From amk Thu May 14 19:12:10 1998')
     <re.MatchObject instance at 80c5978>

-Under the hood, these functions simply produce a :class:`RegexObject` for  
you
+Under the hood, these functions simply create a pattern object for you
  and call the appropriate method on it.  They also store the compiled  
object in a
  cache, so future calls using the same RE are faster.

  Should you use these module-level functions, or should you get the
-:class:`RegexObject` and call its methods yourself?  That choice depends  
on how
+pattern and call its methods yourself?  That choice depends on how
  frequently the RE will be used, and on your personal coding style.  If the  
RE is
  being used at only one point in the code, then the module functions are  
probably
  more convenient.  If a program contains a lot of regular expressions, or  
re-uses
@@ -1018,7 +1051,7 @@

  Up to this point, we've simply performed searches against a static string.
  Regular expressions are also commonly used to modify strings in various  
ways,
-using the following :class:`RegexObject` methods:
+using the following pattern methods:

  +------------------+-----------------------------------------------+
  | Method/Attribute | Purpose                                       |
@@ -1038,7 +1071,7 @@
  Splitting Strings
  -----------------

-The :meth:`split` method of a :class:`RegexObject` splits a string apart
+The :meth:`split` method of a pattern splits a string apart
  wherever the RE matches, returning a list of the pieces. It's similar to  
the
  :meth:`split` method of strings but provides much more generality in the
  delimiters that you can split by; :meth:`split` only supports splitting by
@@ -1183,10 +1216,10 @@
     'Call 0xffd2 for printing, 0xc000 for user code.'

  When using the module-level :func:`re.sub` function, the pattern is passed  
as
-the first argument.  The pattern may be a string or  
a :class:`RegexObject`; if
+the first argument.  The pattern may be provided as an object or as a  
string; if
  you need to specify regular expression flags, you must either use a
-:class:`RegexObject` as the first parameter, or use embedded modifiers in  
the
-pattern, e.g.  ``sub("(?i)b+", "x", "bbbb BBBB")`` returns ``'x x'``.
+pattern object as the first parameter, or use embedded modifiers in the
+pattern string, e.g. ``sub("(?i)b+", "x", "bbbb BBBB")`` returns ``'x x'``.


  Common Problems
=======================================
--- /howto/unicode.rst	Fri May 20 00:14:47 2011
+++ /howto/unicode.rst	Fri May 20 00:15:12 2011
@@ -34,7 +34,7 @@

  1968年に American Standard Code for Information Interchange が標準化されま 
した。
  頭文字の ASCII でよく知られています。
-ASCII は0から127までの、異なる文字の数値コードを定義しています。
+ASCII は0から127までの、異なる文字の数値コードを定義していて、
  例えば、小文字の 'a' にはコード値 97 が割り当てられています。

  ..
@@ -45,10 +45,10 @@
    as 'naïve' and 'café', and some publications have house styles which  
require
    spellings such as 'coöperate'.)

-ASCII はアメリカの開発標準だったのでアクセント無しの文字のみを定義していま 
した。
+ASCII はアメリカの開発標準だったのでアクセント無しの文字のみを定義してい 
て、
  'e' はありましたが、'é' や 'Í' はありませんでした。
  つまり、アクセント付きの文字を必要とする言語は ASCII できちんと表現するとが 
できません。
-(実際には英語でもアクセント無しという問題はありました、
+(実際には英語でもアクセント無いために起きる問題がありました、
  'naïve' や 'café' のようなアクセントを含む単語や、
  いくつかの出版社は 'coöperate' のような独自のスタイルのつづりを必要とするな 
ど)

@@ -57,9 +57,9 @@
    looking at Apple ][ BASIC programs, published in French-language  
publications in
    the mid-1980s, that had lines like these::

-しばらくの間は単のアクセントが表示されないプログラムを書きました。
+しばらくの間は単にアクセントが表示されないプログラムを書きました。
  1980年半ばのフランス語で出版された Apple ][ の BASIC プログラムを見た記憶を 
辿ると、
-そこにはこんな行がありました::
+そこにはこんな行が含んでいました::

  	PRINT "FICHER EST COMPLETE."
  	PRINT "CARACTERE NON ACCEPTE."
@@ -81,13 +81,12 @@
    and some were **de facto** conventions that were invented by one company  
or
    another and managed to catch on.

-1980年代には、多くのパーソナルコンピューターは 8-bit でした、
+1980年代には、多くのパーソナルコンピューターは 8-bit で、
  つまり 8-bit で 0-255 までの値を確保することができました。
  ASCII コードは 127 までだったので、いくつかのマシンは 128 から 255 の値を
  アクセント付きの文字に割り当てました。
-マシン毎に異なる文字コードを持っていました、
-しかし、そのせいでファイル交換の問題が起きました。
-結局、128-255 の間の値はよく使われる集合がたくさん現われることになりまし 
た。
+マシン毎に異なる文字コードがあり、そのためにファイル交換の問題が起きること 
となりました。
+結局、128-255 の間の値は多くのよく使われる集合が現われることになりました。
  そのうちいくつかは International Standards Organzation の定める本当の標準に 
なり、
  またいくつかは一社で開発され、別の会社へと流行することで **事実上の** 慣習 
となりました。

@@ -705,7 +704,8 @@
    can also assemble strings using the :func:`unichr` built-in function,  
but this is
    even more tedious.

-127 より大きいコードポイントに対してエスケープシーケンスを使うのはあまり多 
くないうちは有効ですが、
+127 より大きいコードポイントに対してエスケープシーケンスを使うのは、
+エスケープシーケンスがあまり多くないうちは有効ですが、
  フランス語等のアクセントを使う言語でメッセージのような多くのアクセント文字 
を使う場合には邪魔になります。
  文字を :func:`unichr` 組み込み関数を使って組み上げることもできますが、それ 
はさらに長くなってしまうでしょう。

@@ -1040,7 +1040,7 @@
  通常 Unicode 文字列をシステム依存のエンコーディングに変換することによって実 
装されています。
  例えば、Mac OS X は UTF-8 を利用し、Windows ではエンコーディングが設定で変 
更することが可能です;
  Windows では Python は "mbcs" という名前に現在設定されているエンコーディン 
グを問い合わせて利用します。
-Unix システムでは ``LANG`` や ``LC_CTYPE``` 環境変数を設定していれば、
+Unix システムでは ``LANG`` や ``LC_CTYPE`` 環境変数を設定していれば、
  それだけがファイルシステムのエンコーディングとなります;
  もしエンコーディングを設定しなければ、デフォルトエンコーディングは ASCII に 
なります。

@@ -1156,10 +1156,10 @@
  この問題を見逃がすのは簡単です、ソフトウェアに対してアクセントを含まない 
データのみでテストを行なえばよいのです;
  全てはうまく動作しているように見えます、
  しかし実際には最初に 127 より大きい文字を試みたユーザにバグが待ち構えている 
ことになります。
-第二の助言は::
+第二の助言は:

      テストデータには 127 より大きい文字を含み、
-    さらに 255 より大きいの文字を含むことが望ましい。
+    さらに 255 より大きい文字を含むことが望ましい。

  ..
    When using data coming from a web browser or some other untrusted  
source, a
=======================================
--- /howto/urllib2.rst	Sat Dec  4 02:43:38 2010
+++ /howto/urllib2.rst	Fri May 20 00:15:12 2011
@@ -182,10 +182,9 @@
  Handling Exceptions
  ===================

-*urlopen* raises :exc:`URLError` when it cannot handle a response (though  
as usual
-with Python APIs, builtin exceptions such as
-:exc:`ValueError`, :exc:`TypeError` etc. may also
-be raised).
+*urlopen* raises :exc:`URLError` when it cannot handle a response (though  
as
+usual with Python APIs, built-in exceptions such as :exc:`ValueError`,
+:exc:`TypeError` etc. may also be raised).

  :exc:`HTTPError` is the subclass of :exc:`URLError` raised in the specific  
case of
  HTTP URLs.
@@ -311,7 +310,7 @@
      >>> req = urllib2.Request('http://www.python.org/fish.html')
      >>> try:
      >>>     urllib2.urlopen(req)
-    >>> except URLError, e:
+    >>> except HTTPError, e:
      >>>     print e.code
      >>>     print e.read()
      >>>
@@ -488,7 +487,7 @@

  .. note::

-    In the above example we only supplied our ``HHTPBasicAuthHandler`` to
+    In the above example we only supplied our ``HTTPBasicAuthHandler`` to
      ``build_opener``. By default openers have the handlers for normal  
situations
      -- ``ProxyHandler``, ``UnknownHandler``, ``HTTPHandler``,
      ``HTTPDefaultErrorHandler``, ``HTTPRedirectHandler``, ``FTPHandler``,
=======================================
--- /howto/webservers.rst	Sat Dec  4 02:43:38 2010
+++ /howto/webservers.rst	Fri May 20 00:15:12 2011
@@ -6,74 +6,75 @@

  .. topic:: Abstract

-   This document shows how Python fits into the web.  It presents some  
ways on
-   how to integrate Python with the web server and general practices  
useful for
+   This document shows how Python fits into the web.  It presents some ways
+   to integrate Python with a web server, and general practices useful for
     developing web sites.


-Programming for the Web has become a hot topic since the raise of the "Web  
2.0",
+Programming for the Web has become a hot topic since the rise of "Web 2.0",
  which focuses on user-generated content on web sites.  It has always been
  possible to use Python for creating web sites, but it was a rather tedious  
task.
-Therefore, many so-called "frameworks" and helper tools were created to  
help
-developers creating sites faster and these sites being more robust.  This  
HOWTO
-describes some of the methods used to combine Python with a web server to  
create
-dynamic content.  It is not meant as a general introduction as this topic  
is far
-too broad to be covered in one single document.  However, a short overview  
of
-the most popular libraries is provided.
+Therefore, many frameworks and helper tools have been created to assist
+developers in creating faster and more robust sites.  This HOWTO describes
+some of the methods used to combine Python with a web server to create
+dynamic content.  It is not meant as a complete introduction, as this  
topic is
+far too broad to be covered in one single document.  However, a short  
overview
+of the most popular libraries is provided.

  .. seealso::

-   While this HOWTO tries to give an overview over Python in the Web, it  
cannot
-   always be as up to date as desired.  Web development in Python is moving
-   forward rapidly, so the wiki page on `Web Programming
-   <http://wiki.python.org/moin/WebProgramming>`_ might be more in sync  
with
+   While this HOWTO tries to give an overview of Python in the web, it  
cannot
+   always be as up to date as desired.  Web development in Python is  
rapidly
+   moving forward, so the wiki page on `Web Programming
+   <http://wiki.python.org/moin/WebProgramming>`_ may be more in sync with
     recent development.


-The low-level view
+The Low-Level View
  ==================

-.. .. image:: http.png
-
-When a user enters a web site, his browser makes a connection to the site's
-webserver (this is called the *request*).  The server looks up the file in  
the
+When a user enters a web site, their browser makes a connection to the  
site's
+web server (this is called the *request*).  The server looks up the file  
in the
  file system and sends it back to the user's browser, which displays it  
(this is
-the *response*).  This is roughly how the unterlying protocol, HTTP works.
-
-Now, dynamic web sites are not files in the file system, but rather  
programs
-which are run by the web server when a request comes in.  They can do all  
sorts
-of useful things, like display the postings of a bulletin board, show your
-mails, configurate software or just display the current time.  These  
programs
-can be written in about any programming language the server supports, so  
it is
-easy to use Python for creating dynamic web sites.
-
-As most of HTTP servers are written in C or C++, they cannot execute  
Python code
-in a simple way -- a bridge is needed between the server and the program.   
These
-bridges or rather interfaces define how programs interact with the  
server.  In
-the past there have been numerous attempts to create the best possible
-interface, but there are only a few worth mentioning.
-
-Not every web server supports every interface.  Many web servers do  
support only
-old, now-obsolete interfaces.  But they can often be extended using some
-third-party modules to support new interfaces.
+the *response*).  This is roughly how the underlying protocol, HTTP, works.
+
+Dynamic web sites are not based on files in the file system, but rather on
+programs which are run by the web server when a request comes in, and which
+*generate* the content that is returned to the user.  They can do all  
sorts of
+useful things, like display the postings of a bulletin board, show your  
email,
+configure software, or just display the current time.  These programs can  
be
+written in any programming language the server supports.  Since most  
servers
+support Python, it is easy to use Python to create dynamic web sites.
+
+Most HTTP servers are written in C or C++, so they cannot execute Python  
code
+directly -- a bridge is needed between the server and the program.  These
+bridges, or rather interfaces, define how programs interact with the  
server.
+There have been numerous attempts to create the best possible interface,  
but
+there are only a few worth mentioning.
+
+Not every web server supports every interface.  Many web servers only  
support
+old, now-obsolete interfaces; however, they can often be extended using
+third-party modules to support newer ones.


  Common Gateway Interface
  ------------------------

-This interface is the oldest one, supported by nearly every web server out  
of
-the box.  Programs using CGI to communicate with their web server need to  
be
-started by the server for every request.  So, every request starts a new  
Python
-interpreter -- which takes some time to start up -- thus making the whole
-interface only usable for low load situations.
-
-The upside of CGI is that it is simple -- writing a program which uses CGI  
is a
-matter of about three lines of code.  But this simplicity comes at a  
price: it
-does very few things to help the developer.
-
-Writing CGI programs, while still possible, is not recommended anymore.   
With
-WSGI (more on that later) it is possible to write programs that emulate  
CGI, so
-they can be run as CGI if no better option is available.
+This interface, most commonly referred to as "CGI", is the oldest, and is
+supported by nearly every web server out of the box.  Programs using CGI to
+communicate with their web server need to be started by the server for  
every
+request.  So, every request starts a new Python interpreter -- which takes  
some
+time to start up -- thus making the whole interface only usable for low  
load
+situations.
+
+The upside of CGI is that it is simple -- writing a Python program which  
uses
+CGI is a matter of about three lines of code.  This simplicity comes at a
+price: it does very few things to help the developer.
+
+Writing CGI programs, while still possible, is no longer recommended.  With
+:ref:`WSGI <WSGI>`, a topic covered later in this document, it is possible  
to write
+programs that emulate CGI, so they can be run as CGI if no better option is
+available.

  .. seealso::

@@ -81,7 +82,7 @@
     creating plain CGI programs:

     * :mod:`cgi` -- Handling of user input in CGI scripts
-   * :mod:`cgitb` -- Displays nice tracebacks when errors happen in of CGI
+   * :mod:`cgitb` -- Displays nice tracebacks when errors happen in CGI
       applications, instead of presenting a "500 Internal Server Error"  
message

     The Python wiki features a page on `CGI scripts
@@ -99,23 +100,23 @@
      # -*- coding: UTF-8 -*-

      # enable debugging
-    import cgitb; cgitb.enable()
+    import cgitb
+    cgitb.enable()

      print "Content-Type: text/plain;charset=utf-8"
      print

      print "Hello World!"

-You need to write this code into a file with a ``.py`` or ``.cgi``  
extension,
-this depends on your web server configuration.  Depending on your web  
server
-configuration, this file may also need to be in a ``cgi-bin`` folder, for
-security reasons.
+Depending on your web server configuration, you may need to save this code  
with
+a ``.py`` or ``.cgi`` extension.  Additionally, this file may also need to  
be
+in a ``cgi-bin`` folder, for security reasons.

  You might wonder what the ``cgitb`` line is about.  This line makes it  
possible
  to display a nice traceback instead of just crashing and displaying  
an "Internal
  Server Error" in the user's browser.  This is useful for debugging, but it  
might
-risk exposing some confident data to the user.  Don't use it when the  
script is
-ready for production use.  Still, you should *always* catch exceptions, and
+risk exposing some confidential data to the user.  You should not use  
``cgitb``
+in production code for this reason.  You should *always* catch exceptions,  
and
  display proper error pages -- end-users don't like to see  
nondescript "Internal
  Server Errors" in their browsers.

@@ -124,73 +125,83 @@
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  If you don't have your own web server, this does not apply to you.  You can
-check whether if works as-is and if not you need to talk to the  
administrator of
-your web server anyway. If it is a big hoster, you can try filing a ticket
-asking for Python support.
-
-If you're your own administrator or want to install it for testing  
purposes on
-your own computers, you have to configure it by yourself.  There is no one  
and
-single way on how to configure CGI, as there are many web servers with  
different
-configuration options.  The currently most widely used free web server is
-`Apache HTTPd <http://httpd.apache.org/>`_, Apache for short -- this is  
the one
-that most people use, it can be easily installed on nearly every system  
using
-the systems' package management.  But `lighttpd  
<http://www.lighttpd.net>`_ has
-been gaining attention since some time and is said to have a better  
performance.
-On many systems this server can also be installed using the package  
management,
-so manually compiling the web server is never needed.
-
-* On Apache you can take a look into the `Dynamic Content with CGI
+check whether it works as-is, and if not you will need to talk to the
+administrator of your web server. If it is a big host, you can try filing a
+ticket asking for Python support.
+
+If you are your own administrator or want to set up CGI for testing  
purposes on
+your own computers, you have to configure it by yourself.  There is no  
single
+way to configure CGI, as there are many web servers with different
+configuration options.  Currently the most widely used free web server is
+`Apache HTTPd <http://httpd.apache.org/>`_, or Apache for short. Apache  
can be
+easily installed on nearly every system using the system's package  
management
+tool.  `lighttpd <http://www.lighttpd.net>`_ is another alternative and is
+said to have better performance.  On many systems this server can also be
+installed using the package management tool, so manually compiling the web
+server may not be needed.
+
+* On Apache you can take a look at the `Dynamic Content with CGI
    <http://httpd.apache.org/docs/2.2/howto/cgi.html>`_ tutorial, where  
everything
    is described.  Most of the time it is enough just to set ``+ExecCGI``.   
The
    tutorial also describes the most common gotchas that might arise.
+
  * On lighttpd you need to use the `CGI module
-  <http://trac.lighttpd.net/trac/wiki/Docs%3AModCGI>`_ which can be  
configured
+  <http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModCGI>`_\ , which can  
be configured
    in a straightforward way.  It boils down to setting ``cgi.assign``  
properly.


  Common problems with CGI scripts
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

-Trying to use CGI sometimes leads to small annoyances that one might  
experience
-while trying to get these scripts to run.  Sometimes it happens that a  
seemingly
-correct script does not work as expected, which is caused by some small  
hidden
-reason that's difficult to spot.
-
-Some of these reasons are:
-
-* The Python script is not marked executable.  When CGI scripts are not
-  executable most of the web servers will let the user download it,  
instead of
+Using CGI sometimes leads to small annoyances while trying to get these
+scripts to run.  Sometimes a seemingly correct script does not work as
+expected, the cause being some small hidden problem that's difficult to  
spot.
+
+Some of these potential problems are:
+
+* The Python script is not marked as executable.  When CGI scripts are not
+  executable most web servers will let the user download it, instead of
    running it and sending the output to the user.  For CGI scripts to run
-  properly the ``+x`` bit needs to be set.  Using ``chmod a+x  
your_script.py``
-  might already solve the problem.
-* The line endings must be of Unix-type.  This is important because the web
-  server checks the first line of the script (called shebang) and tries to  
run
-  the program specified there.  It gets easily confused by Windows line  
endings
-  (Carriage Return & Line Feed, also called CRLF), so you have to convert  
the
-  file to Unix line endings (only Line Feed, LF).  This can be done
-  automatically by uploading the file via FTP in text mode instead of  
binary
-  mode, but the preferred way is just telling your editor to save the  
files with
-  Unix line endings.  Most proper editors support this.
-* Your web server must be able to read the file, you need to make sure the
-  permissions are fine.  Often the server runs as user and group  
``www-data``,
-  so it might be worth a try to change the file ownership or making the  
file
-  world readable by using ``chmod a+r your_script.py``.
-* The webserver must be able to know that the file you're trying to access  
is a
-  CGI script.  Check the configuration of your web server, maybe there is  
some
-  mistake.
-* The path to the interpreter in the shebang (``#!/usr/bin/env python``)  
must be
-  currect.  This line calls ``/usr/bin/env`` to find Python, but it'll  
fail if
-  there is no ``/usr/bin/env``.  If you know where your Python is  
installed, you
-  can also use that path.  The commands ``whereis python`` and ``type -p
-  python`` might also help to find where it is installed.  Once this is  
known,
-  the shebang line can be changed accordingly: ``#!/usr/bin/python``.
+  properly on Unix-like operating systems, the ``+x`` bit needs to be set.
+  Using ``chmod a+x your_script.py`` may solve this problem.
+
+* On a Unix-like system, The line endings in the program file must be Unix
+  style line endings.  This is important because the web server checks the
+  first line of the script (called shebang) and tries to run the program
+  specified there.  It gets easily confused by Windows line endings  
(Carriage
+  Return & Line Feed, also called CRLF), so you have to convert the file to
+  Unix line endings (only Line Feed, LF).  This can be done automatically  
by
+  uploading the file via FTP in text mode instead of binary mode, but the
+  preferred way is just telling your editor to save the files with Unix  
line
+  endings.  Most editors support this.
+
+* Your web server must be able to read the file, and you need to make sure  
the
+  permissions are correct.  On unix-like systems, the server often runs as  
user
+  and group ``www-data``, so it might be worth a try to change the file
+  ownership, or making the file world readable by using ``chmod a+r
+  your_script.py``.
+
+* The web server must know that the file you're trying to access is a CGI  
script.
+  Check the configuration of your web server, as it may be configured
+  to expect a specific file extension for CGI scripts.
+
+* On Unix-like systems, the path to the interpreter in the shebang
+  (``#!/usr/bin/env python``) must be correct.  This line calls
+  ``/usr/bin/env`` to find Python, but it will fail if there is no
+  ``/usr/bin/env``, or if Python is not in the web server's path.  If you  
know
+  where your Python is installed, you can also use that full path.  The
+  commands ``whereis python`` and ``type -p python`` could help you find
+  where it is installed.  Once you know the path, you can change the  
shebang
+  accordingly: ``#!/usr/bin/python``.
+
  * The file must not contain a BOM (Byte Order Mark). The BOM is meant for
-  determining the byte order of UTF-16 encodings, but some editors write  
this
-  also into UTF-8 files.  The BOM interferes with the shebang line, so be  
sure
-  to tell your editor not to write the BOM.
-* :ref:`mod-python` might be making problems.  mod_python is able to  
handle CGI
-  scripts by itself, but it can also be a source for problems.  Be sure you
-  disable it.
+  determining the byte order of UTF-16 and UTF-32 encodings, but some  
editors
+  write this also into UTF-8 files.  The BOM interferes with the shebang  
line,
+  so be sure to tell your editor not to write the BOM.
+
+* If the web server is using :ref:`mod-python`, ``mod_python`` may be  
having
+  problems.  ``mod_python`` is able to handle CGI scripts by itself, but  
it can
+  also be a source of issues.


  .. _mod-python:
@@ -199,33 +210,34 @@
  ----------

  People coming from PHP often find it hard to grasp how to use Python in  
the web.
-Their first thought is mostly `mod_python <http://www.modpython.org/>`_  
because
-they think that this is the equivalent to ``mod_php``.  Actually it is not
-really.  It does embed the interpreter into the Apache process, thus  
speeding up
-requests by not having to start a Python interpreter every request.  On the
-other hand, it is by far not "Python intermixed with HTML" as PHP often  
does.
-The Python equivalent of that is a template engine.  mod_python itself is  
much
-more powerful and gives more access to Apache internals.  It can emulate  
CGI, it
-can work an a "Python Server Pages" mode similar to JSP which is "HTML
-intermangled with Python" and it has a "Publisher" which destignates one  
file to
-accept all requests and decide on what to do then.
-
-But mod_python has some problems.  Unlike the PHP interpreter the Python
-interpreter uses caching when executing files, so when changing a file the  
whole
-web server needs to be re-started to update.  Another problem ist the basic
-concept -- Apache starts some child processes to handle the requests and
-unfortunately every child process needs to load the whole Python  
interpreter
-even if it does not use it.  This makes the whole web server slower.   
Another
-problem is that as mod_python is linked against a specific version of
-``libpython``, it is not possible to switch from an older version to a  
newer
-(e.g. 2.4 to 2.5) without recompiling mod_python.  mod_python is also  
bound to
-the Apache web server, so programs written for mod_python cannot easily  
run on
-other web servers.
-
-These are the reasons why mod_python should be avoided when writing new
-programs.  In some circumstances it might be still a good idea to use  
mod_python
-for deployment, but WSGI makes it possible to run WSGI programs under  
mod_python
-as well.
+Their first thought is mostly `mod_python <http://www.modpython.org/>`_\ ,
+because they think that this is the equivalent to ``mod_php``.  Actually,  
there
+are many differences.  What ``mod_python`` does is embed the interpreter  
into
+the Apache process, thus speeding up requests by not having to start a  
Python
+interpreter for each request.  On the other hand, it is not "Python  
intermixed
+with HTML" in the way that PHP is often intermixed with HTML. The Python
+equivalent of that is a template engine.  ``mod_python`` itself is much  
more
+powerful and provides more access to Apache internals.  It can emulate CGI,
+work in a "Python Server Pages" mode (similar to JSP) which is "HTML
+intermingled with Python", and it has a "Publisher" which designates one  
file
+to accept all requests and decide what to do with them.
+
+``mod_python`` does have some problems.  Unlike the PHP interpreter, the  
Python
+interpreter uses caching when executing files, so changes to a file will
+require the web server to be restarted.  Another problem is the basic  
concept
+-- Apache starts child processes to handle the requests, and unfortunately
+every child process needs to load the whole Python interpreter even if it  
does
+not use it.  This makes the whole web server slower.  Another problem is  
that,
+because ``mod_python`` is linked against a specific version of  
``libpython``,
+it is not possible to switch from an older version to a newer (e.g. 2.4 to  
2.5)
+without recompiling ``mod_python``.  ``mod_python`` is also bound to the  
Apache
+web server, so programs written for ``mod_python`` cannot easily run on  
other
+web servers.
+
+These are the reasons why ``mod_python`` should be avoided when writing new
+programs.  In some circumstances it still might be a good idea to use
+``mod_python`` for deployment, but WSGI makes it possible to run WSGI  
programs
+under ``mod_python`` as well.


  FastCGI and SCGI
@@ -233,19 +245,19 @@

  FastCGI and SCGI try to solve the performance problem of CGI in another  
way.
  Instead of embedding the interpreter into the web server, they create
-long-running processes which run in the background. There still is some  
module
-in the web server which makes it possible for the web server to "speak"  
with the
-background process.  As the background process is independent from the  
server,
-it can be written in any language of course also in Python.  The language  
just
-needs to have a library which handles the communication with the web  
server.
+long-running background processes. There is still a module in the web  
server
+which makes it possible for the web server to "speak" with the background
+process.  As the background process is independent of the server, it can be
+written in any language, including Python.  The language just needs to  
have a
+library which handles the communication with the webserver.

  The difference between FastCGI and SCGI is very small, as SCGI is  
essentially
-just a "simpler FastCGI".  But as the web server support for SCGI is  
limited
+just a "simpler FastCGI".  As the web server support for SCGI is limited,
  most people use FastCGI instead, which works the same way.  Almost  
everything
-that applies to SCGI also applies to FastCGI as well, so we'll only write  
about
+that applies to SCGI also applies to FastCGI as well, so we'll only cover
  the latter.

-These days, FastCGI is never used directly.  Just like ``mod_python`` it  
is only
+These days, FastCGI is never used directly.  Just like ``mod_python``, it  
is only
  used for the deployment of WSGI applications.

  .. seealso::
@@ -259,18 +271,20 @@
  Setting up FastCGI
  ^^^^^^^^^^^^^^^^^^

-Depending on the web server you need to have a special module.
-
-* Apache has both `mod_fastcgi <http://www.fastcgi.com/>`_ and `mod_fcgid
+Each web server requires a specific module.
+
+* Apache has both `mod_fastcgi <http://www.fastcgi.com/drupal/>`_ and  
`mod_fcgid
    <http://fastcgi.coremail.cn/>`_.  ``mod_fastcgi`` is the original one,  
but it
-  has some licensing issues that's why it is sometimes considered non-free.
-  ``mod_fcgid`` is a smaller, compatible alternative. One of these modules  
needs
+  has some licensing issues, which is why it is sometimes considered  
non-free.
+  ``mod_fcgid`` is a smaller, compatible alternative.  One of these  
modules needs
    to be loaded by Apache.
+
  * lighttpd ships its own `FastCGI module
-  <http://trac.lighttpd.net/trac/wiki/Docs%3AModFastCGI>`_ as well as an  
`SCGI
-  module <http://trac.lighttpd.net/trac/wiki/Docs%3AModSCGI>`_.
-* nginx also supports `FastCGI
-  <http://wiki.codemongers.com/NginxSimplePythonFCGI>`_.
+  <http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModFastCGI>`_ as well as  
an
+  `SCGI module <http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModSCGI>`_.
+
+* `nginx <http://nginx.org/>`_ also supports `FastCGI
+  <http://wiki.nginx.org/NginxSimplePythonFCGI>`_.

  Once you have installed and configured the module, you can test it with the
  following WSGI-application::
@@ -300,28 +314,27 @@
  .. seealso::

     There is some documentation on `setting up Django with FastCGI
-   <http://www.djangoproject.com/documentation/fastcgi/>`_, most of which  
can be
-   reused for other WSGI-compliant frameworks and libraries.  Only the
-   ``manage.py`` part has to be changed, the example used here can be used
-   instead. Django does more or less the exact same thing.
+   <http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/>`_,  
most of
+   which can be reused for other WSGI-compliant frameworks and libraries.
+   Only the ``manage.py`` part has to be changed, the example used here  
can be
+   used instead.  Django does more or less the exact same thing.


  mod_wsgi
  --------

-`mod_wsgi <http://www.modwsgi.org/>`_ is an attempt to get rid of the low  
level
-gateways.  As FastCGI, SCGI, mod_python are mostly used to deploy WSGI
-applications anyway, mod_wsgi was started to directly embed WSGI  
aplications
-into the Apache web server.  The benefit from this approach is that WSGI
-applications can be deployed much easier as is is specially designed to  
host
-WSGI applications -- unlike the other low level methods which have glue  
code to
-host WSGI applications (like flup which was mentioned before).  The  
downside is
-that mod_wsgi is limited to the Apache web server, other servers would need
+`mod_wsgi <http://code.google.com/p/modwsgi/>`_ is an attempt to get rid  
of the
+low level gateways.  Given that FastCGI, SCGI, and mod_python are mostly  
used to
+deploy WSGI applications, mod_wsgi was started to directly embed WSGI  
applications
+into the Apache web server. mod_wsgi is specifically designed to host WSGI
+applications.  It makes the deployment of WSGI applications much easier  
than
+deployment using other low level methods, which need glue code.  The  
downside
+is that mod_wsgi is limited to the Apache web server; other servers would  
need
  their own implementations of mod_wsgi.

-It supports two modes: the embedded mode in which it integrates with the  
Apache
-process and the daemon mode which is more FastCGI-like.  Contrary to  
FastCGI,
-mod_wsgi handles the worker-processes by itself which makes administration
+mod_wsgi supports two modes: embedded mode, in which it integrates with the
+Apache process, and daemon mode, which is more FastCGI-like.  Unlike  
FastCGI,
+mod_wsgi handles the worker-processes by itself, which makes administration
  easier.


@@ -330,58 +343,61 @@
  Step back: WSGI
  ===============

-WSGI was already mentioned several times so it has to be something  
important.
-In fact it really is, so now it's time to explain.
-
-The *Web Server Gateway Interface*, :pep:`333` or WSGI for short is  
currently
-the best possible way to Python web programming.  While it is great for
-programmers writing frameworks, the normal person does not need to get in  
direct
-contact with it.  But when choosing a framework for web development it is  
a good
-idea to take one which supports WSGI.
-
-The big profit from WSGI is the unification.  When your program is  
compatible
-with WSGI -- that means that your framework has support for WSGI, your  
program
-can be deployed on every web server interface for which there are WSGI  
wrappers.
-So you do not need to care about whether the user uses mod_python or  
FastCGI --
-with WSGI it just works on any gateway interface.  The Python standard  
library
-contains its own WSGI server :mod:`wsgiref`, which is a small web server  
that
-can be used for testing.
-
-A really great WSGI feature are the middlewares.  Middlewares are layers  
around
-your program which can add various functionality to it.  There is a  
`number of
-middlewares <http://wsgi.org/wsgi/Middleware_and_Utilities>`_ already  
available.
-For example, instead of writing your own session management (to identify a  
user
-in subsequent requests, as HTTP does not maintain state, so it does now  
know
-that the requests belong to the same user) you can just take one  
middleware,
-plug it in and you can rely an already existing functionality.  The same  
thing
-is compression -- say you want to compress your HTML using gzip, to save  
your
-server's bandwidth.  So you only need to plug-in a middleware and you're  
done.
-Authentication is also a problem easily solved using a middleware.
-
-So, generally -- although WSGI may seem complex, the initial phase of  
learning
-can be very rewarding as WSGI does already have solutions to many problems  
that
-might arise while writing web sites.
+WSGI has already been mentioned several times, so it has to be something
+important.  In fact it really is, and now it is time to explain it.
+
+The *Web Server Gateway Interface*,  or WSGI for short, is defined in
+:pep:`333` and is currently the best way to do Python web programming.   
While
+it is great for programmers writing frameworks, a normal web developer  
does not
+need to get in direct contact with it.  When choosing a framework for web
+development it is a good idea to choose one which supports WSGI.
+
+The big benefit of WSGI is the unification of the application programming
+interface.  When your program is compatible with WSGI -- which at the outer
+level means that the framework you are using has support for WSGI -- your
+program can be deployed via any web server interface for which there are  
WSGI
+wrappers.  You do not need to care about whether the application user uses
+mod_python or FastCGI or mod_wsgi -- with WSGI your application will work  
on
+any gateway interface.  The Python standard library contains its own WSGI
+server, :mod:`wsgiref`, which is a small web server that can be used for
+testing.
+
+A really great WSGI feature is middleware.  Middleware is a layer around  
your
+program which can add various functionality to it.  There is quite a bit of
+`middleware <http://wsgi.org/wsgi/Middleware_and_Utilities>`_ already
+available.  For example, instead of writing your own session management  
(HTTP
+is a stateless protocol, so to associate multiple HTTP requests with a  
single
+user your application must create and manage such state via a session),  
you can
+just download middleware which does that, plug it in, and get on with  
coding
+the unique parts of your application.  The same thing with compression --  
there
+is existing middleware which handles compressing your HTML using gzip to  
save
+on your server's bandwidth.  Authentication is another a problem easily  
solved
+using existing middleware.
+
+Although WSGI may seem complex, the initial phase of learning can be very
+rewarding because WSGI and the associated middleware already have  
solutions to
+many problems that might arise while developing web sites.


  WSGI Servers
  ------------

  The code that is used to connect to various low level gateways like CGI or
-mod_python is called *WSGI server*.  One of these servers is ``flup``  
which was
-already mentioned and supports FastCGI, SCGI as well as `AJP
+mod_python is called a *WSGI server*.  One of these servers is ``flup``,  
which
+supports FastCGI and SCGI, as well as `AJP
  <http://en.wikipedia.org/wiki/Apache_JServ_Protocol>`_.  Some of these  
servers
-are written in Python as ``flup`` is, but there also exist others which are
+are written in Python, as ``flup`` is, but there also exist others which  
are
  written in C and can be used as drop-in replacements.

-There are quite a lot of servers already available, so a Python web  
application
-can be deployed nearly everywhere.  This is one big advantage that Python  
has
-compared with other web techniques.
+There are many servers already available, so a Python web application
+can be deployed nearly anywhere.  This is one big advantage that Python has
+compared with other web technologies.

  .. seealso::

-   A good overview of all WSGI-related code can be found in the `WSGI wiki
+   A good overview of WSGI-related code can be found in the `WSGI wiki
     <http://wsgi.org/wsgi>`_, which contains an extensive list of `WSGI  
servers
-   <http://wsgi.org/wsgi/Servers>`_, which can be used by *every*  
application
+   <http://wsgi.org/wsgi/Servers>`_ which can be used by *any* application
     supporting WSGI.

     You might be interested in some WSGI-supporting modules already  
contained in
@@ -393,39 +409,46 @@
  Case study: MoinMoin
  --------------------

-What does WSGI give the web application developer?  Let's take a look on  
one
-long existing web application written in Python without using WSGI.
-
-One of the most widely used wiki software is `MoinMoin  
<http://moinmo.in/>`_.
-It was created in 2000, so it predates WSGI by about three years.  While  
it now
-includes support for WSGI, older versions needed separate code to run on  
CGI,
-mod_python, FastCGI and standalone.  Now, this all is possible by using  
WSGI and
-the already-written gateways.  For running with on FastCGI ``flup`` can be  
used,
-for running a standalone server :mod:`wsgiref` is the way to go.
-
-
-Model-view-controller
+What does WSGI give the web application developer?  Let's take a look at
+an application that's been around for a while, which was written in
+Python without using WSGI.
+
+One of the most widely used wiki software packages is `MoinMoin
+<http://moinmo.in/>`_.  It was created in 2000, so it predates WSGI by  
about
+three years.  Older versions needed separate code to run on CGI,  
mod_python,
+FastCGI and standalone.
+
+It now includes support for WSGI.  Using WSGI, it is possible to deploy
+MoinMoin on any WSGI compliant server, with no additional glue code.
+Unlike the pre-WSGI versions, this could include WSGI servers that the
+authors of MoinMoin know nothing about.
+
+
+Model-View-Controller
  =====================

-The term *MVC* is often heard in statements like "framework *foo* supports  
MVC".
-While MVC is not really something technical but rather organisational,  
many web
-frameworks use this model to help the developer to bring structure into his
-program.  Bigger web applications can have lots of code so it is a good  
idea to
-have structure in the program right from the beginnings.  That way, even  
users
-of other frameworks (or even languages, as MVC is nothing Python-specific)  
can
-understand the existing code easier, as they are already familiar with the
-structure.
+The term *MVC* is often encountered in statements such as "framework *foo*
+supports MVC".  MVC is more about the overall organization of code, rather  
than
+any particular API.  Many web frameworks use this model to help the  
developer
+bring structure to their program.  Bigger web applications can have lots of
+code, so it is a good idea to have an effective structure right from the  
beginning.
+That way, even users of other frameworks (or even other languages, since  
MVC is
+not Python-specific) can easily understand the code, given that they are
+already familiar with the MVC structure.

  MVC stands for three components:

-* The *model*.  This is the data that is meant to modify.  In Python  
frameworks
-  this component is often represented by the classes used by the
-  object-relational mapper.  So, all declarations go here.
+* The *model*.  This is the data that will be displayed and modified.  In
+  Python frameworks, this component is often represented by the classes  
used by
+  an object-relational mapper.
+
  * The *view*.  This component's job is to display the data of the model to  
the
-  user.  Typically this component is represented by the templates.
+  user.  Typically this component is implemented via templates.
+
  * The *controller*.  This is the layer between the user and the model.  The
-  controller reacts on user actions (like opening some specific URL) and  
tells
-  the model to modify the data if neccessary.
+  controller reacts to user actions (like opening some specific URL), tells
+  the model to modify the data if necessary, and tells the view code what  
to
+  display,

  While one might think that MVC is a complex design pattern, in fact it is  
not.
  It is used in Python because it has turned out to be useful for creating  
clean,
@@ -434,135 +457,144 @@
  .. note::

     While not all Python frameworks explicitly support MVC, it is often  
trivial
-   to create a web site which uses the MVC pattern by seperating the data  
logic
+   to create a web site which uses the MVC pattern by separating the data  
logic
     (the model) from the user interaction logic (the controller) and the
-   templates (the view).  That's why it is important not to write  
unneccessary
-   Python code in the templates -- it is against MVC and creates more  
chaos.
+   templates (the view).  That's why it is important not to write  
unnecessary
+   Python code in the templates -- it works against the MVC model and  
creates
+   chaos in the code base, making it harder to understand and modify.

  .. seealso::

-   The english Wikipedia has an article about the `Model-View-Controller  
pattern
-   <http://en.wikipedia.org/wiki/Model-view-controller>`_, which includes  
a long
-   list of web frameworks for different programming languages.
+   The English Wikipedia has an article about the `Model-View-Controller  
pattern
+   <http://en.wikipedia.org/wiki/Model-view-controller>`_.  It includes a  
long
+   list of web frameworks for various programming languages.


-Ingredients for web sites
-=========================
-
-Web sites are complex constructs, so tools were created to help the web  
site
-developer to make his work maintainable.  None of these tools are in any  
way
-Python specific, they also exist for other programming languages as well.   
Of
-course, developers are not forced to use these tools and often there is no
-"best" tool, but it is worth informing yourself before choosing something
-because of the big number of helpers that the developer can use.
+Ingredients for Websites
+========================
+
+Websites are complex constructs, so tools have been created to help web
+developers make their code easier to write and more maintainable.  Tools  
like
+these exist for all web frameworks in all languages.  Developers are not  
forced
+to use these tools, and often there is no "best" tool.  It is worth  
learning
+about the available tools because they can greatly simplify the process of
+developing a web site.


  .. seealso::

-   People have written far more components that can be combined than these
-   presented here.  The Python wiki has a page about these components,  
called
+   There are far more components than can be presented here.  The Python  
wiki
+   has a page about these components, called
     `Web Components <http://wiki.python.org/moin/WebComponents>`_.


  Templates
  ---------

-Mixing of HTML and Python code is possible with some libraries.  While
+Mixing of HTML and Python code is made possible by a few libraries.  While
  convenient at first, it leads to horribly unmaintainable code.  That's why
  templates exist.  Templates are, in the simplest case, just HTML files with
-placeholders.  The HTML is sent to the user's browser after filling out the
+placeholders.  The HTML is sent to the user's browser after filling in the
  placeholders.

-Python already includes such simple templates::
-
-    # a simple template
-    template = "<html><body><h1>Hello %s!</h1></body></html>"
-    print template % "Reader"
-
-The Python standard library also includes some more advanced templates  
usable
-through :class:`string.Template`, but in HTML templates it is needed to use
-conditional and looping contructs like Python's *for* and *if*.  So, some
-*template engine* is needed.
-
-Now, Python has a lot of template engines which can be used with or  
without a
-`framework`_.  Some of these are using a plain-text programming language  
which
-is very easy to learn as it is quite limited while others use XML so the
-template output is always guaranteed to be valid XML.  Some `frameworks`_  
ship
-their own template engine or recommend one particular.  If one is not yet  
sure,
-using these is a good idea.
-
-.. note::
-
-   While Python has quite a lot of different template engines it usually  
does
-   not make sense to use a homebrewed template system.  The time needed to
-   evaluate all templating systems is not really worth it, better invest  
the
-   time in looking through the most popular ones.  Some frameworks have  
their
-   own template engine or have a recommentation for one.  It's wise to use
-   these.
-
-   Popular template engines include:
-
-   * Mako
-   * Genshi
-   * Jinja
+Python already includes two ways to build simple templates::
+
+    >>> template = "<html><body><h1>Hello %s!</h1></body></html>"
+    >>> print template % "Reader"
+    <html><body><h1>Hello Reader!</h1></body></html>
+
+    >>> from string import Template
+    >>> template = Template("<html><body><h1>Hello  
${name}</h1></body></html>")
+    >>> print template.substitute(dict(name='Dinsdale'))
+    <html><body><h1>Hello Dinsdale!</h1></body></html>
+
+To generate complex HTML based on non-trivial model data, conditional
+and looping constructs like Python's *for* and *if* are generally needed.
+*Template engines* support templates of this complexity.
+
+There are a lot of template engines available for Python which can be used  
with
+or without a `framework`_.  Some of these define a plain-text programming
+language which is easy to learn, partly because it is limited in scope.
+Others use XML, and the template output is guaranteed to be always be valid
+XML.  There are many other variations.
+
+Some `frameworks`_ ship their own template engine or recommend one in
+particular.  In the absence of a reason to use a different template engine,
+using the one provided by or recommended by the framework is a good idea.
+
+Popular template engines include:
+
+   * `Mako <http://www.makotemplates.org/>`_
+   * `Genshi <http://genshi.edgewall.org/>`_
+   * `Jinja <http://jinja.pocoo.org/2/>`_

  .. seealso::

-   Lots of different template engines divide the attention between  
themselves
-   because it's easy to create them in Python.  The page `Templating
+   There are many template engines competing for attention, becuase it is
+   pretty easy to create them in Python.  The page `Templating
     <http://wiki.python.org/moin/Templating>`_ in the wiki lists a big,
-   ever-growing number of these.
+   ever-growing number of these.  The three listed above are  
considered "second
+   generation" template engines and are a good place to start.


  Data persistence
  ----------------

-*Data persistence*, while sounding very complicated is just about storing  
data.
-This data might be the text of blog entries, the postings of a bulletin  
board or
-the text of a wiki page.  As always, there are different ways to store
-informations on a web server.
-
-Often relational database engines like `MySQL <http://www.mysql.com/>`_ or
-`PostgreSQL <http://http://www.postgresql.org/>`_ are used due to their  
good
-performance handling very large databases consisting of up to millions of
-entries.  These are *queried* using a language called `SQL
-<http://en.wikipedia.org/wiki/SQL>`_.  Python programmers in general do  
not like
-SQL too much, they prefer to work with objects.  It is possible to save  
Python
-objects into a database using a technology called `ORM
-<http://en.wikipedia.org/wiki/Object-relational_mapping>`_.  ORM  
translates all
-object-oriented access into SQL code under the hood, the user does not  
need to
-think about it.  Most `frameworks`_ use ORMs and it works quite well.
-
-A second possibility is using files that are saved on the hard disk  
(sometimes
-called flatfiles).  This is very easy, but is not too fast.  There is even  
a
-small database engine called `SQLite <http://www.sqlite.org/>`_ which is  
bundled
-with Python in the :mod:`sqlite` module and uses only one file.  This  
database
-can be used to store objects via an ORM and has no other dependencies.  For
-smaller sites SQLite is just enough.  But it is not the only way in which  
data
-can be saved into the file systems.  Sometimes normal, plain text files are
-enough.
-
-The third and least used possibility are so-called object oriented  
databases.
-These databases store the *actual objects* instead of the relations that
-OR-mapping creates between rows in a database.  This has the advantage that
-nearly all objects can be saven in a straightforward way, unlike in  
relational
-databases where some objects are very hard to represent with ORMs.
-
-`Frameworks`_ often give the users hints on which method to choose, it is
-usually a good idea to stick to these unless there are some special  
requirements
-which require to use the one method and not the other.
+*Data persistence*, while sounding very complicated, is just about storing  
data.
+This data might be the text of blog entries, the postings on a bulletin  
board or
+the text of a wiki page.  There are, of course, a number of different ways  
to store
+information on a web server.
+
+Often, relational database engines like `MySQL <http://www.mysql.com/>`_ or
+`PostgreSQL <http://www.postgresql.org/>`_ are used because of their good
+performance when handling very large databases consisting of millions of
+entries.  There is also a small database engine called `SQLite
+<http://www.sqlite.org/>`_, which is bundled with Python in  
the :mod:`sqlite3`
+module, and which uses only one file.  It has no other dependencies.  For
+smaller sites SQLite is just enough.
+
+Relational databases are *queried* using a language called `SQL
+<http://en.wikipedia.org/wiki/SQL>`_.  Python programmers in general do not
+like SQL too much, as they prefer to work with objects.  It is possible to  
save
+Python objects into a database using a technology called `ORM
+<http://en.wikipedia.org/wiki/Object-relational_mapping>`_ (Object  
Relational
+Mapping).  ORM translates all object-oriented access into SQL code under  
the
+hood, so the developer does not need to think about it.  Most  
`frameworks`_ use
+ORMs, and it works quite well.
+
+A second possibility is storing data in normal, plain text files (some
+times called "flat files").  This is very easy for simple sites,
+but can be difficult to get right if the web site is performing many
+updates to the stored data.
+
+A third possibility are object oriented databases (also called "object
+databases").  These databases store the object data in a form that closely
+parallels the way the objects are structured in memory during program
+execution.  (By contrast, ORMs store the object data as rows of data in  
tables
+and relations between those rows.)  Storing the objects directly has the
+advantage that nearly all objects can be saved in a straightforward way,  
unlike
+in relational databases where some objects are very hard to represent.
+
+`Frameworks`_ often give hints on which data storage method to choose.  It  
is
+usually a good idea to stick to the data store recommended by the framework
+unless the application has special requirements better satisfied by an
+alternate storage mechanism.

  .. seealso::

     * `Persistence Tools <http://wiki.python.org/moin/PersistenceTools>`_  
lists
-     possibilities on how to save data in the file system, some of these  
modules
-     are part of the standard library
+     possibilities on how to save data in the file system.  Some of these
+     modules are part of the standard library
+
     * `Database Programming  
<http://wiki.python.org/moin/DatabaseProgramming>`_
-     helps on choosing a method on how to save the data
-   * `SQLAlchemy <http://www.sqlalchemy.org/>`_, the most powerful  
OR-Mapper for
-     Python and `Elixir <http://elixir.ematia.de/>`_ which makes it easier  
to
-     use
+     helps with choosing a method for saving data
+
+   * `SQLAlchemy <http://www.sqlalchemy.org/>`_, the most powerful  
OR-Mapper
+     for Python, and `Elixir <http://elixir.ematia.de/>`_, which makes
+     SQLAlchemy easier to use
+
     * `SQLObject <http://www.sqlobject.org/>`_, another popular OR-Mapper
+
     * `ZODB <https://launchpad.net/zodb>`_ and `Durus
       <http://www.mems-exchange.org/software/durus/>`_, two object oriented
       databases
@@ -573,42 +605,44 @@
  Frameworks
  ==========

-As web sites can easily become quite large, there are so-called frameworks  
which
-were created to help the developer with making these sites.  Although the  
most
-well-known framework is Ruby on Rails, Python does also have its own  
frameworks
-which are partly inspired by Rails or which were existing a long time  
before
-Rails.
-
-Two possible approaches to web frameworks exist: the minimalistic approach  
and
-the all-inclusive approach (somtimes called *full-stack*). Frameworks  
which are
-all-inclusive give you everything you need to start working, like a  
template
-engine, some way to save and access data in databases and many features  
more.
-Most users are best off using these as they are widely used by lots of  
other
-users and well documented in form of books and tutorials.  Other web  
frameworks
-go the minimalistic approach trying to be as flexible as possible leaving  
the
-user the freedom to choose what's best for him.
-
-The majority of users is best off with all-inclusive framewors.  They bring
-everything along so a user can just jump in and start to code.  While they  
do
-have some limitations they can fullfill 80% of what one will ever want to
-perfectly.  They consist of various components which are designed to work
-together as good as possible.
-
-The multitude of web frameworks written in Python demonstrates that it is  
really
-easy to write one.  One of the most well-known web applications written in
-Python is `Zope <http://www.zope.org/>`_ which can be regarded as some  
kind of
-big framework.  But Zope was not the only framework, there were some others
-which are by now nearly forgotten.  These do not need to be mentioned  
anymore,
-because most people that used them moved on to newer ones.
+The process of creating code to run web sites involves writing code to  
provide
+various services.  The code to provide a particular service often works the
+same way regardless of the complexity or purpose of the web site in  
question.
+Abstracting these common solutions into reusable code produces what are  
called
+"frameworks" for web development.  Perhaps the most well-known framework  
for
+web development is Ruby on Rails, but Python has its own frameworks.  Some  
of
+these were partly inspired by Rails, or borrowed ideas from Rails, but many
+existed a long time before Rails.
+
+Originally Python web frameworks tended to incorporate all of the services
+needed to develop web sites as a giant, integrated set of tools.  No two  
web
+frameworks were interoperable:  a program developed for one could not be
+deployed on a different one without considerable re-engineering work.   
This led
+to the development of "minimalist" web frameworks that provided just the  
tools
+to communicate between the Python code and the http protocol, with all  
other
+services to be added on top via separate components.  Some ad hoc standards
+were developed that allowed for limited interoperability between  
frameworks,
+such as a standard that allowed different template engines to be used
+interchangeably.
+
+Since the advent of WSGI, the Python web framework world has been evolving
+toward interoperability based on the WSGI standard.  Now many web  
frameworks,
+whether "full stack" (providing all the tools one needs to deploy the most
+complex web sites) or minimalist, or anything in between, are built from
+collections of reusable components that can be used with more than one
+framework.
+
+The majority of users will probably want to select a "full stack" framework
+that has an active community.  These frameworks tend to be well documented,
+and provide the easiest path to producing a fully functional web site in
+minimal time.


  Some notable frameworks
  -----------------------

-There is an incredible number of frameworks, so there is no way to  
describe them
-all.  It is not even neccessary, as most of these frameworks are nothing  
special
-and everything that can be done with these can also be done with one of the
-popular ones.
+There are an incredible number of frameworks, so they cannot all be covered
+here.  Instead we will briefly touch on some of the most popular.


  Django
@@ -616,39 +650,37 @@

  `Django <http://www.djangoproject.com/>`_ is a framework consisting of  
several
  tightly coupled elements which were written from scratch and work together  
very
-well.  It includes an ORM which is quite powerful while being simple to  
use and
-has a great online administration interface which makes it possible to  
edit the
-data in the database with a browser.  The template engine is text-based  
and is
-designed to be usable for page designers who cannot write Python.  It  
supports
-so-called template inheritance and filters (which work like Unix pipes).   
Django
-has many handy features bundled, like creation of RSS feeds or generic  
views
-which make it possible to write web sites nearly without any Python code.
-
-It has a big, international community which has created many sites using  
Django.
-There are also quite a lot of add-on projects which extend Django's normal
+well.  It includes an ORM which is quite powerful while being simple to  
use,
+and has a great online administration interface which makes it possible to  
edit
+the data in the database with a browser.  The template engine is  
text-based and
+is designed to be usable for page designers who cannot write Python.  It
+supports template inheritance and filters (which work like Unix pipes).   
Django
+has many handy features bundled, such as creation of RSS feeds or generic  
views,
+which make it possible to create web sites almost without writing any  
Python code.
+
+It has a big, international community, the members of which have created  
many
+web sites.  There are also a lot of add-on projects which extend Django's  
normal
  functionality.  This is partly due to Django's well written `online
-documentation <http://doc.djangoproject.com/>`_ and the `Django book
+documentation <http://docs.djangoproject.com/>`_ and the `Django book
  <http://www.djangobook.com/>`_.


  .. note::

-   Although Django is an MVC-style framework, it calls the components
+   Although Django is an MVC-style framework, it names the elements
     differently, which is described in the `Django FAQ
-    
<http://www.djangoproject.com/documentation/faq/#django-appears-to-be-a-mvc-framework-but-you-call-the-controller-the-view-and-the-view-the-template-how-come-you-don-t-use-the-standard-names>`_.
+    
<http://docs.djangoproject.com/en/dev/faq/general/#django-appears-to-be-a-mvc-framework-but-you-call-the-controller-the-view-and-the-view-the-template-how-come-you-don-t-use-the-standard-names>`_.


  TurboGears
  ^^^^^^^^^^

-The other popular web framework in Python is `TurboGears
***The diff for this file has been truncated for email.***



Pythonjp-checkins メーリングリストの案内
Back to archive index