示例#1
0
文件: opds.py 项目: Shizzz/pathagar
def generate_nav_catalog(subsections, is_root=False):
    links = []

    if is_root:
        links.append({'type': 'application/atom+xml',
                      'rel': 'self',
                      'href': reverse('pathagar.books.views.root')})

    links.append({'title': 'Home', 'type': 'application/atom+xml',
                  'rel': 'start',
                  'href': reverse('pathagar.books.views.root')})

    feed = AtomFeed(title = 'Pathagar Bookserver OPDS feed', \
        atom_id = 'pathagar:full-catalog', subtitle = \
        'OPDS catalog for the Pathagar book server', \
        extra_attrs = ATTRS, hide_generator=True, links=links)


    for subsec in subsections:
        feed.add_item(subsec['id'], subsec['title'],
                      subsec['updated'], links=subsec['links'])

    s = StringIO()
    feed.write(s, 'UTF-8')
    return s.getvalue()
示例#2
0
文件: opds.py 项目: XSCE/xscd
def generate_catalog(request, page_obj):
    attrs = {}
    attrs[u'xmlns:dcterms'] = u'http://purl.org/dc/terms/'
    attrs[u'xmlns:opds'] = u'http://opds-spec.org/'
    attrs[u'xmlns:dc'] = u'http://purl.org/dc/elements/1.1/'
    attrs[u'xmlns:opensearch'] = 'http://a9.com/-/spec/opensearch/1.1/'
    
    links = []
    
    if page_obj.has_previous():
        previous_page = page_obj.previous_page_number()
        links.append({'title': 'Previous results', 'type': 'application/atom+xml',
                      'rel': 'previous',
                      'href': page_qstring(request, previous_page)})
    
    if page_obj.has_next():
        next_page = page_obj.next_page_number()
        links.append({'title': 'Next results', 'type': 'application/atom+xml',
                      'rel': 'next',
                      'href': page_qstring(request, next_page)})
    
    feed = AtomFeed(title = 'Pathagar Bookserver OPDS feed', \
        atom_id = 'pathagar:full-catalog', subtitle = \
        'OPDS catalog for the Pathagar book server', \
        extra_attrs = attrs, hide_generator=True, links=links)

    for book in page_obj.object_list:
        if book.cover_img:
            linklist = [{'rel': \
                    'http://opds-spec.org/acquisition', 'href': \
                    reverse('pathagar.books.views.download_book',
                            kwargs=dict(book_id=book.pk)),
                    'type': __get_mimetype(book)}, {'rel': \
                    'http://opds-spec.org/cover', 'href': \
                    book.cover_img.url }]
        else:
           linklist = [{'rel': \
                    'http://opds-spec.org/acquisition', 'href': \
                    reverse('pathagar.books.views.download_book',
                            kwargs=dict(book_id=book.pk)),
                    'type': __get_mimetype(book)}]
        
        add_kwargs = {
            'content': book.a_summary,
            'links': linklist,
            'authors': [{'name' : book.a_author}],
            'dc_publisher': book.dc_publisher,
            'dc_issued': book.dc_issued,
            'dc_identifier': book.dc_identifier,
        }
           
        if book.dc_language is not None:
            add_kwargs['dc_language'] = book.dc_language.code

        feed.add_item(book.a_id, book.a_title, book.a_updated, **add_kwargs)

    s = StringIO()
    feed.write(s, 'UTF-8')
    return s.getvalue()
