当前位置: 首页>>代码示例>>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;未经允许,请勿转载。