本文整理汇总了Python中superdesk.errors.FormatterError.newmsmlG2FormatterError方法的典型用法代码示例。如果您正苦于以下问题:Python FormatterError.newmsmlG2FormatterError方法的具体用法?Python FormatterError.newmsmlG2FormatterError怎么用?Python FormatterError.newmsmlG2FormatterError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类superdesk.errors.FormatterError
的用法示例。
在下文中一共展示了FormatterError.newmsmlG2FormatterError方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: format
# 需要导入模块: from superdesk.errors import FormatterError [as 别名]
# 或者: from superdesk.errors.FormatterError import newmsmlG2FormatterError [as 别名]
def format(self, article, subscriber, codes=None):
"""
Create article in NewsML G2 format
:param dict article:
:param dict subscriber:
:param list codes: selector codes
:return [(int, str)]: return a List of tuples. A tuple consist of
publish sequence number and formatted article string.
:raises FormatterError: if the formatter fails to format an article
"""
try:
pub_seq_num = superdesk.get_resource_service('subscribers').generate_sequence_number(subscriber)
is_package = self._is_package(article)
self._message_attrib.update(self._debug_message_extra)
news_message = etree.Element('newsMessage', attrib=self._message_attrib)
self._format_header(article, news_message, pub_seq_num)
item_set = self._format_item(news_message)
if is_package:
item = self._format_item_set(article, item_set, 'packageItem')
self._format_groupset(article, item)
elif article[ITEM_TYPE] in {CONTENT_TYPE.PICTURE, CONTENT_TYPE.AUDIO, CONTENT_TYPE.VIDEO}:
item = self._format_item_set(article, item_set, 'newsItem')
self._format_contentset(article, item)
else:
nitfFormater = NITFFormatter()
nitf = nitfFormater.get_nitf(article, subscriber, pub_seq_num)
newsItem = self._format_item_set(article, item_set, 'newsItem')
self._format_content(article, newsItem, nitf)
return [(pub_seq_num, self.XML_ROOT + etree.tostring(news_message).decode('utf-8'))]
except Exception as ex:
raise FormatterError.newmsmlG2FormatterError(ex, subscriber)
示例2: format
# 需要导入模块: from superdesk.errors import FormatterError [as 别名]
# 或者: from superdesk.errors.FormatterError import newmsmlG2FormatterError [as 别名]
def format(self, article, destination, selector_codes=None):
try:
pub_seq_num = superdesk.get_resource_service('output_channels').generate_sequence_number(destination)
nitfFormater = NITFFormatter()
nitf = nitfFormater.get_nitf(article, destination, pub_seq_num)
self._message_attrib.update(self._debug_message_extra)
newsMessage = etree.Element('newsMessage', attrib=self._message_attrib)
self._format_header(article, newsMessage, pub_seq_num)
itemSet = self._format_item(newsMessage)
if article['type'] == 'text' or article['type'] == 'preformatted':
self._format_newsitem(article, itemSet, nitf)
return pub_seq_num, self.XML_ROOT + etree.tostring(newsMessage).decode('utf-8')
except Exception as ex:
raise FormatterError.newmsmlG2FormatterError(ex, destination)
示例3: format
# 需要导入模块: from superdesk.errors import FormatterError [as 别名]
# 或者: from superdesk.errors.FormatterError import newmsmlG2FormatterError [as 别名]
def format(self, article, subscriber):
try:
pub_seq_num = superdesk.get_resource_service('subscribers').generate_sequence_number(subscriber)
is_package = self._is_package(article)
self._message_attrib.update(self._debug_message_extra)
newsMessage = etree.Element('newsMessage', attrib=self._message_attrib)
self._format_header(article, newsMessage, pub_seq_num)
itemSet = self._format_item(newsMessage)
if is_package:
item = self._format_item_set(article, itemSet, 'packageItem')
self._format_groupset(article, item)
elif article[ITEM_TYPE] == CONTENT_TYPE.PICTURE:
item = self._format_item_set(article, itemSet, 'newsItem')
self._format_contentset(article, item)
else:
nitfFormater = NITFFormatter()
nitf = nitfFormater.get_nitf(article, subscriber, pub_seq_num)
newsItem = self._format_item_set(article, itemSet, 'newsItem')
self._format_content(article, newsItem, nitf)
return [(pub_seq_num, self.XML_ROOT + etree.tostring(newsMessage).decode('utf-8'))]
except Exception as ex:
raise FormatterError.newmsmlG2FormatterError(ex, subscriber)