コード例 #1
0
    def add_item_elements(self, handler, item):
        """
        We override this entire method to handle
        pubdate -> published
        updated -> updated
        description -> content (instead of summary)
        """
        handler.addQuickElement(u"title", item['title'])
        handler.addQuickElement(u"link", u"",
                {u"href": item['link'], u"rel": u"alternate"})
        if item['updated'] is not None:
            handler.addQuickElement(u"updated",
                    rfc3339_date(item['updated']).decode('utf-8'))
        if item['pubdate'] is not None:
            handler.addQuickElement(u"published",
                    rfc3339_date(item['pubdate']).decode('utf-8'))

        # Author information.
        if item['author_name'] is not None:
            handler.startElement(u"author", {})
            handler.addQuickElement(u"name", item['author_name'])
            if item['author_email'] is not None:
                handler.addQuickElement(u"email", item['author_email'])
            if item['author_link'] is not None:
                handler.addQuickElement(u"uri", item['author_link'])
            handler.endElement(u"author")

        # Unique ID.
        handler.addQuickElement(u"id", item['unique_id'])

        # Content.
        item_type = item.get('type', u'html')
        content_dict = {u"type": item_type}
        if item['base']:
            content_dict[u"xml:base"] = item['base']

        if item['description'] is not None:
            handler.addQuickElement(u"content", item['description'],
                    content_dict)

        # Enclosure.
        if item['enclosure'] is not None:
            handler.addQuickElement(u"link", '',
                {u"rel": u"enclosure",
                 u"href": item['enclosure'].url,
                 u"length": item['enclosure'].length,
                 u"type": item['enclosure'].mime_type})

        # Categories.
        for cat in item['categories']:
            handler.addQuickElement(u"category", u"", {u"term": cat})

        # Rights.
        if item['item_copyright'] is not None:
            handler.addQuickElement(u"rights", item['item_copyright'])
コード例 #2
0
 def test_rfc3339_date_without_time(self):
     """
     Test rfc3339_date() correctly formats date objects.
     """
     self.assertEqual(
         feedgenerator.rfc3339_date(datetime.date(2008, 11, 14)),
         "2008-11-14T00:00:00Z")
コード例 #3
0
 def test_rfc3339_date(self):
     """
     Test rfc3339_date() correctly formats datetime objects.
     """
     self.assertEqual(
         feedgenerator.rfc3339_date(
             datetime.datetime(2008, 11, 14, 13, 37, 0)),
         "2008-11-14T13:37:00Z")
コード例 #4
0
ファイル: tests.py プロジェクト: Telofy/feedgenerator
 def test_rfc3339_date_with_timezone(self):
     """
     Test rfc3339_date() correctly formats datetime objects with tzinfo.
     """
     self.assertEqual(
         feedgenerator.rfc3339_date(datetime.datetime(2008, 11, 14, 13, 37, 0, tzinfo=FixedOffset(datetime.timedelta(minutes=120)))),
         "2008-11-14T13:37:00+02:00"
     )
コード例 #5
0
ファイル: tests.py プロジェクト: Telofy/feedgenerator
 def test_rfc3339_date(self):
     """
     Test rfc3339_date() correctly formats datetime objects.
     """
     self.assertEqual(
         feedgenerator.rfc3339_date(datetime.datetime(2008, 11, 14, 13, 37, 0)),
         "2008-11-14T13:37:00Z"
     )
コード例 #6
0
ファイル: tests.py プロジェクト: Telofy/feedgenerator
 def test_rfc3339_date_without_time(self):
     """
     Test rfc3339_date() correctly formats date objects.
     """
     self.assertEqual(
         feedgenerator.rfc3339_date(datetime.date(2008, 11, 14)),
         "2008-11-14T00:00:00Z"
     )
コード例 #7
0
def build_expected_atom_result(feed, expected_result, encoding):
    # Result's date is of course different from the date in the fixture.
    # So make them equal!
    d = feedgenerator.rfc3339_date(feed.latest_post_date())
    s = expected_result.replace('%DATE%', d)
    if encoding:
        return s.encode(encoding)
    else:
        return s
