コード例 #1
0
ファイル: cuf.py プロジェクト: gocloudxyz/yagi
def dump_item(entity, service_title="Server"):
    """Serializes a single dictionary as an ATOM entry"""
    from StringIO import StringIO

    outfile = StringIO()
    handler = feedgenerator.SimplerXMLGenerator(outfile, 'utf-8')
    handler.startDocument()
    title = unicode(yagi.config.get('event_feed', 'feed_title'))
    feed = CufPagedFeed(
        title=title,
        link=_entity_url(),
        feed_url=_entity_url(),
        description=title,
        language=None,
        previous_page_url=None,
        next_page_url=None)

    event_type = unicode(entity['event_type'])
    original_message_id = unicode("original_message_id:{id}".format(id=
                                  entity['original_message_id']))
    feed.add_item(
        title=unicode(entity['event_type']),
        link=_entity_link(entity['id'], entity['event_type']),
        description=event_type,
        contents=entity['content']['payload'],
        categories=[event_type, original_message_id])
    feed.write_item(handler, feed.items[0], root=True, title=service_title)
    return outfile.getvalue()
コード例 #2
0
ファイル: test_feed.py プロジェクト: anujm/yagi
 def test_write_item_in_cuf_feed(self):
     outfile = StringIO()
     handler = feedgenerator.SimplerXMLGenerator(outfile, 'utf-8')
     handler.startDocument()
     contents =  '<event xmlns="http://docs.rackspace.com/core/event"' \
                 ' xmlns:nova="http://docs.rackspace.com/event/nova" ' \
                 'version="1" tenantId="2882"/></event>'
     item = {u'description': u'test', u'pubdate': None,
             u'author_link': None, u'author_name': None,
             u'link': 'http://127.0.0.1/test/some_uuid',
             u'ttl': None, u'enclosure': None, u'categories': [u'test'],
             u'item_copyright': None, u'title': u'test',
             u'author_email': None, u'comments': None,
             'contents': contents,
             u'unique_id': None}
     cuf_paged_feed = CufPagedFeed(title='test',
                                   link='http://127.0.0.1/test/some_uuid',
                                   feed_url='http://127.0.0.1/test/some_uuid',
                                   description='test',
                                   language=None,
                                   previous_page_url=None,
                                   next_page_url=None)
     cuf_paged_feed.write_item(handler,item)
     expected_result = '<?xml version="1.0" encoding="utf-8"?>\n'\
     '<atom:entry><atom:title>Server</atom:title>'\
     '<atom:content type="application/xml">&lt;event ' \
     'xmlns="http://docs.rackspace.com/core/event"' \
     ' xmlns:nova="http://docs.rackspace.com/event/nova" version="1"' \
     ' tenantId="2882"/&gt;&lt;/event&gt;</atom:content></atom:entry></atom>'
     self.assertEqual(outfile.getvalue(),expected_result)
コード例 #3
0
 def test_write_item_in_cuf_feed(self):
     outfile = StringIO()
     handler = feedgenerator.SimplerXMLGenerator(outfile, 'utf-8')
     handler.startDocument()
     contents = '<event xmlns="http://docs.rackspace.com/core/event" ' \
                'xmlns:nova="http://docs.rackspace.com/event/nova" ' \
                'version="1" tenantId="2882"/></event>'
     item = {u'description': u'test', u'pubdate': None,
             u'author_link': None, u'author_name': None,
             u'link': 'http://127.0.0.1/test/some_uuid',
             u'ttl': None, u'enclosure': None, u'categories': [u'test'],
             u'item_copyright': None, u'title': u'test',
             u'author_email': None, u'comments': None,
             'contents': contents,
             u'unique_id': None}
     cuf_paged_feed = CufPagedFeed(title='test',
                                   link='http://127.0.0.1/test/some_uuid',
                                   feed_url='http://127.0.0.1/test/some_uuid',
                                   description='test',
                                   language=None,
                                   previous_page_url=None,
                                   next_page_url=None)
     cuf_paged_feed.write_item(handler, item)
     expected_result = '<?xml version="1.0" encoding="utf-8"?>\n'\
     '<atom:entry><atom:category term="test"></atom:category>'\
     '<atom:title type="text">'\
     'Server</atom:title><atom:content type="application/xml">&lt;event '\
     'xmlns="http://docs.rackspace.com/core/event" xmlns:nova="http://'\
     'docs.rackspace.com/event/nova" version="1" ' \
     'tenantId="2882"/&gt;&lt;/event&gt;</atom:content></atom:entry>'
     self.assertEqual(outfile.getvalue(), expected_result)
コード例 #4
0
def dump_item(entity, service_title="Server"):
    """Serializes a single dictionary as an ATOM entry"""
    from StringIO import StringIO

    outfile = StringIO()
    handler = feedgenerator.SimplerXMLGenerator(outfile, 'utf-8')
    handler.startDocument()
    title = unicode(yagi.config.get('event_feed', 'feed_title'))
    feed = CufPagedFeed(title=title,
                        link=_entity_url(),
                        feed_url=_entity_url(),
                        description=title,
                        language=None,
                        previous_page_url=None,
                        next_page_url=None)

    event_type = unicode(entity['event_type'])
    original_message_id = unicode(
        "original_message_id:{id}".format(id=entity['original_message_id']))
    feed.add_item(title=unicode(entity['event_type']),
                  link=_entity_link(entity['id'], entity['event_type']),
                  description=event_type,
                  contents=entity['content']['payload'],
                  categories=[event_type, original_message_id])
    feed.write_item(handler, feed.items[0], root=True, title=service_title)
    return outfile.getvalue()