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


Python ParserError.parseFileError方法代码示例

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


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

示例1: _update

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseFileError [as 别名]
    def _update(self, provider):
        self.provider = provider
        self.path = provider.get('config', {}).get('path', None)

        if not self.path:
            logger.info('No path')
            return []

        for filename in get_sorted_files(self.path, sort_by=FileSortAttributes.created):
            try:
                filepath = os.path.join(self.path, filename)
                if os.path.isfile(filepath):
                    stat = os.lstat(filepath)
                    last_updated = datetime.fromtimestamp(stat.st_mtime, tz=utc)
                    if self.is_latest_content(last_updated, provider.get('last_updated')):
                        item = self.parser.parse_file(filepath, provider)
                        dpa_derive_dateline(item)

                        self.move_file(self.path, filename, provider=provider, success=True)
                        yield [item]
                    else:
                        self.move_file(self.path, filename, provider=provider, success=True)
            except Exception as ex:
                self.move_file(self.path, filename, provider=provider, success=False)
                raise ParserError.parseFileError('DPA', filename, ex, provider)
开发者ID:ancafarcas,项目名称:superdesk,代码行数:27,代码来源:dpa.py

示例2: parse_file

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseFileError [as 别名]
    def parse_file(self, filename, provider):
        try:
            path = provider.get('config', {}).get('path', None)

            if not path:
                return []

            item = self.parser.parse_file(os.path.join(path, filename), provider)

            return [item]
        except Exception as ex:
            raise ParserError.parseFileError('Teletype', filename, ex, provider)
开发者ID:verifiedpixel,项目名称:superdesk-core,代码行数:14,代码来源:teletype.py

示例3: parse_file

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseFileError [as 别名]
    def parse_file(self, filename, provider):
        try:
            self.path = provider.get('config', {}).get('path', None)

            if not self.path:
                return []

            with open(os.path.join(self.path, filename), 'r') as f:
                item = self.parser.parse_message(etree.fromstring(f.read()), provider)

            return [item]
        except Exception as ex:
            self.move_file(self.path, filename, provider=provider, success=False)
            raise ParserError.parseFileError('AAP', filename, ex, provider)
开发者ID:Flowdeeps,项目名称:superdesk-1,代码行数:16,代码来源:aap.py

示例4: test_raise_parseFileError

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseFileError [as 别名]
 def test_raise_parseFileError(self):
     with assert_raises(ParserError) as error_context:
         try:
             raise Exception("Testing parseFileError")
         except Exception as ex:
             raise ParserError.parseFileError('afp', 'test.txt', ex, self.provider)
     exception = error_context.exception
     self.assertTrue(exception.code == 1002)
     self.assertTrue(exception.message == "Ingest file could not be parsed")
     self.assertIsNotNone(exception.system_exception)
     self.assertEqual(exception.system_exception.args[0], "Testing parseFileError")
     self.assertEqual(len(self.mock_logger_handler.messages['error']), 1)
     message = self.mock_logger_handler.messages['error'][0]
     self.assertIn("ParserError Error 1002 - Ingest file could not be parsed", message)
     self.assertIn("Testing parseFileError on channel TestProvider", message)
     self.assertIn("source=afp", message)
     self.assertIn("file=test.txt", message)
开发者ID:jerome-poisson,项目名称:superdesk-core,代码行数:19,代码来源:errors_test.py

示例5: parse_file

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseFileError [as 别名]
    def parse_file(self, filename, provider):
        try:
            path = provider.get('config', {}).get('path', None)

            if not path:
                return []

            with open(os.path.join(path, filename), 'r') as f:
                item = self.parser.parse_message(etree.fromstring(f.read()), provider)

                item['firstcreated'] = normalize_date(item.get('firstcreated'), self.tz)
                item['versioncreated'] = normalize_date(item.get('versioncreated'), self.tz)

            return [item]
        except Exception as ex:
            self.move_file(self.path, filename, provider=provider, success=False)
            raise ParserError.parseFileError('AAP', filename, ex, provider)
开发者ID:akintolga,项目名称:superdesk-server,代码行数:19,代码来源:aap.py

示例6: test_raise_parseFileError

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseFileError [as 别名]
 def test_raise_parseFileError(self):
     with assert_raises(ParserError) as error_context:
         try:
             ex = Exception("Testing parseFileError")
             raise ex
         except Exception:
             raise ParserError.parseFileError('afp', 'test.txt', ex, self.provider)
     exception = error_context.exception
     self.assertTrue(exception.code == 1002)
     self.assertTrue(exception.message == "Ingest file could not be parsed")
     self.assertIsNotNone(exception.system_exception)
     self.assertEqual(exception.system_exception.args[0], "Testing parseFileError")
     self.assertEqual(len(self.mock_logger_handler.messages['error']), 2)
     self.assertEqual(self.mock_logger_handler.messages['error'][0],
                      "Source Type: afp - File: test.txt could not be processed")
     self.assertEqual(self.mock_logger_handler.messages['error'][1],
                      "ParserError Error 1002 - Ingest file could not be parsed: "
                      "Testing parseFileError on channel TestProvider")
开发者ID:ancafarcas,项目名称:superdesk-core,代码行数:20,代码来源:errors_test.py

