01 はじめに

□未翻訳

□翻訳中

□翻訳完了(中垣健志)

■レビュー(Omi Chiba)

はじめに

web2pyは、セキュアなデータベース駆動型のWebアプリケーションをアジャイルで開発するための、フリーでオープンなWebフレームワークです。フレームワーク自身がPythonでかかれていて、かつPythonでプログラムする事ができます。web2pyはフルスタックフレームワークです、つまり完全なWebアプリケーションの開発に必要なすべてのコンポーネントを含んでいます。

web2py1 is a free, open-source web framework for agile development of secure database-driven web applications; it is written in Python2 and programmable in Python. web2py is a full-stack framework, meaning that it contains all the components you need to build fully functional web applications.

web2pyは、Web開発者をソフトウェア開発の良いプラクティス、いわゆるモデル/ビュー/コントローラ (MVC)パターンに導くためのガイドとなるよう、デザインされています。web2pyは、 データの構造の表現(モデル)を、データの見せ方の表現(ビュー)やアプリケーションのロジックやワークフロー(コントローラ)から分離します。web2pyは 開発者を助けるために、それら3つの構成に対して、それぞれ、設計、実装、テストできるようなライブラリを提供し、協調して動作させることができます。

web2py is designed to guide a web developer to follow good software engineering practices, such as using the Model View Controller (MVC) pattern. web2py separates the data representation (the model) from the data presentation (the view) and also from the application logic and workflow (the controller). web2py provides libraries to help the developer design, implement, and test each of these three parts separately, and makes them work together.

web2pyは、セキュリティを考慮して構築されています。つまり、確立された手法に沿った形で、セキュリティの脆弱性につながるような問題を解決しています。たとえばこのフレームワークでは、すべての入力を検証し(インジェクションを防ぐため)、すべての出力をエスケープし(クロスサイトスクリプティングを防ぐため)、アップロードしたファイル名を変更します(ディレクトリトラバーサルを防ぐため)。web2pyはアプリケーション開発者に対して、セキュリティを考慮した実装をせざるをえないようにします。

web2py is built for security. This means that it automatically addresses many of the issues that can lead to security vulnerabilities, by following well established practices. For example, it validates all input (to prevent injections), escapes all output (to prevent cross-site scripting), renames uploaded files (to prevent directory traversal attacks). web2py leaves little choice to application developers in matters related to security.

web2pyには、開発者がSQLを記述しなくてもよいようにするために、SQLを動的に作成するデータベース抽象レイヤ(DAL)が含まれています。DALは、SQLite、MySQL、PostgreSQL、MSSQL、Firebird、Oracle、IBM DB2、Informix、そしてIngresについて、それぞれのデータベースに依存しない透過的なSQLを生成することができます。さらに、Google App Engine(GAE)上で動いている時は、Google BigTableに対する関数呼び出しも生成することができます。一旦、データベースのテーブルを定義すると、データベースとテーブルにアクセスできる十分な機能を持ったWebベースのデータベース管理インターフェースが生成されます。

web2py includes a Database Abstraction Layer (DAL) that writes SQL3 dynamically so that you, the developer, don't have to. The DAL knows how to generate SQL transparently for SQLite4, MySQL6, PostgreSQL5, MSSQL7, FireBird8, Oracle9, IBM DB210, Informix11, and Ingres12. The DAL can also generate function calls for Google BigTable when running on the Google App Engine (GAE)13. Once one or more database tables are defined, web2py also generates a fully functional web-based database administration interface to access the database and the tables.

web2pyは、Webはコンピュータである、というWeb2.0のパラダイムを完全に取り入れるための最適なフレームワークという点で、他のWebフレームワークとは異なります。実際、web2pyにはインストールや設定などはありません。Pythonが実行できる任意のアーキテクチャ(Windows、Windows CE、Mac OS X、iOS、Unix / Linux)で動作します。そして開発、デプロイ、メンテナンスといったアプリケーション開発の各フェーズに対して、ローカルやリモートから操作のできるWebのインターフェイスを提供しています。web2pyはCPython(Cによる実装)およびJython(Java実装)で動きます。動作させられるバージョンは2.4、2.5、2.6および2.7がありますが、"正式"には2.5のみを対象内として、その他のバージョンについては下位互換性の確認も含めてテストは行っていません。

web2py differs from other web frameworks in that it is the only framework to fully embrace the Web 2.0 paradigm, where the web is the computer. In fact, web2py does not require installation or configuration; it runs on any architecture that can run Python (Windows, Windows CE, Mac OS X, iOS, and Unix/Linux), and the development, deployment, and maintenance phases for the applications can be done via a local or remote web interface. web2py runs with CPython (the C implementation) and Jython (the Java implementation), on Python versions 2.4, 2.5, 2.6, and 2.7, although "officially" it only supports 2.5 so that we can guarantee backward compatibility for applications.

web2pyは、チケットシステムを提供しています。エラーが発生した場合、チケットが発行され、エラーが管理者用に記録されます。

