當前位置: 首頁>>代碼示例>>Python>>正文


Python etree.DocumentInvalid方法代碼示例

本文整理匯總了Python中lxml.etree.DocumentInvalid方法的典型用法代碼示例。如果您正苦於以下問題:Python etree.DocumentInvalid方法的具體用法?Python etree.DocumentInvalid怎麽用?Python etree.DocumentInvalid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在lxml.etree的用法示例。


在下文中一共展示了etree.DocumentInvalid方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _validate

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import DocumentInvalid [as 別名]
def _validate(self, doc):
        """
        Do the actual validation.

        Arguments:
            doc (etree.ElementTree|str|bytes|pathlib.Path): the document. if etree: us as-is. if str/bytes: parse as XML string. If Path: read_text on it

        Returns: ValidationReport
        """
        report = ValidationReport()
        if isinstance(doc, Path):
            doc = ET.parse(str(doc))
        if isinstance(doc, (bytes, str)):
            doc = ET.fromstring(doc)
        try:
            self._xmlschema.assertValid(doc)
        except ET.DocumentInvalid as fail:
            for err in fail.error_log:  # pylint: disable=no-member
                report.add_error("Line %s: %s" % (err.line, err.message))
        return report 
開發者ID:OCR-D,項目名稱:core,代碼行數:22,代碼來源:xsd_validator.py

示例2: _is_valid

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import DocumentInvalid [as 別名]
def _is_valid(cls, xml, xsd_filepath, xsd_name):
        '''Returns whether or not an XML file is valid according to
        an XSD. Returns a tuple, the first value is a boolean indicating
        whether the validation passed or not. The second is a list of tuples,
        each containing the error message and the error line.

        Params:
          xml - etree of the XML to be validated
          xsd_filepath - full path to the XSD file
          xsd_name - string describing the XSD

        Returns:
          (is_valid, [(error_message_string, error_line_number)])
        '''
        xsd = etree.parse(xsd_filepath)
        schema = etree.XMLSchema(xsd)
        # With libxml2 versions before 2.9, this fails with this error:
        #    gmx_schema = etree.XMLSchema(gmx_xsd)
        # File "xmlschema.pxi", line 103, in
        # lxml.etree.XMLSchema.__init__ (src/lxml/lxml.etree.c:116069)
        # XMLSchemaParseError: local list type: A type, derived by list or
        # union, must have the simple ur-type definition as base type,
        # not '{http://www.opengis.net/gml/3.2}doubleList'., line 118
        try:
            schema.assertValid(xml)
        except etree.DocumentInvalid:
            log.info(
                'Validation errors found using schema {0}'.format(xsd_name))
            errors = []
            for error in schema.error_log:
                errors.append((error.message, error.line))
            errors.insert
            return False, errors
        return True, [] 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:36,代碼來源:validation.py

示例3: _parse_response

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import DocumentInvalid [as 別名]
def _parse_response(body, method_name):
        try:
            if log.getEffectiveLevel() <= logging.DEBUG:
                log.debug("Server response: \n%s", body.decode())

            response = etree.fromstring(body)
            schema.assertValid(response)
        except etree.DocumentInvalid:
            raise ValueError("Invalid body")

        result = response.xpath('//params/param/value/*')
        if result:
            return xml2py(result[0])

        fault = response.xpath('//fault/value/*')
        if fault:
            err = xml2py(fault[0])

            raise xml2py_exception(
                err.get('faultCode', exceptions.SystemError.code),
                err.get('faultString', 'Unknown error'),
                default_exc_class=exceptions.ServerError
            )

        raise exceptions.ParseError('Respond body for method "%s" '
                                    'not contains any response.', method_name) 
開發者ID:mosquito,項目名稱:aiohttp-xmlrpc,代碼行數:28,代碼來源:client.py

示例4: _parse_body

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import DocumentInvalid [as 別名]
def _parse_body(self, body):
        try:
            return self._parse_xml(body)
        except etree.DocumentInvalid:
            raise HTTPBadRequest 