示例7: _update

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseFileError [as 别名]
    def _update(self, provider):
        self.provider = provider
        self.path = provider.get("config", {}).get("path", None)

        if not self.path:
            logger.warn(
                "File Feeding Service {} is configured without path. Please check the configuration".format(
                    provider["name"]
                )
            )
            return []

        registered_parser = self.get_feed_parser(provider)
        for filename in get_sorted_files(self.path, sort_by=FileSortAttributes.created):
            try:
                file_path = os.path.join(self.path, filename)
                if os.path.isfile(file_path):
                    stat = os.lstat(file_path)
                    last_updated = datetime.fromtimestamp(stat.st_mtime, tz=utc)

                    if self.is_latest_content(last_updated, provider.get("last_updated")):
                        if isinstance(registered_parser, XMLFeedParser):
                            with open(file_path, "rt") as f:
                                xml = ElementTree.parse(f)
                                parser = self.get_feed_parser(provider, xml.getroot())
                                item = parser.parse(xml, provider)
                        else:
                            parser = self.get_feed_parser(provider, file_path)
                            item = parser.parse(file_path, provider)

                        self.after_extracting(item, provider)
                        self.move_file(self.path, filename, provider=provider, success=True)

                        if isinstance(item, list):
                            yield item
                        else:
                            yield [item]
                    else:
                        self.move_file(self.path, filename, provider=provider, success=True)
            except Exception as ex:
                self.move_file(self.path, filename, provider=provider, success=False)
                raise ParserError.parseFileError("{}-{}".format(provider["name"], self.NAME), filename, ex, provider)

        push_notification("ingest:update")
开发者ID:copyfun,项目名称:superdesk-core,代码行数:46,代码来源:file_service.py

示例8: parse_file

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseFileError [as 别名]
    def parse_file(self, filename, provider):
        """
        Given a filename of a file to be ingested prepend the path found in the providers config and call
        the underlying parse_file method
        :param filename:
        :param provider:
        :return: The item parsed from the file
        """
        try:
            path = provider.get('config', {}).get('path', None)

            if not path:
                return []

            item = self.parser.parse_file(os.path.join(path, filename), provider)

            return [item]
        except Exception as ex:
            raise ParserError.parseFileError('DPA', filename, ex, provider)
开发者ID:ancafarcas,项目名称:superdesk,代码行数:21,代码来源:dpa.py

示例9: _update

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseFileError [as 别名]
    def _update(self, provider):
        self.provider = provider
        self.path = provider.get('config', {}).get('path', None)

        if not self.path:
            logger.warn('File Feeding Service {} is configured without path. Please check the configuration'
                        .format(provider['name']))
            return []

        registered_parser = self.get_feed_parser(provider)
        for filename in get_sorted_files(self.path, sort_by=FileSortAttributes.created):
            try:
                file_path = os.path.join(self.path, filename)
                if os.path.isfile(file_path):
                    stat = os.lstat(file_path)
                    last_updated = datetime.fromtimestamp(stat.st_mtime, tz=utc)

                    if self.is_latest_content(last_updated, provider.get('last_updated')):
                        if isinstance(registered_parser, XMLFeedParser):
                            with open(file_path, 'r') as f:
                                xml_string = etree.fromstring(f.read())
                                parser = self.get_feed_parser(provider, xml_string)
                                item = parser.parse(xml_string, provider)
                        else:
                            parser = self.get_feed_parser(provider, file_path)
                            item = parser.parse(file_path, provider)

                        self.after_extracting(item, provider)
                        self.move_file(self.path, filename, provider=provider, success=True)

                        yield [item]
                    else:
                        self.move_file(self.path, filename, provider=provider, success=True)
            except Exception as ex:
                self.move_file(self.path, filename, provider=provider, success=False)
                raise ParserError.parseFileError('{}-{}'.format(provider['name'], self.NAME), filename, ex, provider)

        push_notification('ingest:update')
开发者ID:ahilles107,项目名称:superdesk-core,代码行数:40,代码来源:file_service.py

示例10: AAPIngestService

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseFileError [as 别名]
from datetime import datetime
from .nitf import NITFParser
from superdesk.io.file_ingest_service import FileIngestService
from superdesk.utc import utc, timezone
from superdesk.notification import push_notification
from superdesk.io import register_provider
from ..etree import etree, ParseError as etreeParserError
from superdesk.utils import get_sorted_files, FileSortAttributes
from superdesk.errors import ParserError, ProviderError


logger = logging.getLogger(__name__)
PROVIDER = 'aap'
errors = [ParserError.nitfParserError().get_error_description(),
          ProviderError.ingestError().get_error_description(),
          ParserError.parseFileError().get_error_description()]


class AAPIngestService(FileIngestService):
    """AAP Ingest Service"""

    def __init__(self):
        self.tz = timezone('Australia/Sydney')
        self.parser = NITFParser()

    def prepare_href(self, href):
        return href

    def _update(self, provider):
        self.provider = provider
        self.path = provider.get('config', {}).get('path', None)
开发者ID:Flowdeeps,项目名称:superdesk-1,代码行数:33,代码来源:aap.py

示例11: parse

# 需要导入模块: from superdesk.errors import ParserError [as 别名]
# 或者: from superdesk.errors.ParserError import parseFileError [as 别名]
 def parse(self, image_path, provider=None):
     try:
         item = self.parse_item(image_path)
         return item
     except Exception as ex:
         raise ParserError.parseFileError(exception=ex, provider=provider)
开发者ID:jerome-poisson,项目名称:superdesk-core,代码行数:8,代码来源:image_iptc.py


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