当前位置: 首页>>代码示例>>Python>>正文


Python ParserError.newsmlTwoParserError方法代码示例

本文整理汇总了Python中superdesk.errors.ParserError.newsmlTwoParserError方法的典型用法代码示例。如果您正苦于以下问题:Python ParserError.newsmlTwoParserError方法的具体用法?Python ParserError.newsmlTwoParserError怎么用?Python ParserError.newsmlTwoParserError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在superdesk.errors.ParserError的用法示例。


在下文中一共展示了ParserError.newsmlTwoParserError方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse_message

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import newsmlTwoParserError [as 别名]
 def parse_message(self, tree, provider):
     """Parse NewsMessage."""
     items = []
     try:
         self.root = tree
         for item_set in tree.findall(self.qname("itemSet")):
             for item_tree in item_set:
                 item = self.parse_item(item_tree)
                 items.append(item)
         return items
     except Exception as ex:
         raise ParserError.newsmlTwoParserError(ex, provider)
开发者ID:Flowdeeps,项目名称:superdesk-1,代码行数:14,代码来源:newsml_2_0.py

示例2: parse

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import newsmlTwoParserError [as 别名]
 def parse(self, xml, provider=None):
     self.root = xml
     items = []
     try:
         header = self.parse_header(xml)
         for item_set in xml.findall(self.qname('itemSet')):
             for item_tree in item_set:
                 item = self.parse_item(item_tree)
                 item['priority'] = header['priority']
                 items.append(item)
         return items
     except Exception as ex:
         raise ParserError.newsmlTwoParserError(ex, provider)
开发者ID:MiczFlor,项目名称:superdesk-core,代码行数:15,代码来源:newsml_2_0.py

示例3: parse

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import newsmlTwoParserError [as 别名]
    def parse(self, xml, provider=None):
        self.root = xml
        items = []
        try:
            for item_set in xml.findall(self.qname('itemSet')):
                for item_tree in item_set:
                    # Ignore the packageItem, it has no guid
                    if 'guid' in item_tree.attrib:
                        item = self.parse_item(item_tree)
                        item['priority'] = 6
                        item['anpa_category'] = [{'qcode': 'f'}]
                        item['subject'] = [{'qcode': '04000000', 'name': subject_codes['04000000']}]
                        item.setdefault('word_count', get_word_count(item['body_html']))
                        # Hard code the urgency
                        item['urgency'] = 3
                        # Dateline is always Wellington in NZ
                        located = [c for c in app.locators.find_cities(country_code='NZ', state_code='NZ.G2') if
                                   c.get('city', '').lower() == 'wellington']
                        if len(located) == 1:
                            item['dateline'] = dict()
                            item['dateline']['located'] = located[0]

                        if item.get('body_html') and item['dateline']:
                            parsed = parse_html(item.get('body_html'), content='xml')
                            pars = parsed.xpath('//p')
                            for par in pars:
                                if not par.text:
                                    continue
                                # check the first par for a byline
                                if pars.index(par) == 0 and par.text.startswith('By '):
                                    item['byline'] = par.text.replace('By ', '')
                                    par.getparent().remove(par)
                                date, source, the_rest = par.text.partition(' (BusinessDesk) - ')
                                if source:
                                    item['dateline']['date'] = date_parser(date, fuzzy=True)
                                    par.text = the_rest
                                # remove the signoff if in the last par
                                if par.text == '(BusinessDesk)' and pars.index(par) + 1 == len(pars):
                                    par.getparent().remove(par)
                            item['body_html'] = to_string(parsed, remove_root_div=True)
                        locator_map = superdesk.get_resource_service('vocabularies').find_one(req=None, _id='locators')
                        if locator_map:
                            item['place'] = [x for x in locator_map.get('items', []) if x['qcode'].upper() == 'NZ']

                        items.append(item)
            return items
        except Exception as ex:
            raise ParserError.newsmlTwoParserError(ex, provider)
开发者ID:jerome-poisson,项目名称:superdesk-core,代码行数:50,代码来源:scoop_newsml_2_0.py

示例4: test_raise_newsmlTwoParserError

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import newsmlTwoParserError [as 别名]
 def test_raise_newsmlTwoParserError(self):
     with assert_raises(ParserError) as error_context:
         try:
             ex = Exception("Testing newsmlTwoParserError")
             raise ex
         except Exception:
             raise ParserError.newsmlTwoParserError(ex, self.provider)
     exception = error_context.exception
     self.assertTrue(exception.code == 1005)
     self.assertTrue(exception.message == "NewsML2 input could not be processed")
     self.assertIsNotNone(exception.system_exception)
     self.assertEqual(exception.system_exception.args[0], "Testing newsmlTwoParserError")
     self.assertEqual(len(self.mock_logger_handler.messages['error']), 1)
     self.assertEqual(self.mock_logger_handler.messages['error'][0],
                      "ParserError Error 1005 - NewsML2 input could not be processed: "
                      "Testing newsmlTwoParserError on channel TestProvider")
开发者ID:ancafarcas,项目名称:superdesk-core,代码行数:18,代码来源:errors_test.py

示例5: parse

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import newsmlTwoParserError [as 别名]
    def parse(self, xml, provider=None):
        self.root = xml
        try:
            item = self.parse_item(xml)
            if not item.get('headline'):
                item['headline'] = text_utils.get_text(item.get('body_html', ''), 'html')[:100]

            try:
                abstract = xml.xpath("//iptc:description[@role='drol:summary']", namespaces={'iptc': IPTC_NS})[0].text
            except IndexError:
                pass
            else:
                if abstract:
                    item['abstract'] = abstract
            return [item]
        except Exception as ex:
            raise ParserError.newsmlTwoParserError(ex, provider)
