本文整理汇总了Python中xml.parsers.expat.ErrorString方法的典型用法代码示例。如果您正苦于以下问题:Python expat.ErrorString方法的具体用法?Python expat.ErrorString怎么用?Python expat.ErrorString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.parsers.expat
的用法示例。
在下文中一共展示了expat.ErrorString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: feed
# 需要导入模块: from xml.parsers import expat [as 别名]
# 或者: from xml.parsers.expat import ErrorString [as 别名]
def feed(self, data, isFinal = 0):
if not self._parsing:
self.reset()
self._parsing = 1
self._cont_handler.startDocument()
try:
# The isFinal parameter is internal to the expat reader.
# If it is set to true, expat will check validity of the entire
# document. When feeding chunks, they are not normally final -
# except when invoked from close.
self._parser.Parse(data, isFinal)
except expat.error as e:
exc = SAXParseException(expat.ErrorString(e.code), e, self)
# FIXME: when to invoke error()?
self._err_handler.fatalError(exc)
示例2: feed
# 需要导入模块: from xml.parsers import expat [as 别名]
# 或者: from xml.parsers.expat import ErrorString [as 别名]
def feed(self, data, isFinal = 0):
if not self._parsing:
self.reset()
self._parsing = 1
self._cont_handler.startDocument()
try:
# The isFinal parameter is internal to the expat reader.
# If it is set to true, expat will check validity of the entire
# document. When feeding chunks, they are not normally final -
# except when invoked from close.
self._parser.Parse(data, isFinal)
except expat.error, e:
exc = SAXParseException(expat.ErrorString(e.code), e, self)
# FIXME: when to invoke error()?
self._err_handler.fatalError(exc)
示例3: test_parse_again
# 需要导入模块: from xml.parsers import expat [as 别名]
# 或者: from xml.parsers.expat import ErrorString [as 别名]
def test_parse_again(self):
parser = expat.ParserCreate()
file = StringIO.StringIO(data)
parser.ParseFile(file)
# Issue 6676: ensure a meaningful exception is raised when attempting
# to parse more than one XML document per xmlparser instance,
# a limitation of the Expat library.
with self.assertRaises(expat.error) as cm:
parser.ParseFile(file)
self.assertEqual(expat.ErrorString(cm.exception.code),
expat.errors.XML_ERROR_FINISHED)
示例4: test_error_code
# 需要导入模块: from xml.parsers import expat [as 别名]
# 或者: from xml.parsers.expat import ErrorString [as 别名]
def test_error_code(self):
from xml.parsers import expat
self.assertEqual(expat.ErrorString(self._get_error('foo').code),
expat.errors.XML_ERROR_SYNTAX)
示例5: test_parse_again
# 需要导入模块: from xml.parsers import expat [as 别名]
# 或者: from xml.parsers.expat import ErrorString [as 别名]
def test_parse_again(self):
parser = expat.ParserCreate()
file = BytesIO(data)
parser.ParseFile(file)
# Issue 6676: ensure a meaningful exception is raised when attempting
# to parse more than one XML document per xmlparser instance,
# a limitation of the Expat library.
with self.assertRaises(expat.error) as cm:
parser.ParseFile(file)
self.assertEqual(expat.ErrorString(cm.exception.code),
expat.errors.XML_ERROR_FINISHED)
示例6: _get_bugzilla_bug
# 需要导入模块: from xml.parsers import expat [as 别名]
# 或者: from xml.parsers.expat import ErrorString [as 别名]
def _get_bugzilla_bug(bug_id):
"""Fetch bug ``bug_id``.
:param int bug_id: The ID of a bug in the Bugzilla database.
:return: A FRIGGIN UNDOCUMENTED python-bugzilla THING.
:raises BugFetchError: If an error occurs while fetching the bug. For
example, a network timeout occurs or the bug does not exist.
"""
# Is bug ``bug_id`` in the cache?
if bug_id in _bugzilla:
LOGGER.debug('Bugzilla bug {0} found in cache.'.format(bug_id))
else:
LOGGER.info('Bugzilla bug {0} not in cache. Fetching.'.format(bug_id))
# Make a network connection to the Bugzilla server.
try:
bz_conn = bugzilla.RHBugzilla()
bz_conn.connect(BUGZILLA_URL)
except (TypeError, ValueError):
raise BugFetchError(
'Could not connect to {0}'.format(BUGZILLA_URL)
)
# Fetch the bug and place it in the cache.
try:
_bugzilla[bug_id] = bz_conn.getbugsimple(bug_id)
except Fault as err:
raise BugFetchError(
'Could not fetch bug. Error: {0}'.format(err.faultString)
)
except ExpatError as err:
raise BugFetchError(
'Could not interpret bug. Error: {0}'
.format(ErrorString(err.code))
)
return _bugzilla[bug_id]