本文整理汇总了Python中superdesk.errors.ParserError.parseMessageError方法的典型用法代码示例。如果您正苦于以下问题:Python ParserError.parseMessageError方法的具体用法?Python ParserError.parseMessageError怎么用?Python ParserError.parseMessageError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类superdesk.errors.ParserError
的用法示例。
在下文中一共展示了ParserError.parseMessageError方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _test
# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseMessageError [as 别名]
def _test(self, provider):
"""Test connection."""
config = provider.get('config', {})
xml = self._fetch_data(config, provider)
data = feedparser.parse(xml)
if data.bozo:
raise ParserError.parseMessageError(data.bozo_exception, provider)
示例2: _update
# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseMessageError [as 别名]
def _update(self, provider):
"""
Check data provider for data updates and returns new items (if any).
:param provider: data provider instance
:return: a list containing a list of new content items
:rtype: list
:raises IngestApiError: if data retrieval error occurs
:raises ParserError: if retrieved RSS data cannot be parsed
"""
config = provider.get('config', {})
if config.get('auth_required'):
self.auth_info = {
'username': config.get('username', ''),
'password': config.get('password', '')
}
try:
xml_data = self._fetch_data(config, provider)
data = feedparser.parse(xml_data)
except IngestApiError:
raise
except Exception as ex:
raise ParserError.parseMessageError(ex, provider)
# If provider last updated time is not available, set it to 1.1.1970
# so that it will be recognized as "not up to date".
# Also convert it to a naive datetime object (removing tzinfo is fine,
# because it is in UTC anyway)
t_provider_updated = provider.get('last_updated', utcfromtimestamp(0))
t_provider_updated = t_provider_updated.replace(tzinfo=None)
new_items = []
field_aliases = config.get('field_aliases')
for entry in data.entries:
t_entry_updated = utcfromtimestamp(timegm(entry.updated_parsed))
if t_entry_updated <= t_provider_updated:
continue
item = self._create_item(entry, field_aliases)
self.add_timestamps(item)
# If the RSS entry references any images, create picture items from
# them and create a package referencing them and the entry itself.
# If there are no image references, treat entry as a simple text
# item, even if it might reference other media types, e.g. videos.
image_urls = self._extract_image_links(entry)
if image_urls:
image_items = self._create_image_items(image_urls, item)
new_items.extend(image_items)
new_items.append(item)
item = self._create_package(item, image_items)
new_items.append(item)
return [new_items]
示例3: parse
# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseMessageError [as 别名]
def parse(self, xml, provider=None):
item = {ITEM_TYPE: CONTENT_TYPE.TEXT, # set the default type.
}
try:
self.do_mapping(item, xml, namespaces=NS)
except Exception as ex:
raise ParserError.parseMessageError(ex, provider)
return item
示例4: test_raise_parseMessageError
# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseMessageError [as 别名]
def test_raise_parseMessageError(self):
with assert_raises(ParserError) as error_context:
ex = Exception("Testing parseMessageError")
raise ParserError.parseMessageError(ex, self.provider)
exception = error_context.exception
self.assertTrue(exception.code == 1001)
self.assertTrue(exception.message == "Message could not be parsed")
self.assertIsNotNone(exception.system_exception)
self.assertEqual(exception.system_exception.args[0], "Testing parseMessageError")
self.assertEqual(len(self.mock_logger_handler.messages['error']), 1)
self.assertEqual(self.mock_logger_handler.messages['error'][0],
"ParserError Error 1001 - Message could not be parsed: "
"Testing parseMessageError on channel TestProvider")
示例5: _update
# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseMessageError [as 别名]
def _update(self, provider, update):
config = provider.get('config', {})
json_items = self._fetch_data(config, provider)
parsed_items = []
for item in json_items:
try:
parser = self.get_feed_parser(provider, item)
parsed_items.append(parser.parse(item))
except Exception as ex:
raise ParserError.parseMessageError(ex, provider, data=item)
return parsed_items
示例6: test_parse_message_error_save_data
# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseMessageError [as 别名]
def test_parse_message_error_save_data(self):
data = 'some data'
with assert_raises(ParserError):
try:
raise Exception("Err message")
except Exception as ex:
raise ParserError.parseMessageError(ex, self.provider, data=data)
self.assertEqual(len(self.mock_logger_handler.messages['error']), 1)
message = self.mock_logger_handler.messages['error'][0]
self.assertIn('file=', message)
filename = message.split('file=')[1]
with open(filename, 'r') as file:
self.assertEqual(data, file.read())
示例7: _get_decsription
# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseMessageError [as 别名]
def _get_decsription(self, lines, provider):
"""Lookup the bom product to determine the descriptive string, not finding this is a fatal error
:param lines:
:param provider:
:return:
"""
warning_str = 'Unknown'
bom_products_map = get_resource_service('vocabularies').find_one(req=None, _id='bom_products')
product = [x for x in bom_products_map.get('items', []) if x['qcode'] == lines[0].strip() and x['is_active']]
if len(product) > 0:
warning_str = product[0].get('name', '')
else:
logger.error('No BOM product mapping found for {}'.format(lines[0].strip()))
raise ParserError.parseMessageError(Exception('No BOM product'), provider, data=lines[0])
return warning_str
示例8: _update
# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseMessageError [as 别名]
def _update(self, provider):
"""Check data provider for data updates and returns new items (if any).
:param provider: data provider instance
:return: a list containing a list of new content items
:rtype: list
:raises IngestApiError: if data retrieval error occurs
:raises ParserError: if retrieved RSS data cannot be parsed
"""
config = provider.get('config', {})
try:
xml_data = self._fetch_data(config, provider)
data = feedparser.parse(xml_data)
except IngestApiError:
raise
except Exception as ex:
raise ParserError.parseMessageError(ex, provider)
# If provider last updated time is not available, set it to 1.1.1970
# so that it will be recognized as "not up to date".
# Also convert it to a naive datetime object (removing tzinfo is fine,
# because it is in UTC anyway)
t_provider_updated = provider.get('last_updated', utcfromtimestamp(0))
t_provider_updated = t_provider_updated.replace(tzinfo=None)
new_items = []
field_aliases = config.get('field_aliases')
for entry in data.entries:
t_entry_updated = utcfromtimestamp(timegm(entry.updated_parsed))
if t_entry_updated > t_provider_updated:
item = self._create_item(entry, field_aliases)
self.add_timestamps(item)
new_items.append(item)
return [new_items]
示例9: RssIngestService
# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseMessageError [as 别名]
from superdesk.io import register_provider
from superdesk.io.ingest_service import IngestService
from superdesk.utils import merge_dicts
from urllib.parse import quote as urlquote, urlsplit, urlunsplit
PROVIDER = "rss"
utcfromtimestamp = datetime.utcfromtimestamp
errors = [
IngestApiError.apiAuthError().get_error_description(),
IngestApiError.apiNotFoundError().get_error_description(),
IngestApiError.apiGeneralError().get_error_description(),
ParserError.parseMessageError().get_error_description(),
]
class RssIngestService(IngestService):
"""Ingest service for providing feeds received in RSS 2.0 format.
(NOTE: it should also work with other syndicated feeds formats, too, since
the underlying parser supports them, but for our needs RSS 2.0 is assumed)
"""
ItemField = namedtuple("ItemField", ["name", "name_in_data", "type"])
item_fields = [
ItemField("guid", "guid", str),
ItemField("uri", "guid", str),