开发者ID:sjunaid,项目名称:superdesk-core,代码行数:19,代码来源:stt_newsml.py

示例6: parse

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import newsmlTwoParserError [as 别名]
 def parse(self, xml, provider=None):
     self.root = xml
     items = []
     try:
         header = self.parse_header(xml)
         for item_set in xml.findall(self.qname('itemSet')):
             for item_tree in item_set:
                 # Ignore the packageItem, it has no guid
                 if 'guid' in item_tree.attrib:
                     item = self.parse_item(item_tree)
                     item['priority'] = header['priority']
                     item['anpa_category'] = [{'qcode': 'f'}]
                     item['subject'] = [{'qcode': '04000000', 'name': subject_codes['04000000']}]
                     item.setdefault('word_count', get_word_count(item['body_html']))
                     items.append(item)
         return items
     except Exception as ex:
         raise ParserError.newsmlTwoParserError(ex, provider)
开发者ID:mscam,项目名称:superdesk-core,代码行数:20,代码来源:scoop_newsml_2_0.py

示例7: parse

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import newsmlTwoParserError [as 别名]
 def parse(self, xml, provider=None):
     self.root = xml
     items = []
     try:
         header = self.parse_header(xml)
         for item_set in xml.findall(self.qname('itemSet')):
             for item_tree in item_set:
                 item = self.parse_item(item_tree)
                 item['priority'] = header['priority']
                 items.append(item)
         else:
             if xml.tag.endswith('newsItem') or xml.tag.endswith('packageItem'):
                 item = self.parse_item(xml)
                 item.setdefault('priority', header['priority'])
                 items.append(item)
         return items
     except Exception as ex:
         raise ParserError.newsmlTwoParserError(ex, provider)
开发者ID:sjunaid,项目名称:superdesk-core,代码行数:20,代码来源:newsml_2_0.py

示例8: parse

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import newsmlTwoParserError [as 别名]

#.........这里部分代码省略.........
        try:
            item = self.parse_item(xml)
            if not item.get('headline'):
                item['headline'] = text_utils.get_text(item.get('body_html', ''), 'html')[:100]

            # abstract
            try:
                abstract = xml.xpath("//iptc:description[@role='drol:summary']", namespaces={'iptc': IPTC_NS})[0].text
            except IndexError:
                pass
            else:
                if abstract:
                    item['abstract'] = abstract

            # genre
            for genre_elt in xml.xpath("//iptc:genre", namespaces={'iptc': IPTC_NS}):
                qcode = genre_elt.get('qcode')
                if qcode is None:
                    continue
                elif qcode.startswith('sttgenre:'):
                    qcode = qcode[9:]
                    genre_data = {'qcode': qcode}
                    name_elt = genre_elt.find(self.qname('name'))
                    name = name_elt.text if name_elt is not None and name_elt.text else ""
                    try:
                        name = self.getVocabulary("genre", qcode, name)
                    except ValueError:
                        continue
                    else:
                        genre_data['name'] = name
                        item.setdefault('genre', []).append(genre_data)
                elif qcode.startswith('sttversion:'):
                    qcode = qcode[11:]
                    version_data = {'qcode': qcode, 'scheme': 'sttversion'}
                    name_elt = genre_elt.find(self.qname('name'))
                    name = name_elt.text if name_elt is not None and name_elt.text else ""
                    try:
                        name = self.getVocabulary("sttgenre", qcode, name)
                    except ValueError:
                        continue
                    else:
                        version_data['name'] = name
                        item.setdefault('subject', []).append(version_data)

            # location
            for location_elt in xml.xpath("//iptc:assert", namespaces={'iptc': IPTC_NS}):
                qcode = location_elt.get("qcode")
                if not qcode or not qcode.startswith("sttlocmeta:default:"):
                    continue
                qcode = qcode[19:]
                location_data = {"scheme": "sttlocmeta:default", "qcode": qcode}
                for broader_elt in location_elt.xpath(".//iptc:broader[@type='cpnat:geoArea']",
                                                      namespaces={'iptc': IPTC_NS}):
                    qcode = broader_elt.get('qcode')
                    if not qcode:
                        continue
                    for key, mapping in STT_LOCATION_MAP.items():
                        if qcode.startswith(key + ":"):
                            if "qcode" in mapping:
                                qcode = qcode[len(key) + 1:]
                            try:
                                name = broader_elt.find(self.qname('name')).text
                            except AttributeError:
                                name = ""
                            try:
                                name = self.getVocabulary(key, qcode, name)
                            except ValueError:
                                continue
                            else:
                                location_data[mapping["qcode"]] = qcode
                                if "name" in mapping:
                                    location_data[mapping["name"]] = name
                item.setdefault('place', []).append(location_data)

            # public editorial note
            if 'ednote' in item:
                # stt has specific roles for public and private editorial notes
                # so we remove ednote found by parent parser, as it takes first one
                # as a public note
                del item['ednote']
            try:
                ednote = xml.xpath("//iptc:edNote[@role='sttnote:public']", namespaces={'iptc': IPTC_NS})[0].text
            except IndexError:
                pass
            else:
                if ednote:
                    item['ednote'] = ednote

            # private editorial note
            try:
                private_note = xml.xpath("//iptc:edNote[@role='sttnote:private']", namespaces={'iptc': IPTC_NS})[0].text
            except IndexError:
                pass
            else:
                if private_note:
                    item.setdefault('extra', {})['sttnote_private'] = private_note

            return [item]
        except Exception as ex:
            raise ParserError.newsmlTwoParserError(ex, provider)
开发者ID:jerome-poisson,项目名称:superdesk-core,代码行数:104,代码来源:stt_newsml.py


注:本文中的superdesk.errors.ParserError.newsmlTwoParserError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。