Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes
MoinMoin.support.werkzeug.contrib.atom.AtomFeed Class Reference

List of all members.

Public Member Functions

def __init__
def add
def __repr__
def generate
def to_string
def get_response
def __call__
def __unicode__
def __str__

Public Attributes

 title
 title_type
 url
 feed_url
 id
 updated
 author
 icon
 logo
 rights
 rights_type
 subtitle
 subtitle_type
 generator
 links
 entries

Static Public Attributes

tuple default_generator = ('Werkzeug', None, None)

Detailed Description

A helper class that creates Atom feeds.

:param title: the title of the feed. Required.
:param title_type: the type attribute for the title element.  One of
                   ``'html'``, ``'text'`` or ``'xhtml'``.
:param url: the url for the feed (not the url *of* the feed)
:param id: a globally unique id for the feed.  Must be an URI.  If
           not present the `feed_url` is used, but one of both is
           required.
:param updated: the time the feed was modified the last time.  Must
                be a :class:`datetime.datetime` object.  If not
                present the latest entry's `updated` is used.
:param feed_url: the URL to the feed.  Should be the URL that was
                 requested.
:param author: the author of the feed.  Must be either a string (the
               name) or a dict with name (required) and uri or
               email (both optional).  Can be a list of (may be
               mixed, too) strings and dicts, too, if there are
               multiple authors. Required if not every entry has an
               author element.
:param icon: an icon for the feed.
:param logo: a logo for the feed.
:param rights: copyright information for the feed.
:param rights_type: the type attribute for the rights element.  One of
                    ``'html'``, ``'text'`` or ``'xhtml'``.  Default is
                    ``'text'``.
:param subtitle: a short description of the feed.
:param subtitle_type: the type attribute for the subtitle element.
                      One of ``'text'``, ``'html'``, ``'text'``
                      or ``'xhtml'``.  Default is ``'text'``.
:param links: additional links.  Must be a list of dictionaries with
              href (required) and rel, type, hreflang, title, length
              (all optional)
:param generator: the software that generated this feed.  This must be
                  a tuple in the form ``(name, url, version)``.  If
                  you don't want to specify one of them, set the item
                  to `None`.
:param entries: a list with the entries for the feed. Entries can also
                be added later with :meth:`add`.

For more information on the elements see
http://www.atomenabled.org/developers/syndication/

Everywhere where a list is demanded, any iterable can be used.

Definition at line 48 of file atom.py.


Constructor & Destructor Documentation

def MoinMoin.support.werkzeug.contrib.atom.AtomFeed.__init__ (   self,
  title = None,
  entries = None,
  kwargs 
)

Definition at line 97 of file atom.py.

00097 
00098     def __init__(self, title=None, entries=None, **kwargs):
00099         self.title = title
00100         self.title_type = kwargs.get('title_type', 'text')
00101         self.url = kwargs.get('url')
00102         self.feed_url = kwargs.get('feed_url', self.url)
00103         self.id = kwargs.get('id', self.feed_url)
00104         self.updated = kwargs.get('updated')
00105         self.author = kwargs.get('author', ())
00106         self.icon = kwargs.get('icon')
00107         self.logo = kwargs.get('logo')
00108         self.rights = kwargs.get('rights')
00109         self.rights_type = kwargs.get('rights_type')
00110         self.subtitle = kwargs.get('subtitle')
00111         self.subtitle_type = kwargs.get('subtitle_type', 'text')
00112         self.generator = kwargs.get('generator')
00113         if self.generator is None:
00114             self.generator = self.default_generator
00115         self.links = kwargs.get('links', [])
00116         self.entries = entries and list(entries) or []
00117 
00118         if not hasattr(self.author, '__iter__') \
00119            or isinstance(self.author, (basestring, dict)):
00120             self.author = [self.author]
00121         for i, author in enumerate(self.author):
00122             if not isinstance(author, dict):
00123                 self.author[i] = {'name': author}
00124 
00125         if not self.title:
00126             raise ValueError('title is required')
00127         if not self.id:
00128             raise ValueError('id is required')
00129         for author in self.author:
00130             if 'name' not in author:
00131                 raise TypeError('author must contain at least a name')


Member Function Documentation

def MoinMoin.support.werkzeug.contrib.atom.AtomFeed.__call__ (   self,
  environ,
  start_response 
)
Use the class as WSGI response object.

Definition at line 214 of file atom.py.

00214 
00215     def __call__(self, environ, start_response):
00216         """Use the class as WSGI response object."""
00217         return self.get_response()(environ, start_response)

Here is the call graph for this function:

Definition at line 143 of file atom.py.

00143 
00144     def __repr__(self):
00145         return '<%s %r (%d entries)>' % (
00146             self.__class__.__name__,
00147             self.title,
00148             len(self.entries)
00149         )

Definition at line 221 of file atom.py.

00221 
00222     def __str__(self):
00223         return self.to_string().encode('utf-8')
00224 

Here is the call graph for this function:

Definition at line 218 of file atom.py.

00218 
00219     def __unicode__(self):
00220         return self.to_string()

Here is the call graph for this function:

def MoinMoin.support.werkzeug.contrib.atom.AtomFeed.add (   self,
  args,
  kwargs 
)
Add a new entry to the feed.  This function can either be called
with a :class:`FeedEntry` or some keyword and positional arguments
that are forwarded to the :class:`FeedEntry` constructor.

Definition at line 132 of file atom.py.

00132 
00133     def add(self, *args, **kwargs):
00134         """Add a new entry to the feed.  This function can either be called
00135         with a :class:`FeedEntry` or some keyword and positional arguments
00136         that are forwarded to the :class:`FeedEntry` constructor.
00137         """
00138         if len(args) == 1 and not kwargs and isinstance(args[0], FeedEntry):
00139             self.entries.append(args[0])
00140         else:
00141             kwargs['feed_url'] = self.feed_url
00142             self.entries.append(FeedEntry(*args, **kwargs))

Here is the caller graph for this function:

Return a generator that yields pieces of XML.

Definition at line 150 of file atom.py.

00150 
00151     def generate(self):
00152         """Return a generator that yields pieces of XML."""
00153         # atom demands either an author element in every entry or a global one
00154         if not self.author:
00155             if False in map(lambda e: bool(e.author), self.entries):
00156                 self.author = ({'name': u'unbekannter Autor'},)
00157 
00158         if not self.updated:
00159             dates = sorted([entry.updated for entry in self.entries])
00160             self.updated = dates and dates[-1] or datetime.utcnow()
00161 
00162         yield u'<?xml version="1.0" encoding="utf-8"?>\n'
00163         yield u'<feed xmlns="http://www.w3.org/2005/Atom">\n'
00164         yield '  ' + _make_text_block('title', self.title, self.title_type)
00165         yield u'  <id>%s</id>\n' % escape(self.id)
00166         yield u'  <updated>%s</updated>\n' % format_iso8601(self.updated)
00167         if self.url:
00168             yield u'  <link href="%s" />\n' % escape(self.url, True)
00169         if self.feed_url:
00170             yield u'  <link href="%s" rel="self" />\n' % \
00171                 escape(self.feed_url, True)
00172         for link in self.links:
00173             yield u'  <link %s/>\n' % ''.join('%s="%s" ' % \
00174                 (k, escape(link[k], True)) for k in link)
00175         for author in self.author:
00176             yield u'  <author>\n'
00177             yield u'    <name>%s</name>\n' % escape(author['name'])
00178             if 'uri' in author:
00179                 yield u'    <uri>%s</uri>\n' % escape(author['uri'])
00180             if 'email' in author:
00181                 yield '    <email>%s</email>\n' % escape(author['email'])
00182             yield '  </author>\n'
00183         if self.subtitle:
00184             yield '  ' + _make_text_block('subtitle', self.subtitle,
00185                                           self.subtitle_type)
00186         if self.icon:
00187             yield u'  <icon>%s</icon>\n' % escape(self.icon)
00188         if self.logo:
00189             yield u'  <logo>%s</logo>\n' % escape(self.logo)
00190         if self.rights:
00191             yield '  ' + _make_text_block('rights', self.rights,
00192                                           self.rights_type)
00193         generator_name, generator_url, generator_version = self.generator
00194         if generator_name or generator_url or generator_version:
00195             tmp = [u'  <generator']
00196             if generator_url:
00197                 tmp.append(u' uri="%s"' % escape(generator_url, True))
00198             if generator_version:
00199                 tmp.append(u' version="%s"' % escape(generator_version, True))
00200             tmp.append(u'>%s</generator>\n' % escape(generator_name))
00201             yield u''.join(tmp)
00202         for entry in self.entries:
00203             for line in entry.generate():
00204                 yield u'  ' + line
00205         yield u'</feed>\n'

Here is the call graph for this function:

Here is the caller graph for this function:

Return a response object for the feed.

Definition at line 210 of file atom.py.

00210 
00211     def get_response(self):
00212         """Return a response object for the feed."""
00213         return BaseResponse(self.to_string(), mimetype='application/atom+xml')

Here is the call graph for this function:

Here is the caller graph for this function:

Convert the feed into a string.

Definition at line 206 of file atom.py.

00206 
00207     def to_string(self):
00208         """Convert the feed into a string."""
00209         return u''.join(self.generate())

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 104 of file atom.py.

tuple MoinMoin.support.werkzeug.contrib.atom.AtomFeed.default_generator = ('Werkzeug', None, None) [static]

Definition at line 95 of file atom.py.

Definition at line 115 of file atom.py.

Definition at line 101 of file atom.py.

Definition at line 111 of file atom.py.

Definition at line 105 of file atom.py.

Definition at line 102 of file atom.py.

Definition at line 114 of file atom.py.

Definition at line 106 of file atom.py.

Definition at line 107 of file atom.py.

Definition at line 108 of file atom.py.

Definition at line 109 of file atom.py.

Definition at line 110 of file atom.py.

Definition at line 98 of file atom.py.

Definition at line 99 of file atom.py.

Definition at line 103 of file atom.py.

Definition at line 100 of file atom.py.


The documentation for this class was generated from the following file: