本文整理汇总了Python中xml.sax.SAXParseException方法的典型用法代码示例。如果您正苦于以下问题:Python sax.SAXParseException方法的具体用法?Python sax.SAXParseException怎么用?Python sax.SAXParseException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.sax
的用法示例。
在下文中一共展示了sax.SAXParseException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sax_parse_exception_str
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import SAXParseException [as 别名]
def test_sax_parse_exception_str(self):
# pass various values from a locator to the SAXParseException to
# make sure that the __str__() doesn't fall apart when None is
# passed instead of an integer line and column number
#
# use "normal" values for the locator:
str(SAXParseException("message", None,
self.DummyLocator(1, 1)))
# use None for the line number:
str(SAXParseException("message", None,
self.DummyLocator(None, 1)))
# use None for the column number:
str(SAXParseException("message", None,
self.DummyLocator(1, None)))
# use None for both:
str(SAXParseException("message", None,
self.DummyLocator(None, None)))
示例2: parse
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import SAXParseException [as 别名]
def parse(self):
"""
Loads the StyleSheets from the associated file, if it exists.
"""
try:
if os.path.isfile(self.__file):
parser = make_parser()
parser.setContentHandler(SheetParser(self))
with open(self.__file) as the_file:
parser.parse(the_file)
except (IOError, OSError, SAXParseException):
pass
#------------------------------------------------------------------------
#
# StyleSheet
#
#------------------------------------------------------------------------
示例3: parse
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import SAXParseException [as 别名]
def parse(self):
"""
Loads the BookList from the associated file, if it exists.
"""
try:
parser = make_parser()
parser.setContentHandler(BookParser(self, self.dbase))
with open(self.file) as the_file:
parser.parse(the_file)
except (IOError, OSError, ValueError, SAXParseException, KeyError,
AttributeError):
LOG.debug("Failed to parse book list", exc_info=True)
#-------------------------------------------------------------------------
#
# BookParser
#
#-------------------------------------------------------------------------
示例4: parse
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import SAXParseException [as 别名]
def parse(self):
"""
Loads the :class:`OptionList` from the associated file, if it exists.
"""
try:
if os.path.isfile(self.filename):
parser = make_parser()
parser.setContentHandler(OptionParser(self))
with open(self.filename, encoding="utf-8") as the_file:
parser.parse(the_file)
except (IOError, OSError, SAXParseException):
pass
#-------------------------------------------------------------------------
#
# OptionParser
#
#-------------------------------------------------------------------------
示例5: parse
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import SAXParseException [as 别名]
def parse(self):
"""
Loads the OptionList from the associated file, if it exists.
"""
try:
if os.path.isfile(self.filename):
parser = make_parser()
parser.setContentHandler(OptionParser(self))
parser.parse(self.filename)
except (IOError, OSError, SAXParseException):
pass
#-------------------------------------------------------------------------
#
# OptionParser
#
#-------------------------------------------------------------------------
示例6: compatibility_verbose
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import SAXParseException [as 别名]
def compatibility_verbose(self):
try:
compatible, serviceStatusVersion = checkUForgeCompatible(api)
if not compatible:
printer.out("Sorry but this version of Hammr (version = '" + str(
constants.VERSION) + "') is not compatible with the version of UForge (version = '" + str(
serviceStatusVersion) + "').", printer.ERROR)
printer.out(
"Please refer to 'Install Compatibility' section in the documentation to learn how to install a compatible version of Hammr.",
printer.ERROR)
sys.exit(2)
except (SAXParseException, RequestException):
printer.out("Cannot reached the UForge server. Please check the provided URL.", printer.ERROR)
sys.exit(2)
except Exception as e:
hammr_utils.print_uforge_exception(e)
sys.exit(2)
示例7: _create_client
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import SAXParseException [as 别名]
def _create_client(self, wsdl_name):
try:
client = get_client(self._hostname, wsdl_name, self._username,
self._password, self._cachedir, self._verify,
self._timeout,self._port)
except SAXParseException as e:
raise ParseError('%s\nFailed to parse wsdl. Is "%s" a valid '
'namespace?' % (e, wsdl_name))
# One situation that raises TransportError is when credentials are bad.
except (URLError, TransportError) as e:
raise ConnectionError(str(e))
return self._create_client_wrapper(client, wsdl_name)
示例8: test_expat_incomplete
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import SAXParseException [as 别名]
def test_expat_incomplete(self):
parser = create_parser()
parser.setContentHandler(ContentHandler()) # do nothing
self.assertRaises(SAXParseException, parser.parse, StringIO("<foo>"))
self.assertEqual(parser.getColumnNumber(), 5)
self.assertEqual(parser.getLineNumber(), 1)
示例9: test_sf_1513611
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import SAXParseException [as 别名]
def test_sf_1513611(self):
# Bug report: http://www.python.org/sf/1513611
sio = StringIO("invalid")
parser = make_parser()
from xml.sax import SAXParseException
self.assertRaises(SAXParseException, parser.parse, sio)
示例10: _check_descriptor_data
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import SAXParseException [as 别名]
def _check_descriptor_data(descriptor_data):
try:
data = base64.b64decode(descriptor_data).decode('utf-8')
except binascii.Error:
raise CSEContentsUnacceptable("The descriptor was not correctly base64 encoded.")
try:
g = Graph()
g.parse(data=data, format="application/rdf+xml")
except SAXParseException:
raise CSEContentsUnacceptable("The descriptor attribute does not conform to the "
"RDF/XML syntax as defined in RDF 1.1 XML Syntax.")
示例11: test_expat_incomplete
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import SAXParseException [as 别名]
def test_expat_incomplete(self):
parser = create_parser()
parser.setContentHandler(ContentHandler()) # do nothing
self.assertRaises(SAXParseException, parser.parse, StringIO("<foo>"))
示例12: do_soap_request
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import SAXParseException [as 别名]
def do_soap_request(self, methodname, port = -1, iproto = 'TCP', internalip = None):
for location, services in self.services.iteritems():
for service in services:
if service['type'] in UPNP_WANTED_SERVICETYPES:
o = urlparse(location)
endpoint = o[0] + '://' + o[1] + service['url']
if DEBUG:
log('upnp::do_soap_request: methodname', methodname, 'endpoint', endpoint, 'port', port, 'iproto', iproto, 'internalip', internalip)
headers, body = self.create_soap_request(methodname, port, iproto=iproto, internalip=internalip)
if DEBUG:
log('upnp::do_soap_request: headers', headers)
log('upnp::do_soap_request: body', body)
try:
req = urllib2.Request(url=endpoint, data=body, headers=headers)
f = urllib2.urlopen(req)
resp = f.read()
except urllib2.HTTPError as e:
resp = e.fp.read()
if DEBUG:
print_exc()
srch = SOAPResponseContentHandler(methodname)
if DEBUG:
log('upnp::do_soap_request: method', methodname, 'response', resp)
try:
srch.parse(resp)
except sax.SAXParseException as e:
se = srch.get_error()
if se is None:
srch.set_error(str(e))
except Exception as e:
srch.set_error(str(e))
yield srch
示例13: assertXMLWellFormed
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import SAXParseException [as 别名]
def assertXMLWellFormed(self, stream, msg=None):
"""asserts the XML stream is well-formed (no DTD conformance check)"""
from xml.sax import make_parser, SAXParseException
parser = make_parser()
try:
parser.parse(stream)
except SAXParseException:
if msg is None:
msg = 'XML stream not well formed'
self.fail(msg)
示例14: parseXmlFile
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import SAXParseException [as 别名]
def parseXmlFile(xmlFile, handler):
"""
Parses XML file by a given handler
"""
try:
with contextlib.closing(StringIO(readCachedFileContent(xmlFile))) as stream:
parse(stream, handler)
except (SAXParseException, UnicodeError), ex:
errMsg = "something seems to be wrong with "
errMsg += "the file '%s' ('%s'). Please make " % (xmlFile, ex)
errMsg += "sure that you haven't made any changes to it"
raise SqlmapInstallationException, errMsg
示例15: render
# 需要导入模块: from xml import sax [as 别名]
# 或者: from xml.sax import SAXParseException [as 别名]
def render(self, request):
try:
return super(DisclaimerElement, self).render(request)
except SAXParseException:
return ["Invalid XML template format for %s." % self._banner_filename]
except IOError:
return ["Disclaimer banner file %s could not be read or does not exit." % self._banner_filename]