def failUnlessXmlError(self,f,args,exc,domain,code,message,level,file,line):
        """Run function f, with arguments args and expect an exception exc;
        when the exception is raised, check the libxml2.lastError for
        expected values."""
        # disable the default error handler
        libxml2.registerErrorHandler(None,None)
        try:
	    apply(f,args)
        except exc:
            e = libxml2.lastError()
            if e is None:
                self.fail("lastError not set")
            if 0:
                print "domain = ",e.domain()
                print "code = ",e.code()
                print "message =",repr(e.message())
                print "level =",e.level()
                print "file =",e.file()
                print "line =",e.line()
                print
            self.failUnlessEqual(domain,e.domain())
            self.failUnlessEqual(code,e.code())
            self.failUnlessEqual(message,e.message())
            self.failUnlessEqual(level,e.level())
            self.failUnlessEqual(file,e.file())
            self.failUnlessEqual(line,e.line())
        else:
            self.fail("exception %s should have been raised" % exc)
Example #2
0
 def failUnlessXmlError(self, f, args, exc, domain, code, message, level,
                        file, line):
     """Run function f, with arguments args and expect an exception exc;
     when the exception is raised, check the libxml2.lastError for
     expected values."""
     # disable the default error handler
     libxml2.registerErrorHandler(None, None)
     try:
         apply(f, args)
     except exc:
         e = libxml2.lastError()
         if e is None:
             self.fail("lastError not set")
         if 0:
             print "domain = ", e.domain()
             print "code = ", e.code()
             print "message =", repr(e.message())
             print "level =", e.level()
             print "file =", e.file()
             print "line =", e.line()
             print
         self.failUnlessEqual(domain, e.domain())
         self.failUnlessEqual(code, e.code())
         self.failUnlessEqual(message, e.message())
         self.failUnlessEqual(level, e.level())
         self.failUnlessEqual(file, e.file())
         self.failUnlessEqual(line, e.line())
     else:
         self.fail("exception %s should have been raised" % exc)
Example #3
0
	def isIOError(self, file, docType):
		err = None
		try:
			err = libxml2.lastError()
		except:
			# Suppress exceptions.
			pass
		if (err is None):
			return False
		if err.domain() == libxml2.XML_FROM_IO:
			self.failCritical("failed to access the %s resource '%s'\n" % (docType, file))
Example #4
0
 def isIOError(self, file, docType):
     err = None
     try:
         err = libxml2.lastError()
     except:
         # Suppress exceptions.
         pass
     if (err is None):
         return False
     if err.domain() == libxml2.XML_FROM_IO:
         self.failCritical("failed to access the %s resource '%s'\n" %
                           (docType, file))
Example #5
0
    def validate_xml_string(self, sXml_content):
        ctxt = libxml2.createDocParserCtxt(sXml_content)

        #        ctxt.validate(1)

        ctxt.parseDocument()

        # detecte si au moins une erreur c'est produite
        try:
            error = libxml2.lastError()
        except:
            error = None

        if error != None:
            sMessage = _(
                "At least one error occured when validating XML file.")
            raise "metroValidationError", sMessage

        doc = ctxt.doc()
        doc.freeDoc()
	def relaxngOutput(type, message) :
		print "RelaxNG %s" % type
		e = libxml2.lastError()
		print "\t%s:%s" % (e.file(), e.line())
		print "\t%s" % message.strip()