示例#3
0
def generate_catalog(books, q=None):
    attrs = {}
    attrs[u'xmlns:dcterms'] = u'http://purl.org/dc/terms/'
    attrs[u'xmlns:opds'] = u'http://opds-spec.org/'
    attrs[u'xmlns:dc'] = u'http://purl.org/dc/elements/1.1/'
    attrs[u'xmlns:opensearch'] = 'http://a9.com/-/spec/opensearch/1.1/'

    links = []

    if books.has_previous():
        if q:
            links.append({'title':'Previous results', 'type':'application/atom+xml', \
            'rel':'previous','href':'?page=' + str(books.previous_page_number()) + '&q=' + q })
        else:
            links.append({'title':'Previous results', 'type':'application/atom+xml', \
            'rel':'previous','href':'?page=' + str(books.previous_page_number())})


    if books.has_next():
        if q:
            links.append({'title':'Next results', 'type':'application/atom+xml', \
            'rel':'next','href':'?page=' + str(books.next_page_number()) + '&q=' + q })
        else:
            links.append({'title':'Next results', 'type':'application/atom+xml', \
            'rel':'next','href':'?page=' + str(books.next_page_number())})




    feed = AtomFeed(title = 'Pathagar Bookserver OPDS feed', \
        atom_id = 'pathagar:full-catalog', subtitle = \
        'OPDS catalog for the Pathagar book server', \
        extra_attrs = attrs, hide_generator=True, links=links)


    for book in books.object_list:
        if book.cover_img:
            linklist = [{'rel': \
                    'http://opds-spec.org/acquisition', 'href': \
                    book.file.url, 'type': __get_mimetype(book)}, {'rel': \
                    'http://opds-spec.org/cover', 'href': \
                    book.cover_img.url }]
        else:
           linklist = [{'rel': \
                    'http://opds-spec.org/acquisition', 'href': \
                    book.file.url, 'type': __get_mimetype(book)}]

        feed.add_item(book.a_id, book.a_title, book.a_updated, \
            content=book.a_summary, links = linklist, \
            authors = [{'name' : book.a_author}], \
            dc_language=book.dc_language.code, dc_publisher=book.dc_publisher, \
            dc_issued=book.dc_issued, dc_identifier=book.dc_identifier)

    s = StringIO()
    feed.write(s, 'UTF-8')
    return s.getvalue()
示例#4
0
 def get_feed(self, extra_params=None):
     
     if extra_params:
         try:
             obj = self.get_object(extra_params.split('/'))
         except (AttributeError, LookupError):
             raise LookupError('Feed does not exist')
     else:
         obj = None
     
     feed = AtomFeed(
         atom_id = self.__get_dynamic_attr('feed_id', obj),
         title = self.__get_dynamic_attr('feed_title', obj),
         updated = self.__get_dynamic_attr('feed_updated', obj),
         icon = self.__get_dynamic_attr('feed_icon', obj),
         logo = self.__get_dynamic_attr('feed_logo', obj),
         rights = self.__get_dynamic_attr('feed_rights', obj),
         subtitle = self.__get_dynamic_attr('feed_subtitle', obj),
         authors = self.__get_dynamic_attr('feed_authors', obj, default=[]),
         categories = self.__get_dynamic_attr('feed_categories', obj, default=[]),
         contributors = self.__get_dynamic_attr('feed_contributors', obj, default=[]),
         links = self.__get_dynamic_attr('feed_links', obj, default=[]),
         extra_attrs = self.__get_dynamic_attr('feed_extra_attrs', obj),
         hide_generator = self.__get_dynamic_attr('hide_generator', obj, default=False)
     )
     
     items = self.__get_dynamic_attr('items', obj)
     if items is None:
         raise LookupError('Feed has no items field')
     
     for item in items:
         feed.add_item(
             atom_id = self.__get_dynamic_attr('item_id', item), 
             title = self.__get_dynamic_attr('item_title', item),
             updated = self.__get_dynamic_attr('item_updated', item),
             content = self.__get_dynamic_attr('item_content', item),
             published = self.__get_dynamic_attr('item_published', item),
             rights = self.__get_dynamic_attr('item_rights', item),
             source = self.__get_dynamic_attr('item_source', item),
             summary = self.__get_dynamic_attr('item_summary', item),
             authors = self.__get_dynamic_attr('item_authors', item, default=[]),
             categories = self.__get_dynamic_attr('item_categories', item, default=[]),
             contributors = self.__get_dynamic_attr('item_contributors', item, default=[]),
             links = self.__get_dynamic_attr('item_links', item, default=[]),
             extra_attrs = self.__get_dynamic_attr('item_extra_attrs', item, default={}),
         )
     
     if self.VALIDATE:
         feed.validate()
     return feed
示例#5
0
    def get(self, api_key=None):
        db = client.articles
        
        feed = AtomFeed(title='Articles Feed', link_self='somelink', feed_id='someid', author='NY Media', entries=None)
        articles = db.articles.find().limit(15)
        for article in articles:
            feed.add(article['entryTitle'], unicode(article['excerpt']),
                     content_type='html',
                     author=article.get('authoredBy', ''),
                     url=article['canonicalUrl'],
                     updated=article.get('publishDate', ''),
                     published=article.get('publishDate', ''))

        return  dumps(feed.to_string())