web2py provides a ticketing system. If an error occurs, a ticket is issued to the user, and the error is logged for the administrator.

web2pyはオープンソースであり、GPL2.0ライセンスの下に公開されています。ただし、web2pyで開発されたアプリケーションは、どのライセンス制約にも縛られません。アプリケーションがweb2pyのソースコードを含んでいない限り、"派生物"としてはみなされません。web2pyは、アプリケーションが実行時にweb2pyを必要とする場合でも、それをバイトコードにコンパイルし、そしてソースを公開せずに配布する事を、開発者に対して認めています。web2pyのライセンスには、事前コンパイルされたweb2pyのバイナリを含みつつソースコードを含まない形で製品を出荷する事も例外的に認めています。

web2py is open source and released under the GPL2.0 license, but applications developed with web2py are not subject to any license constraint. In fact, as long as they do not contain web2py source code, they are not considered "derivative works". web2py also allows the developer to bytecode-compile applications and distribute them as closed source, although they will require web2py to run. The web2py license includes an exception that allows web developers to ship their products with original pre-compiled web2py binaries, without the accompanying source code.

web2pyのもう1つの特徴は、将来のバージョンにおいて後方互換性を維持することを誓っていることです。web2pyは2007年10月に初めて公開されました。新機能が追加されてバグも修正されていますが、しかしweb2py1.0で動いているプログラムは、最新版でも動きます。

Another feature of web2py is that we, its developers, commit to maintain backward compatibility in future versions. We have done so since the first release of web2py in October, 2007. New features have been added and bugs have been fixed, but if a program worked with web2py 1.0, that program will still work today.

さてここで、web2pyの記述の強力さとシンプルさを示すいくつかの例を示します。次のコードをみてください:

Here are some examples of web2py statements that illustrate its power and simplicity. The following code:

1.

db.define_table('person', Field('name'), Field('image', 'upload'))

このコードは、"name"という文字列、"image"というアップロードが必要なもの(実際の画像)、という二つのフィールドを持つ"person"というテーブルを、データベースに作成します。テーブルがすでに存在しているが定義と一致しない場合には、適切に変更されます。

creates a database table called "person" with two fields: "name", a string; and "image", something that needs to be uploaded (the actual image). If the table already exists but does not match this definition, it is altered appropriately.

上記のようにテーブルが定義されている場合、次のコードを見てください:

Given the table defined above, the following code:

1.

form = crud.create(db.person)

このコードは、画像もアップロードすることのできるpersonテーブル用の登録フォームを作成します。このコードはまた、送信されたフォームを検証し、アップロードされた画像を安全な方法でリネームし、画像をファイルに保存し、対応するレコードをデータベースに挿入し、二重投稿を防ぎ、送信データの検証が通らない場合にエラーメッセージをフォームに追加して最終的に修飾されるようにします。

creates an insert form for this table that allows users to upload images. It also validates a submitted form, renames the uploaded image in a secure way, stores the image in a file, inserts the corresponding record in the database, prevents double submission, and eventually modifies the form itself by adding error messages if the data submitted by the user does not pass validation.

次のコードを見てください。

The following code:

1.

2.

@auth.requires_permission('read','person')

def f(): ....

このコードは、訪問者が"person"テーブルのレコードを"read"できる権限を持つグループのメンバーでない限り、関数fへアクセスを拒否します。もし訪問者がログインをしていない場合、ログインページ(web2pyのデフォルトとして提供されている)にリダイレクトされます。

prevents visitors from accessing the function f unless the visitor is a member of a group whose members have permissions to "read" records of table "person". If the visitor is not logged in, he gets directed to a login page (provided by default by web2py).

次のコードは、ページのコンポーネントをコードに埋め込んでいます。

The following code embeds a page component.

1.

{{=LOAD('other_controller','function.load',ajax=True, ajax_trap=True)}}

このコードはweb2pyに対して、ビューの中に 他のコントローラー関数(これは任意の関数で動作)によって生成されたコンテンツをロードするように指示します。コンテンツは Ajax を介してを読み込まれ、現在のページ(現在のレイアウトが使用されます。other_controllerの 関数のレイアウトは使用されません)に埋め込まれます。また 読み込まれたコンテンツに含まれるすべてのフォームの送信処理をトラップするので、ページをリロードすることなくAjax 経由で送信できます。非 web2py アプリケーションからコンテンツを読み込むことができます。

This instructs web2py to load in a view the content generated by the other controller function (this works with any function). It loads the content via Ajax, embeds it into the current page (using the current layout, not the layout of the other_controller function), and traps all forms contained in the loaded content so that they are also submitted via Ajax without reloading the page. It can also LOAD content from non-web2py applications.

LOADヘルパーは、アプリケーションをモジュール化されたデザインにすることを助けます。本書の最後の章でくわしく解説します。

The LOAD helper allows very modular design of applications; it is discussed in some detail in the last chapter of this book.