ライブラリ

□未翻訳

□翻訳中

□翻訳完了(細田謙二)

■レビュー(中垣健志)

ライブラリ

web2pyのライブラリは、グローバルオブジェクトとしてユーザアプリケーションに公開されます。たとえば、request、response、session、cache、クラス(ヘルパー、バリデータ、DALのAPI)、関数(Tとredirect)などがあります。

The web2py libraries are exposed to the user applications as global objects. For example (request, response, session, cache), classes (helpers, validators, DAL API), and functions (Tand redirect).

これらのオブジェクトは、次のコアファイルで定義されています:

These objects are defined in the following core files:

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

web2py.py

gluon/__init__.py gluon/highlight.py gluon/restricted.py gluon/streamer.py

gluon/admin.py gluon/html.py gluon/rewrite.py gluon/template.py

gluon/cache.py gluon/http.py gluon/rocket.py gluon/storage.py

gluon/cfs.py gluon/import_all.py gluon/sanitizer.py gluon/tools.py

gluon/compileapp.py gluon/languages.py gluon/serializers.py gluon/utils.py

gluon/contenttype.py gluon/main.py gluon/settings.py gluon/validators.py

gluon/dal.py gluon/myregex.py gluon/shell.py gluon/widget.py

gluon/decoder.py gluon/newcron.py gluon/sql.py gluon/winservice.py

gluon/fileutils.py gluon/portalocker.py gluon/sqlhtml.py gluon/xmlrpc.py

gluon/globals.py gluon/reserved_sql_keywords.py

次の雛形アプリがweb2pyにtar+gzipで圧縮されて同梱されています。

The tar gzipped scaffolding app that ship with web2py is

1.

welcome.w2p

このアプリは、インストール時に作成され、アップグレード時に上書きされます。

It is created upon installation and overwritten on upgrade.

最初にweb2pyを起動すると、depositとapplicationsという2つの新しいフォルダが作成されます。"welcome"アプリは"welcome.w2p"ファイルに圧縮され、雛形アプリとして利用されます。depositフォルダはアプリケーションのインスール、アンインストールのための一時的な保存場所として使用されます。

The first time you start web2py, two new folders are created: deposit and applications. The "welcome" app is zipped into a "welcome.w2p" file to be used as scaffolding app. The deposit folder is used as temporary storage for installing and uninstalling applications.

web2pyのユニットテストはここに保存されています。

web2py unit-tests are in

1.

gluon/tests/

さまざまなWebサーバと接続するためのハンドラがあります:

There are handlers for connecting with various web servers:

1.

2.

3.

4.

5.

6.

7.

cgihandler.py

gaehandler.py

fcgihandler.py

wsgihandler.py

modpythonhandler.py

gluon/contrib/gateways/__init__.py

gluon/contrib/gateways/fcgi.py

(fcgi.pyは、Allan Saddiによって開発されたものです)

(fcgi.py was developed by Allan Saddi)

また、3つのサンプルファイルがあります:

There are three example files:

1.

2.

3.

options_std.py

routes.example.py

router.example.py

1番目はオプション的な設定ファイルで、-Lオプションでweb2py.pyに渡されます。2番目はURLマッピングファイルの例です。"routes.py"に名前を変更すると、自動的に読み込まれるようになります。3番目は、URLマッピング用のもう1つの構文で、これも"routes.py"に名前を変更(またはコピー)することができます。

The former is an optional configuration file that can be passed to web2py.py with the -Loption. The second is an example of a URL mapping file. It is loaded automatically when renamed "routes.py". The third is an alternative syntax for URL mapping, and can also be renamed (or copied to) "routes.py".

次のファイルは

The files

1.

2.

3.

app.yaml

index.yaml

queue.yaml

Google App Engine上にデプロイするために必要な設定ファイルです。詳しくは、デプロイレシピの章とGoogleのドキュメンテーションのページをご覧ください。

are configuration files used for deployment on the Google App Engine. You can read more about them in the Deployment Recipes chapter and on the Google Documentation pages.

また、多くはサードパーティによって開発された追加的なライブラリがあります:

There are also additional libraries, usually developed by a third party:

feedparserはMark Pilgrimによって作られた、RSSとAtomのフィードを読み取るためのものです:

feedparser28 by Mark Pilgrim for reading RSS and Atom feeds:

1.

2.

gluon/contrib/__init__.py

gluon/contrib/feedparser.py

markdown2はTrent Mickによって作られた、wikiマークアップ用のものです:

markdown229 by Trent Mick for wiki markup:

1.

2.

gluon/contrib/markdown/__init__.py

gluon/contrib/markdown/markdown2.py

markminのマークアップです:

markmin markup:

1.

gluon/contrib/markmin.py

pysimplesoapはMariano Reingartによって作成された軽量なSOAPサーバーの実装です。

pysimplesoap is a lightweight SOAP server implementation created by Mariano Reingart:

1.

gluon/contrib/pysimplesoap/

memcache用のPython APIです。Evan Martinによって作成されました:

memcache30 Python API by Evan Martin:

1.

2.

gluon/contrib/memcache/__init__.py

gluon/contrib/memcache/memcache.py

gqlは、DALをGoogle App Engine用に移植したものです。

gql, a port of the DAL to the Google App Engine:

1.

gluon/contrib/gql.py

memdbは、DALをmemcache上に移植したものです:

memdb, a port of the DAL on top of memcache:

1.

gluon/contrib/memdb.py

gae_memcacheは、Google App Engine上でmemcacheを使うためのAPIです。

gae_memcache is an API to use memcache on the Google App Engine:

1.

gluon/contrib/gae_memcache.py

pyrtfは、リッチテキストフォーマット(RTF)を生成するためのライブラリです。Simon Cusackによって開発され、Grant Edwardsにより改定されました。

pyrtf26 for generating Rich Text Format (RTF) documents, developed by Simon Cusack and revised by Grant Edwards:

1.

2.

3.

4.

5.

6.

7.

8.

gluon/contrib/pyrtf

gluon/contrib/pyrtf/__init__.py

gluon/contrib/pyrtf/Constants.py

gluon/contrib/pyrtf/Elements.py

gluon/contrib/pyrtf/PropertySets.py

gluon/contrib/pyrtf/README

gluon/contrib/pyrtf/Renderer.py

gluon/contrib/pyrtf/Styles.py

PyRSS2GenはRSSフィードを生成するためのものです。Dalke Scientific Softwareによって開発されました:

PyRSS2Gen27 developed by Dalke Scientific Software, to generate RSS feeds:

1.

gluon/contrib/rss2.py

simplejsonはJSONオブジェクトをパースし書くための標準ライブラリです。Bob Ippolitoによって作成されました:

simplejson25 by Bob Ippolito, the standard library for parsing and writing JSON objects:

1.

2.

3.

4.

5.

gluon/contrib/simplejson/__init__.py

gluon/contrib/simplejson/decoder.py

gluon/contrib/simplejson/encoder.py

gluon/contrib/simplejson/jsonfilter.py

gluon/contrib/simplejson/scanner.py

AuthorizeNetは、Authorize.netネットワークを介してクレジットカードの支払いを受け入れるAPIを提供します

AuthorizeNet92 provides API to accept credit card payments via Authorize.net network

1.

gluon/contrib/AuthorizeNet.py

PAM用のChris AtLeeによって作られた認証APIです:

PAM72 authentication API created by Chris AtLee:

1.

gluon/contrib/pam.py

テスト用のダミーデータをデータベースに入力するためのベイズ分類機です:

A Bayesian classifier to populate the database with dummy data for testing purposes:

1.

gluon/contrib/populate.py

web2pyがサービスとして稼働しているとき、windowsのタスクバーでインタラクティブな操作を行うためのファイルです:

A file that allows interaction with the taskbar in windows, when web2py is running as a service:

1.

gluon/contrib/taskbar_widget.py

オプションで用意されているlogin_methodsとlogin_formsは、認証で使用されます:

Optional login_methods and login_forms to be used for authentication:

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

gluon/contrib/login_methods/__init__.py

gluon/contrib/login_methods/basic_auth.py

gluon/contrib/login_methods/cas_auth.py

gluon/contrib/login_methods/email_auth.py