def atom():
    feed = AtomFeed(author='postmarketOS bloggers',
                    feed_url=request.url,
                    icon=url_for('logo_svg', _external=True),
                    title='postmarketOS Blog',
                    url=url_for('blog', _external=True))

    for year, posts in get_posts(external_links=True).items():
        for post in posts:
            feed.add(
                content=post['html'],
                content_type='html',
                title=post['title'],
                url=post['url'],
                # midnight
                updated=datetime.combine(post['date'], datetime.min.time()))
    return feed.get_response()
def edge_atom():
    feed = AtomFeed(author='postmarketOS',
                    feed_url=request.url,
                    icon=url_for('logo_svg', _external=True),
                    title='Breaking updates in pmOS edge',
                    url=url_for('edge', _external=True))

    for year, posts in get_posts(external_links=True,
                                 dir=EDGE_CONTENT_DIR).items():
        for post in posts:
            feed.add(
                content=post['html'],
                content_type='html',
                title=post['title'],
                url=post['url'],
                # midnight
                updated=datetime.combine(post['date'], datetime.min.time()))
    return feed.get_response()
示例#8
0
 def getFeedFromNode(self, feedNode, gui):
     feedVersion = feedNode.getAttribute("type")
     if (feedVersion == "rss"):
         feed = RssFeed()
     if (feedVersion == "atom"):
         feed = AtomFeed()
     feed.loadFromNode(feedNode, gui)
     feed.feedVersion = feedVersion
     return feed
示例#9
0
 def getFeedFromState(self, feedState, gui):
     feedVersion = feedState.feedVersion
     if (feedVersion == "rss"):
         feed = RssFeed()
     if (feedVersion == "atom"):
         feed = AtomFeed()
     feed.loadFromState(feedState, gui)
     feed.feedVersion = feedVersion
     return feed
示例#10
0
def generate_nav_catalog(subsections, is_root=False, links=None):
    
    if links is None:
        links = []
    
    if is_root:
        links.append({'type': 'application/atom+xml;profile=opds-catalog;kind=navigation',
                      'rel': 'self',
                      'href': reverse('pathagar.books.views.root')})
        links.append({'type': 'application/opensearchdescription+xml',
                      'rel': 'search',
                      'href': reverse('opensearch_description') })
    
    links.append({'title': 'Home', 'type': 'application/atom+xml;profile=opds-catalog;kind=navigation',
                  'rel': 'start',
                  'href': reverse('root_feed')})
    
    icon = None;
    if is_root:
        icon = FEED_ICON_LOCATION
    
    feed = AtomFeed(title = FEED_TITLE,
                    atom_id = 'pathagar:full-catalog',
                    subtitle = FEED_DESCRIPTION,
                    extra_attrs = ATTRS,
                    hide_generator=True,
                    links=links,
                    icon=icon)
    
    for subsec in subsections:
        content = None
        if 'content' in subsec:
            content = subsec['content']
        feed.add_item(  subsec['id'],
                        subsec['title'],
                        subsec['updated'],
                        content=content,
                        links=subsec['links'],
                     )

    s = StringIO()
    feed.write(s, 'UTF-8')
    return s.getvalue()
示例#11
0
def generate_nav_catalog(subsections, is_root=False):
    links = []

    if is_root:
        links.append({
            'type': 'application/atom+xml',
            'rel': 'self',
            'href': reverse('pathagar.books.views.root')
        })

    links.append({
        'title': 'Home',
        'type': 'application/atom+xml',
        'rel': 'start',
        'href': reverse('pathagar.books.views.root')
    })

    feed = AtomFeed(title = 'Pathagar Bookserver OPDS feed', \
        atom_id = 'pathagar:full-catalog', subtitle = \
        'OPDS catalog for the Pathagar book server', \
        extra_attrs = ATTRS, hide_generator=True, links=links)

    for subsec in subsections:
        feed.add_item(subsec['id'],
                      subsec['title'],
                      subsec['updated'],
                      links=subsec['links'])

    s = StringIO()
    feed.write(s, 'UTF-8')
    return s.getvalue()
示例#12
0
def generate_catalog(request, page_obj):
    links = []
    links.append({'title': 'Home', 'type': 'application/atom+xml',
                  'rel': 'start',
                  'href': reverse('root_feed')})

    if page_obj.has_previous():
        previous_page = page_obj.previous_page_number()
        links.append(
            {'title': 'Previous results', 'type': 'application/atom+xml',
             'rel': 'previous',
             'href': page_qstring(request, previous_page)})

    if page_obj.has_next():
        next_page = page_obj.next_page_number()
        links.append({'title': 'Next results', 'type': 'application/atom+xml',
                      'rel': 'next',
                      'href': page_qstring(request, next_page)})

    feed = AtomFeed(title='Pathagar Bookserver OPDS feed',
                    atom_id='pathagar:full-catalog',
                    subtitle='OPDS catalog for the Pathagar book server',
                    extra_attrs=ATTRS, hide_generator=True, links=links)

    for book in page_obj.object_list:
        if book.cover_img:
            linklist = [{'rel': 'http://opds-spec.org/acquisition',
                         'href': reverse('book_download',
                                         kwargs=dict(book_id=book.pk)),
                         'type': __get_mimetype(book)},
                        {'rel': 'http://opds-spec.org/cover', 'href':
                            book.cover_img.url}]
        else:
            linklist = [{'rel': 'http://opds-spec.org/acquisition',
                         'href': reverse('book_download',
                                         kwargs=dict(book_id=book.pk)),
                         'type': __get_mimetype(book)}]

        add_kwargs = {
            'content': book.summary,
            'links': linklist,
            'authors': [{'name': a.name} for a in book.authors.all()],
            'dc_publisher': [p.name for p in book.publishers.all()],
            'dc_issued': book.dc_issued,
            'dc_identifier': book.dc_identifier,
        }

        if book.dc_language is not None:
            add_kwargs['dc_language'] = book.dc_language.code

        feed.add_item(book.a_id, book.title, book.a_updated, **add_kwargs)

    s = StringIO()
    feed.write(s, 'UTF-8')
    return s.getvalue()
示例#13
0
文件: opds.py 项目: mapmeld/pathagar
def generate_catalog(request, page_obj):
    attrs = {}
    attrs[u'xmlns:dcterms'] = u'http://purl.org/dc/terms/'
    attrs[u'xmlns:opds'] = u'http://opds-spec.org/'
    attrs[u'xmlns:dc'] = u'http://purl.org/dc/elements/1.1/'
    attrs[u'xmlns:opensearch'] = 'http://a9.com/-/spec/opensearch/1.1/'

    links = []

    if page_obj.has_previous():
        previous_page = page_obj.previous_page_number()
        links.append({
            'title': 'Previous results',
            'type': 'application/atom+xml',
            'rel': 'previous',
            'href': page_qstring(request, previous_page)
        })

    if page_obj.has_next():
        next_page = page_obj.next_page_number()
        links.append({
            'title': 'Next results',
            'type': 'application/atom+xml',
            'rel': 'next',
            'href': page_qstring(request, next_page)
        })

    feed = AtomFeed(title = 'Pathagar Bookserver OPDS feed', \
        atom_id = 'pathagar:full-catalog', subtitle = \
        'OPDS catalog for the Pathagar book server', \
        extra_attrs = attrs, hide_generator=True, links=links)

    for book in page_obj.object_list:
        if book.cover_img:
            linklist = [{'rel': \
                    'http://opds-spec.org/acquisition', 'href': \
                    reverse('pathagar.books.views.download_book',
                            kwargs=dict(book_id=book.pk)),
                    'type': __get_mimetype(book)}, {'rel': \
                    'http://opds-spec.org/cover', 'href': \
                    book.cover_img.url }]
        else:
            linklist = [{'rel': \
                     'http://opds-spec.org/acquisition', 'href': \
                     reverse('pathagar.books.views.download_book',
                             kwargs=dict(book_id=book.pk)),
                     'type': __get_mimetype(book)}]

        add_kwargs = {
            'content': book.a_summary,
            'links': linklist,
            'authors': [{
                'name': book.a_author
            }],
            'dc_publisher': book.dc_publisher,
            'dc_issued': book.dc_issued,
            'dc_identifier': book.dc_identifier,
        }

        if book.dc_language is not None:
            add_kwargs['dc_language'] = book.dc_language.code

        feed.add_item(book.a_id, book.a_title, book.a_updated, **add_kwargs)

    s = StringIO()
    feed.write(s, 'UTF-8')
    return s.getvalue()
示例#14
0
 def test26(self): # content with a src attribute requires there be a summary element too
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}])
     feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content=({'src': 'http://example.com/image.png' }, None), summary='Some Image.')
     feed.validate()
示例#15
0
 def test30(self): # Base64 content requires there be a summary element too
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}])
     feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content=({'type': 'image/png' }, '...some base64...'), summary='Some Image.')
     feed.validate()
