@@ -977,49 +977,50 @@ Feed クラスリファレンス
977
977
カスタムのフィードジェネレータ
978
978
---------------------------------
979
979
980
- .. TBD
981
-
982
- If you need to produce a custom feed format, you've got a couple of options.
983
-
984
- If the feed format is totally custom, you'll want to subclass
985
- ``SyndicationFeed`` and completely replace the ``write()`` and
986
- ``writeString()`` methods.
987
-
988
- However, if the feed format is a spin-off of RSS or Atom (i.e. GeoRSS_, Apple's
989
- `iTunes podcast format`_, etc.), you've got a better choice. These types of
990
- feeds typically add extra elements and/or attributes to the underlying format,
991
- and there are a set of methods that ``SyndicationFeed`` calls to get these extra
992
- attributes. Thus, you can subclass the appropriate feed generator class
993
- (``Atom1Feed`` or ``Rss201rev2Feed``) and extend these callbacks. They are:
980
+ カスタムのフォーマットでフィードを生成したいなら、二つ方法があります。
981
+
982
+ 完全に独自の形式のフィードなら、 ``SyndicationFeed`` をサブクラス化して、
983
+ ``write()`` および ``writeString()`` メソッドを完全に書き直すとよいでしょう。
984
+
985
+ しかし、 (GeoRSS_ や Apple の
986
+ `iTunes podcast フォーマット <iTunes podcast format>`_ )のように、既存のフィー
987
+ ドフォーマットから派生したものであれば、もっといい選択肢があります。この手
988
+ の派生フォーマットは、元のフォーマットにエレメントや属性を追加していて、
989
+ ``SyndicationFeed`` のメソッドには、こうした追加の属性を取得するためのもの
990
+ があります。ですから、適切なフィードクラス (``Atom1Feed`` や
991
+ ``Rss201rev2Feed``) をサブクラス化して、コールバックを拡張すればよいのです。
992
+ 拡張用のメソッドを以下に示します:
994
993
995
994
.. _georss: http://georss.org/
996
995
.. _itunes podcast format: http://www.apple.com/itunes/store/podcaststechspecs.html
997
996
998
997
``SyndicationFeed.root_attributes(self, )``
999
- Return a ``dict`` of attributes to add to the root feed element
1000
- (``feed``/``channel``).
998
+ フィードのルート要素 (``feed``/``channel``) に追加する属性の入った
999
+ ``dict`` を返します。
1001
1000
1002
1001
``SyndicationFeed.add_root_elements(self, handler)``
1003
- Callback to add elements inside the root feed element
1004
- (``feed``/``channel``). ``handler`` is an `XMLGenerator`_ from Python's
1005
- built-in SAX library; you'll call methods on it to add to the XML
1006
- document in process.
1002
+ フィードのルート要素 (`` feed``/``channel``) 要素に新たに要素を付加する
1003
+ ためのコールバックです。 ``handler`` は Python 組み込み SAX ライブラリ
1004
+ の XMLGenerator_ です。このオブジェクトのメソッドを呼び出して、 処理中
1005
+ の XML ドキュメントに要素を追加します。
1007
1006
1008
1007
``SyndicationFeed.item_attributes(self, item)``
1009
- Return a ``dict`` of attributes to add to each item (``item``/``entry``)
1010
- element. The argument, ``item``, is a dictionary of all the data passed to
1011
- ``SyndicationFeed.add_item()``.
1008
+ フィードの各要素 (``item``/``entry``) に追加する属性の入った ``dict``
1009
+ を返します。引数 ``item`` は、 ``SyndicationFeed. item()`` に渡された
1010
+ データの入っている ``dict`` です。
1012
1011
1013
1012
``SyndicationFeed.add_item_elements(self, handler, item)``
1014
- Callback to add elements to each item (``item``/``entry``) element.
1015
- ``handler`` and ``item`` are as above.
1013
+ 各要素の (``item``/``entry``) 要素に新たに要素を付加するためのコールバッ
1014
+ クです。 ``handler`` と ``item`` は上と同じです。
1016
1015
1017
1016
.. warning::
1018
1017
1019
- If you override any of these methods, be sure to call the superclass methods
1020
- since they add the required elements for each feed format.
1018
+ これらのメソッドをオーバライドするときは、スーパクラスのメソッドを忘れ
1019
+ ずに呼び出してください。スーパクラス側でも、必須の要素を追加するために
1020
+ これらのメソッドを使っているからです。
1021
1021
1022
- For example, you might start implementing an iTunes RSS feed generator like so::
1022
+ 例えば、 iTunes RSS フィードジェネレータを実装するなら、書き始めは以下のよ
1023
+ うになるでしょう::
1023
1024
1024
1025
class iTunesFeed(Rss201rev2Feed):
1025
1026
def root_attibutes(self):
@@ -1031,7 +1032,7 @@ For example, you might start implementing an iTunes RSS feed generator like so::
1031
1032
super(iTunesFeed, self).add_root_elements(handler)
1032
1033
handler.addQuickElement('itunes:explicit', 'clean')
1033
1034
1034
- Obviously there's a lot more work to be done for a complete custom feed class,
1035
- but the above example should demonstrate the basic idea.
1035
+ もちろん、カスタムのフィードクラスを定義するには他にもたくさん作業が必要で
1036
+ すが、上の例を見れば基本的な考え方は理解できるはずです。
1036
1037
1037
1038
.. _XMLGenerator: http://docs.python.org/dev/library/xml.sax.utils.html#xml.sax.saxutils.XMLGenerator
0 commit comments