開發者ID:mosquito,項目名稱:aiohttp-xmlrpc,代碼行數:7,代碼來源:handler.py

示例5: test_soap_request_with_inclusive_namespaces

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import DocumentInvalid [as 別名]
def test_soap_request_with_inclusive_namespaces(self):
        with open(os.path.join(interop_dir, "soap", "request.xml")) as req_fh:
            with self.assertRaises(etree.DocumentInvalid):
                XMLVerifier().verify(req_fh.read(),
                                     ca_pem_file=os.path.join(interop_dir, "soap", "ca.pem"),
                                     expect_references=False)
            req_fh.seek(0)
            XMLVerifier().verify(req_fh.read(),
                                 ca_pem_file=os.path.join(interop_dir, "soap", "ca.pem"),
                                 expect_references=False,
                                 validate_schema=False) 
開發者ID:XML-Security,項目名稱:signxml,代碼行數:13,代碼來源:test.py

示例6: create_permission_file

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import DocumentInvalid [as 別名]
def create_permission_file(path, domain_id, policy_element):
    print('creating permission')
    permissions_xsl_path = get_transport_template('dds', 'permissions.xsl')
    permissions_xsl = etree.XSLT(etree.parse(permissions_xsl_path))
    permissions_xsd_path = get_transport_schema('dds', 'permissions.xsd')
    permissions_xsd = etree.XMLSchema(etree.parse(permissions_xsd_path))

    kwargs = {}

    cert_path = os.path.join(os.path.dirname(path), 'cert.pem')
    cert_content = _utilities.load_cert(cert_path)
    kwargs['not_valid_before'] = etree.XSLT.strparam(cert_content.not_valid_before.isoformat())
    kwargs['not_valid_after'] = etree.XSLT.strparam(cert_content.not_valid_after.isoformat())

    if get_rmw_implementation_identifier() in _RMW_WITH_ROS_GRAPH_INFO_TOPIC:
        kwargs['allow_ros_discovery_topic'] = etree.XSLT.strparam('1')
    permissions_xml = permissions_xsl(policy_element, **kwargs)

    domain_id_elements = permissions_xml.findall('permissions/grant/*/domains/id')
    for domain_id_element in domain_id_elements:
        domain_id_element.text = domain_id

    try:
        permissions_xsd.assertValid(permissions_xml)
    except etree.DocumentInvalid as e:
        raise RuntimeError(str(e))

    with open(path, 'wb') as f:
        f.write(etree.tostring(permissions_xml, pretty_print=True)) 
開發者ID:ros2,項目名稱:sros2,代碼行數:31,代碼來源:_permission.py

示例7: load_policy

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import DocumentInvalid [as 別名]
def load_policy(policy_file_path):
    if not os.path.isfile(policy_file_path):
        raise FileNotFoundError("policy file '%s' does not exist" % policy_file_path)
    policy = etree.parse(policy_file_path)
    policy.xinclude()
    try:
        policy_xsd_path = get_policy_schema('policy.xsd')
        policy_xsd = etree.XMLSchema(etree.parse(policy_xsd_path))
        policy_xsd.assertValid(policy)
    except etree.DocumentInvalid as e:
        raise RuntimeError(str(e))
    return policy 
開發者ID:ros2,項目名稱:sros2,代碼行數:14,代碼來源:__init__.py

示例8: dump_policy

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import DocumentInvalid [as 別名]
def dump_policy(policy, stream):
    policy_xsl_path = get_policy_template('policy.xsl')
    policy_xsl = etree.XSLT(etree.parse(policy_xsl_path))
    policy = policy_xsl(policy)
    try:
        policy_xsd_path = get_policy_schema('policy.xsd')
        policy_xsd = etree.XMLSchema(etree.parse(policy_xsd_path))
        policy_xsd.assertValid(policy)
    except etree.DocumentInvalid as e:
        raise RuntimeError(str(e))
    stream.write(etree.tostring(policy, pretty_print=True).decode()) 
開發者ID:ros2,項目名稱:sros2,代碼行數:13,代碼來源:__init__.py


注:本文中的lxml.etree.DocumentInvalid方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。