示例#16
0
 def test31(self): # invalid content type
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}])
     feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content=({'type': 'foo' }, '...some foo content...'))
     self.assertRaises(ValidationError, feed.validate)
示例#17
0
 def test29(self): # Base64 content requires there be a summary element too
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}])
     feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content=({'type': 'application/xml' }, '...not base64...'))
     feed.validate()
示例#18
0
def generate_catalog(request, page_obj):
    links = []
    links.append({'title': 'Home', 'type': 'application/atom+xml;profile=opds-catalog;kind=navigation',
                  'rel': 'start',
                  'href': reverse('pathagar.books.views.root')})

    if page_obj.has_previous():
        previous_page = page_obj.previous_page_number()
        links.append({'title': 'Previous results', 'type': 'application/atom+xml;profile=opds-catalog;kind=acquisition',
                      'rel': 'previous',
                      'href': request.path + page_qstring(request, previous_page)})
    
    if page_obj.has_next():
        next_page = page_obj.next_page_number()
        links.append({'title': 'Next results', 'type': 'application/atom+xml;profile=opds-catalog;kind=acquisition',
                      'rel': 'next',
                      'href': request.path + page_qstring(request, next_page)})
    
    feed = AtomFeed(title = FEED_TITLE,
                    atom_id = 'pathagar:full-catalog',
                    subtitle = FEED_DESCRIPTION,
                    extra_attrs = ATTRS,
                    hide_generator=True,
                    links=links,
                    openSearch_totalResults=page_obj.paginator.count,
                    openSearch_itemsPerPage=page_obj.paginator.num_pages,
                    )
    
    bbparser = fimfic_bbcode.Parser()
    for book in page_obj.object_list:
        
        linklist = [
                        {
                            'rel': 'http://opds-spec.org/acquisition',
                            'href': reverse('pathagar.books.views.download_book',
                                            kwargs=dict(book_id=book.pk, filename=book.a_title+".epub" )),
                            'type': 'application/epub+zip'
                        },
                        {
                            'rel': 'http://opds-spec.org/acquisition',
                            'href': reverse('pathagar.books.views.download_book',
                                            kwargs=dict(book_id=book.pk, filename=book.a_title+".mobi" )),
                            'type': 'application/x-mobipocket-ebook'
                        },
                        {
                            'href': book.getOnlineViewingUrl(),
                        },
                   ]
        
        if book.getCoverImageUrl():
            # We are stripping everything past the question mark. guess_type fails in some cases otherwise.
            mimetype, encoding = mimetypes.guess_type( book.getCoverImageUrl().split('?')[0], strict=False )
            if mimetype is None:
                mimetype = 'image/*'
            linklist.append(
                {
                    'rel': 'http://opds-spec.org/image',
                    'type': mimetype,
                    'href': book.getCoverImageUrl()
                },
            )
        
        if book.getThumbnailUrl():
            # We are stripping everything past the question mark. guess_type fails in some cases otherwise.
            mimetype, encoding = mimetypes.guess_type( book.getThumbnailUrl().split('?')[0], strict=False )
            if mimetype is None:
                mimetype = 'image/*'
            linklist.append(
                {
                    'rel': 'http://opds-spec.org/image/thumbnail',
                    'type': mimetype,
                    'href': book.getThumbnailUrl()
                },
            )
        
        authors = []
        for author in book.a_authors.all():
            authors.append(
                {
                    'name':author.name,
                    'uri':author.getLink(),
                })
        
        categories = []
        for category in book.a_categories.all():
            categories.append(category.category)
        
        add_kwargs = {
            'summary': book.a_summary,
            # The Unicode concatenation forces the output of bbparser to Unicode.
            # bbparser outputs a string instead of Unicode if the input is a empty Unicode/string object
            'content': ( {'type':'html'}, u"" + bbparser.format(book.a_content) ),
            'links': linklist,
            'authors': authors,
            'categories': categories,
            'published': book.a_published,
            'dc_publisher': book.dc_publisher,
            'dc_issued': str(book.dc_issued),
            'dc_identifier': book.dc_identifier,
        }
        
        if book.dc_language is not None:
            add_kwargs['dc_language'] = book.dc_language.code

        feed.add_item(
                book.getUUID(),
                book.a_title,
                book.updated,   # A items atom:updated should refer to the time the item was update on THIS server.
                **add_kwargs
                )

    s = StringIO()
    feed.write(s, 'UTF-8')
    return s.getvalue()