コード例 #8
0
def build_expected_atom_result(feed, expected_result, encoding):
    # Result's date is of course different from the date in the fixture.
    # So make them equal!
    d = feedgenerator.rfc3339_date(feed.latest_post_date())
    s = expected_result.replace('%DATE%', d)
    if encoding:
        return s.encode(encoding)
    else:
        return s
コード例 #9
0
    def add_item_elements(self, handler, item):
        #glommed wholesale from feed generator to change *one* little thing... (mdragon)
        handler.addQuickElement(u"title", item['title'])
        if item['link'] is not None:
            handler.addQuickElement(u"link", u"", {
                u"href": item['link'],
                u"rel": u"alternate"
            })
        if item['pubdate'] is not None:
            handler.addQuickElement(
                u"updated",
                feedgenerator.rfc3339_date(item['pubdate']).decode('utf-8'))

        # Author information.
        if item['author_name'] is not None:
            handler.startElement(u"author", {})
            handler.addQuickElement(u"name", item['author_name'])
            if item['author_email'] is not None:
                handler.addQuickElement(u"email", item['author_email'])
            if item['author_link'] is not None:
                handler.addQuickElement(u"uri", item['author_link'])
            handler.endElement(u"author")

        # Unique ID.
        if item['unique_id'] is not None:
            unique_id = item['unique_id']
        else:
            unique_id = "urn:uuid:%s" % uuid.uuid4()
        handler.addQuickElement(u"id", unique_id)

        # Summary.
        if item['description'] is not None:
            handler.addQuickElement(u"summary", item['description'],
                                    {u"type": u"html"})

        # Enclosure.
        if item['enclosure'] is not None:
            handler.addQuickElement(
                u"link", '', {
                    u"rel": u"enclosure",
                    u"href": item['enclosure'].url,
                    u"length": item['enclosure'].length,
                    u"type": item['enclosure'].mime_type
                })

        # Categories.
        for cat in item['categories']:
            handler.addQuickElement(u"category", u"", {u"term": cat})

        # Rights.
        if item['item_copyright'] is not None:
            handler.addQuickElement(u"rights", item['item_copyright'])
コード例 #10
0
 def test_rfc3339_date_with_timezone(self):
     """
     Test rfc3339_date() correctly formats datetime objects with tzinfo.
     """
     self.assertEqual(
         feedgenerator.rfc3339_date(
             datetime.datetime(2008,
                               11,
                               14,
                               13,
                               37,
                               0,
                               tzinfo=FixedOffset(
                                   datetime.timedelta(minutes=120)))),
         "2008-11-14T13:37:00+02:00")
コード例 #11
0
ファイル: paged_feed.py プロジェクト: pombredanne/yagi
    def add_item_elements(self, handler, item):
        #glommed wholesale from feed generator to change *one* little thing... (mdragon)
        handler.addQuickElement(u"title", item['title'])
        if item['link'] is not None:
            handler.addQuickElement(u"link", u"", {u"href": item['link'], u"rel": u"alternate"})
        if item['pubdate'] is not None:
            handler.addQuickElement(u"updated", feedgenerator.rfc3339_date(item['pubdate']).decode('utf-8'))

        # Author information.
        if item['author_name'] is not None:
            handler.startElement(u"author", {})
            handler.addQuickElement(u"name", item['author_name'])
            if item['author_email'] is not None:
                handler.addQuickElement(u"email", item['author_email'])
            if item['author_link'] is not None:
                handler.addQuickElement(u"uri", item['author_link'])
            handler.endElement(u"author")

        # Unique ID.
        if item['unique_id'] is not None:
            unique_id = item['unique_id']
        else:
            unique_id = "urn:uuid:%s" % uuid.uuid4()
        handler.addQuickElement(u"id", unique_id)

        # Summary.
        if item['description'] is not None:
            handler.addQuickElement(u"summary", item['description'], {u"type": u"html"})

        # Enclosure.
        if item['enclosure'] is not None:
            handler.addQuickElement(u"link", '',
                {u"rel": u"enclosure",
                 u"href": item['enclosure'].url,
                 u"length": item['enclosure'].length,
                 u"type": item['enclosure'].mime_type})

        # Categories.
        for cat in item['categories']:
            handler.addQuickElement(u"category", u"", {u"term": cat})

        # Rights.
        if item['item_copyright'] is not None:
            handler.addQuickElement(u"rights", item['item_copyright'])