gluon/contrib/login_methods/extended_login_form.py

gluon/contrib/login_methods/gae_google_account.py

gluon/contrib/login_methods/ldap_auth.py

gluon/contrib/login_methods/linkedin_account.py

gluon/contrib/login_methods/oauth20_account.py

gluon/contrib/login_methods/openid_auth.py

gluon/contrib/login_methods/pam_auth.py

gluon/contrib/login_methods/rpx_account.py

web2pyにはまた、便利なスクリプトが収められているフォルダがあります。

web2py also contains a folder with useful scripts:

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

scripts/setup-web2py-fedora.sh

scripts/setup-web2py-ubuntu.sh

scripts/cleancss.py

scripts/cleanhtml.py

scripts/contentparser.py

scripts/repair.py

scripts/sessions2trash.py

scripts/sync_languages.py

scripts/tickets2db.py

...

最初の2つは特に便利で、web2pyの本番環境の完全なインストールとセットアップをスクラッチで行うよう試みます。これらは第12章にて説明されます。ただし、多かれ少なかれ、それら自身で説明されています。

The first two are particularly useful because they attempt a complete installation and setup of a web2py production environment from scratch. These are discussed in Chapter 12, but they are more or less self-documenting.

最後に、web2pyはバイナリ配布をビルドするために必要なファイルを含んでいます。

Finally web2py includes these files required to build the binary distributions.

1.

2.え

3.

Makefile

setup_exe.py

setup_app.py

これらはpy2exeとpy2appためのそれぞれのセットアップスクリプトです。web2pyのバイナリ配布をビルドするためだけに必要とされます。あなたがそれらを実行することはありません。

These are setup scripts for py2exe and py2app respectively and they are only required to build the binary distributions of web2py. YOU SHOULD NEVER NEED TO RUN THEM.

要約すると、 web2pyのライブラリは次の機能を提供します:

In summary, web2py libraries provide the following functionality:

  • URLを関数呼び出しに割り当てます。

    • Map URLs into function calls.

  • HTTP経由のパラメータの受け渡しを行います。

    • Handle passing and returning parameters via HTTP.

  • それらのパラメータの検証を行います。

    • Perform validation of those parameters.

  • 大抵のセキュリティ問題からアプリケーションを保護します。

    • Protect the applications from most security issues.

  • データの永続性(データベース、セッション、キャッシュ、クッキー)を扱います。

    • Handle data persistence (database, session, cache, cookies).

  • 幾多のサポートされた言語用に文字列の翻訳を行います。

    • Perform string translations for various supported languages.

  • HTMLをプログラム的に生成します(データベーステーブルからなど)。

    • Generate HTML programmatically (e.g. from database tables).

  • データベース抽象化レイヤ(DAL)を介してSQLを生成します。

    • Generate SQL via a Database Abstraction Layer (DAL).

  • リッチテキストフォーマット(RTF)出力を生成します。

    • Generate Rich Text Format (RTF) output.

  • Comma-Separated Value(CSV)形式の出力をデータベースのテーブルから生成します。

    • Generate Comma-Separated Value (CSV) output from database tables.

  • Really Simple Syndication(RSS)フィードを生成します。

    • Generate Really Simple Syndication (RSS) feeds.

  • JavaScript Object Notation (JSON)をAjax用にシリアライズした文字列を生成します。

    • Generate JavaScript Object Notation (JSON) serialization strings for Ajax.

  • wikiマークアップ(Markdown)をHTMLに変換します。

    • Translate wiki markup (Markdown) to HTML.

  • XML-RPCのWebサービスを公開します。

    • Expose XML-RPC web services.

  • 大きいファイルのアップロードとダウンロードをストリーミングして行います。

    • Upload and download large files via streaming.

web2pyアプリケーションにはさらにファイルがあります。特に、jQuery、calendar、EditArea、nicEditなどのサードパーティ製のJavaScriptライブラリが含まれています。作者の情報はファイル自体に記載されています。

web2py applications contain additional files, particularly third-party JavaScript libraries, such as jQuery, calendar, EditArea and nicEdit. Their authors are acknowledged in the files themselves.