示例#19
0
 def test7(self): # entry summary type one of text, html, xhtml
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}])
     feed.add_item(atom_id='test_entry_id', title='test entry title', summary=('foo', 'test entry summary'), updated=datetime(2007, 8, 1), content='Some content.')
     self.assertRaises(ValidationError, feed.validate)
示例#20
0
 def test1(self): # minimal sunny day
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}])
     feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content='Some content.')
     feed.validate()
示例#21
0
 def test23(self): # content with a src attribute must be empty
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}])
     feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content=({'src': 'http://example.com/image.png' }, ''), summary='Some image.')
     feed.validate()
示例#22
0
 def test13(self): # an entry can override feed author
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}])
     feed.add_item(atom_id='test_entry1_id', title='test entry1 title', updated=datetime(2007, 8, 1), content='Some content.')
     feed.add_item(atom_id='test_entry2_id', title='test entry2 title', updated=datetime(2007, 8, 1), authors=[{'name': 'Someone Else'}], content='Some content.')
     feed.validate()
示例#23
0
 def test12(self): # entry can have author
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1))
     feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}], content='Some content.')
     feed.validate()
示例#24
0
 def test10(self): # source rights type one of text, html, xhtml
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}])
     feed.add_item(atom_id='test_entry_id', title='test entry title', source={'rights': ('foo', 'test source title')}, updated=datetime(2007, 8, 1), content='Some content.')
     self.assertRaises(ValidationError, feed.validate)
示例#25
0
 def test24(self): # content with a src attribute must be empty
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}])
     feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content=({'src': 'http://example.com/image.png' }, "Shouldn't' be here."), summary='Some image.')
     self.assertRaises(ValidationError, feed.validate)
示例#26
0
 def test20(self): # entries without a content element must have a link rel="alternate"
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}])
     feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), links=[{'rel': 'alternate', 'href': 'http://example.com/entry/1/'}])
     feed.validate()
示例#27
0
 def test19(self): # entries without a content element must have a link rel="alternate"
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}])
     feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1))
     self.assertRaises(ValidationError, feed.validate)
示例#28
0
 def test32(self): # content with a src attribute can not have a type of text, html or xhtml
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}])
     feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content=({'src': 'http://example.com/image.png', 'type': 'text'}, None), summary='Some Image.')
     self.assertRaises(ValidationError, feed.validate)
示例#29
0
 def test22(self): # entries must not contain more than one link rel="alternate" that has the same combination of type and hreflang values
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}])
     feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1),
         links=[{'rel': 'alternate', 'type': 'text/html', 'hreflang': 'en'}, {'rel': 'alternate', 'type': 'text/html', 'hreflang': 'en'}])
     self.assertRaises(ValidationError, feed.validate)
示例#30
0
 def test15(self): # if no feed author, all entries must have author, possibly in a source
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1))
     feed.add_item(atom_id='test_entry1_id', title='test entry1 title', updated=datetime(2007, 8, 1), source={'authors': [{'name': 'Someone Else'}]}, content='Some content.')
     feed.add_item(atom_id='test_entry2_id', title='test entry2 title', updated=datetime(2007, 8, 1), authors=[{'name': 'Someone Else'}], content='Some content.')
     feed.validate()
示例#31
0
 def test16(self): # feeds must not contain more than one link rel="alternate" that has the same combination of type and hreflang values
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}],
         links=[{'rel': 'alternate', 'type': 'text/html', 'hreflang': 'en'}, {'rel': 'alternate', 'type': 'text/html', 'hreflang': 'fr'}])
     feed.validate()
示例#32
0
 def test18(self): # entries without a content element must have a link rel="alternate"
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}])
     feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content='Test content.')
     feed.validate()
示例#33
0
 def test14(self): # if no feed author, all entries must have author
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1))
     feed.add_item(atom_id='test_entry1_id', title='test entry1 title', updated=datetime(2007, 8, 1), content='Some content.')
     feed.add_item(atom_id='test_entry2_id', title='test entry2 title', updated=datetime(2007, 8, 1), authors=[{'name': 'Someone Else'}], content='Some content.')
     self.assertRaises(ValidationError, feed.validate)
示例#34
0
 def test27(self): # Base64 content requires there be a summary element too
     feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}])
     feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content=({'type': 'image/png' }, '...some base64...'))
     self.assertRaises(ValidationError, feed.validate)