• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python Model.Model类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中scap.Model.Model的典型用法代码示例。如果您正苦于以下问题:Python Model类的具体用法?Python Model怎么用?Python Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Model类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_load_attribute_required

def test_load_attribute_required():
    attr = Model.load(None, ET.fromstring('<test:RequiredAttributeFixture xmlns:test="http://jaymes.biz/test" required_attribute="test" />'))
    assert isinstance(attr, RequiredAttributeFixture)
    assert hasattr(attr, 'required_attribute')
    assert attr.required_attribute == 'test'

    with pytest.raises(RequiredAttributeException):
        attr = Model.load(None, ET.fromstring('<test:RequiredAttributeFixture xmlns:test="http://jaymes.biz/test" />'))
开发者ID:cjaymes,项目名称:pyscap,代码行数:8,代码来源:test_Model.py


示例2: test_load_root_model

def test_load_root_model():
    root = Model.load(None, ET.fromstring('<test:RootFixture xmlns:test="http://jaymes.biz/test" />'))
    assert isinstance(root, RootFixture)

    with pytest.raises(UnregisteredNamespaceException):
        Model.load(None, ET.fromstring('<test:RootFixture xmlns:test="http://jaymes.biz/derp" />'))

    with pytest.raises(TagMappingException):
        Model.load(None, ET.fromstring('<test:Derp xmlns:test="http://jaymes.biz/test" />'))
开发者ID:cjaymes,项目名称:pyscap,代码行数:9,代码来源:test_Model.py


示例3: test_namespace_registration

def test_namespace_registration():
    Model.register_namespace('scap.model.derp', 'http://jaymes.biz/derp')

    Model.xmlns_to_package('http://jaymes.biz/derp') == 'scap.model.derp'

    Model.unregister_namespace('scap.model.derp')

    with pytest.raises(UnregisteredNamespaceException):
        Model.xmlns_to_package('http://jaymes.biz/derp')
开发者ID:cjaymes,项目名称:pyscap,代码行数:9,代码来源:test_Model.py


示例4: test_load_element_min

def test_load_element_min():
    el = Model.load(None, ET.fromstring('''
        <test:MinMaxElementFixture xmlns:test="http://jaymes.biz/test">
        <test:min>test1</test:min>
        <test:min>test2</test:min>
        <test:min>test3</test:min>
        <test:max>test4</test:max>
        <test:max>test5</test:max>
        </test:MinMaxElementFixture>
        '''))
    assert isinstance(el, MinMaxElementFixture)

    assert hasattr(el, 'min')
    assert isinstance(el.min, ModelList)
    assert len(el.min) == 3
    assert el.min[0].text == 'test1'
    assert el.min[1].text == 'test2'
    assert el.min[2].text == 'test3'

    assert hasattr(el, 'max')
    assert isinstance(el.max, ModelList)
    assert len(el.max) == 2
    assert el.max[0].text == 'test4'
    assert el.max[1].text == 'test5'

    with pytest.raises(MinimumElementException):
        el = Model.load(None, ET.fromstring('''
            <test:MinMaxElementFixture xmlns:test="http://jaymes.biz/test">
            <test:min>test1</test:min>
            <test:max>test4</test:max>
            <test:max>test5</test:max>
            </test:MinMaxElementFixture>
            '''))

    with pytest.raises(MaximumElementException):
        el = Model.load(None, ET.fromstring('''
            <test:MinMaxElementFixture xmlns:test="http://jaymes.biz/test">
            <test:min>test1</test:min>
            <test:min>test2</test:min>
            <test:min>test3</test:min>
            <test:max>test4</test:max>
            <test:max>test5</test:max>
            <test:max>test6</test:max>
            </test:MinMaxElementFixture>
            '''))
开发者ID:cjaymes,项目名称:pyscap,代码行数:45,代码来源:test_Model.py


示例5: test_simple_remote

def test_simple_remote():
    model = Model.load(None, ET.fromstring('<test:XLinkFixture ' +
        'xmlns:test="http://jaymes.biz/test" ' +
        'xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" ' +
        'xlink:href="http://jaymes.biz/test.xml" />'))
    assert isinstance(model._elements, ModelList)
    assert len(model._elements) > 0
    assert isinstance(model._elements[0], RootFixture)
    assert isinstance(model._elements[0].EnclosedFixture, EnclosedFixture)
开发者ID:cjaymes,项目名称:pyscap,代码行数:9,代码来源:test_xlink.py


示例6: resolve

    def resolve(self, benchmark):
        ### Loading.Resolve.Items

        # For each Item in the Benchmark that has an extends property, resolve
        # it by using the following steps:

        # (1) if the Item is Group, resolve all the enclosed Items,
        for item_id in self.items:
            logger.debug('Resolving item: ' + item_id)
            self.items[item_id].resolve(benchmark)

        # (2) resolve the extended Item,
        if self.extends is None:
            return

        extended = self.get_extended(benchmark)
        extended.resolve(benchmark)

        # (3) prepend the property sequence from the extended Item to the
        # extending Item,
        # (5) remove duplicate properties and apply property overrides, and
        for name in self._model_map['attributes']:
            attr_map = self._model_map['attributes'][name]

            if 'in' in attr_map:
                attr_name = attr_map['in']
            else:
                xmlns, attr_name = Model.parse_tag(name)
                attr_name = attr_name.replace('-', '_')
            self.resolve_property(extended, attr_name)

        for element_def in self._model_map['elements']:
            if element_def['tag_name'].endswith('*'):
                continue

            if 'list' in element_def:
                self.resolve_property(extended, element_def['list'])
            elif 'dict' in element_def:
                self.resolve_property(extended, element_def['dict'])
            else:
                if 'in' in element_def:
                    name = element_def['in']
                else:
                    name = element_def['tag_name'].replace('-', '_')
            self.resolve_property(extended, name)

        # (4) if the Item is a Group, assign values for the id properties of
        # Items copied from the extended Group,
        if hasattr(extended, 'items') and len(extended.items) > 0:
            for ext_item in extended.items:
                # make a copy of the item and append to our items
                self.items.append(ext_item.copy())

        # (6) remove the extends property.
        self.extends = None
开发者ID:cjaymes,项目名称:pyscap,代码行数:55,代码来源:GroupType.py


示例7: check

    def check(self, benchmark, host, exports, import_names):
        content = Model.find_content(self.href)
        if content is None:
            raise ReferenceException(self.href + ' was not loaded')

        # find the named content
        if self.name is not None:
            content = content.find_reference(self.name)

        # apply content
        return content.check(host, exports, import_names)
开发者ID:cjaymes,项目名称:pyscap,代码行数:11,代码来源:CheckContentRefType.py


示例8: test_load_enclosed_model

def test_load_enclosed_model():
    root = RootFixture()
    el = Model.load(root, ET.fromstring('<test:EnclosedFixture xmlns:test="http://jaymes.biz/test" />'))
    assert isinstance(el, EnclosedFixture)

    el = Model.load(root, ET.fromstring('<EnclosedFixture />'))
    assert isinstance(el, EnclosedFixture)

    with pytest.raises(UnregisteredNamespaceException):
        Model.load(root, ET.fromstring('<test:EnclosedFixture xmlns:test="http://jaymes.biz/derp" />'))
    with pytest.raises(UnregisteredNamespaceException):
        Model.load(None, ET.fromstring('<EnclosedFixture />'))
    with pytest.raises(TagMappingException):
        Model.load(root, ET.fromstring('<Derp />'))
开发者ID:cjaymes,项目名称:pyscap,代码行数:14,代码来源:test_Model.py


示例9: test_oval_5_3_detected

def test_oval_5_3_detected():
    test_xml = '<oval_definitions ' + \
        'xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5" ' + \
        'xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" ' + \
        'xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5">' + \
        '<generator>' + \
        '<oval:product_name>The OVAL Repository</oval:product_name>' + \
        '<oval:schema_version>5.3</oval:schema_version>' + \
        '<oval:timestamp>2008-04-10T09:00:10.653-04:00</oval:timestamp>' + \
      '</generator>' + \
      '</oval_definitions>'
    model = Model.load(None, ET.fromstring(test_xml))
    from scap.model.oval_5.defs.OvalDefinitionsElement import OvalDefinitionsElement
    assert isinstance(model, OvalDefinitionsElement)
开发者ID:cjaymes,项目名称:pyscap,代码行数:14,代码来源:test_defs.py


示例10: test_simple_local

def test_simple_local():
    path = (
        pathlib.Path(str(pytest.config.rootdir)) / 'tests' / 'model' / 'test_xlink.xml'
    ).as_posix()
    if not path.startswith('/'):
        path = '/' + path
    model = Model.load(None, ET.fromstring('<test:XLinkFixture ' +
        'xmlns:test="http://jaymes.biz/test" ' +
        'xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" ' +
        'xlink:href="file://' + path + '" />'))
    assert isinstance(model._elements, ModelList)
    assert len(model._elements) > 0
    assert isinstance(model._elements[0], RootFixture)
    assert isinstance(model._elements[0].EnclosedFixture, EnclosedFixture)
开发者ID:cjaymes,项目名称:pyscap,代码行数:14,代码来源:test_xlink.py


示例11: test_load_element_wildcard_not_in

def test_load_element_wildcard_not_in():
    el = Model.load(None, ET.fromstring('''
        <test:WildcardElementNotInFixture xmlns:test2="http://jaymes.biz/test2" xmlns:test="http://jaymes.biz/test">
        <test:wildcard_element>test1</test:wildcard_element>
        <test2:wildcard_element>test2</test2:wildcard_element>
        </test:WildcardElementNotInFixture>
        '''))
    assert isinstance(el, WildcardElementNotInFixture)
    assert hasattr(el, '_elements')
    assert isinstance(el._elements, ModelList)
    assert len(el._elements) == 2
    assert isinstance(el._elements[0], EnclosedFixture)
    assert isinstance(el._elements[1], EnclosedFixture2)
    assert el._elements[0].text == 'test1'
    assert el._elements[1].text == 'test2'
开发者ID:cjaymes,项目名称:pyscap,代码行数:15,代码来源:test_Model.py


示例12: test_load_element_map_value_type

def test_load_element_map_value_type():
    el = Model.load(None, ET.fromstring('''
        <test:MapElementFixture xmlns:test="http://jaymes.biz/test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <test:map_value_type id="test1">test1</test:map_value_type>
        <test:map_value_type id="test2">test2</test:map_value_type>
        </test:MapElementFixture>
        '''))

    assert isinstance(el, MapElementFixture)

    assert hasattr(el, 'map_value_type')
    assert len(el.map_value_type) == 2

    assert 'test1' in el.map_value_type
    assert el.map_value_type['test1'] == 'test1'

    assert 'test2' in el.map_value_type
    assert el.map_value_type['test2'] == 'test2'
开发者ID:cjaymes,项目名称:pyscap,代码行数:18,代码来源:test_Model.py


示例13: test_load_element_append_nil

def test_load_element_append_nil():
    el = Model.load(None, ET.fromstring('''
        <test:AppendElementFixture xmlns:test="http://jaymes.biz/test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <test:append_nil xsi:nil="true" />
        <test:append_nil>test2</test:append_nil>
        </test:AppendElementFixture>
        '''))

    assert isinstance(el, AppendElementFixture)

    assert hasattr(el, 'append_nil')
    assert isinstance(el.append_nil, ModelList)
    assert len(el.append_nil) == 2

    assert el.append_nil[0] is None

    assert isinstance(el.append_nil[1], EnclosedFixture)
    assert el.append_nil[1].text == 'test2'
开发者ID:cjaymes,项目名称:pyscap,代码行数:18,代码来源:test_Model.py


示例14: resolve

    def resolve(self, benchmark):
        ### Loading.Resolve.Items

        # For each Item in the Benchmark that has an extends property, resolve
        # it by using the following steps:
        if self.extends is None:
            logger.debug('Extendable not extending: ' + self.id)
            return

        # (2) resolve the extended Item,
        extended = self.get_extended(benchmark)
        logger.debug('Found extended Extendable: ' + extended.id)
        extended.resolve(benchmark)

        # (3) prepend the property sequence from the extended Item to the
        # extending Item,
        # (5) remove duplicate properties and apply property overrides, and
        for name in self._model_map['attributes']:
            attr_map = self._model_map['attributes'][name]

            if 'in' in attr_map:
                attr_name = attr_map['in']
            else:
                xmlns, attr_name = Model.parse_tag(name)
                attr_name = attr_name.replace('-', '_')
            self.resolve_property(extended, attr_name)

        for element_def in self._model_map['elements']:
            if element_def['tag_name'].endswith('*'):
                continue

            if 'list' in element_def:
                self.resolve_property(extended, element_def['list'])
            elif 'dict' in tag_map:
                self.resolve_property(extended, element_def['dict'])
            else:
                if 'in' in element_def:
                    name = element_def['in']
                else:
                    name = element_def['tag_name'].replace('-', '_')
            self.resolve_property(extended, name)

        # (6) remove the extends property.
        self.extends = None
开发者ID:cjaymes,项目名称:pyscap,代码行数:44,代码来源:Extendable.py


示例15: test_def

def test_def():
    test_xml = '''<?xml version="1.0" encoding="UTF-8"?>
<oval_definitions
    xmlns:unix-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix"
    xmlns:ind-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent"
    xmlns:lin-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"
    xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5"
    xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<generator>
		<oval:product_name>Text Editors</oval:product_name>
		<oval:schema_version>5.8</oval:schema_version>
		<oval:timestamp>2013-12-17T12:00:00-04:00</oval:timestamp>
	</generator>
	<definitions>
    		<definition class="compliance" id="oval:gov.nist.usgcb.rhel:def:20000" version="2">
    			<metadata>
    				<title>Ensure that /tmp has its own partition or logical volume</title>
    				<description>The /tmp directory is a world-writable directory used for temporary file storage. Verify that it has its own partition or logical volume.</description>
    			</metadata>
    			<criteria>
    				<!-- <criterion test_ref="oval:gov.nist.usgcb.rhel:tst:20000" comment="Check in /etc/fstab for a /tmp mount point"/> -->
    				<criterion test_ref="oval:gov.nist.usgcb.rhel:tst:2000000" comment="Check if /tmp partition exists"/>
    			</criteria>
    		</definition>
	</definitions>
	<tests>
		<lin-def:partition_test id="oval:gov.nist.usgcb.rhel:tst:2000000" comment="Check if /tmp partition exists" check_existence="at_least_one_exists" check="at least one" version="1">
			<lin-def:object object_ref="oval:gov.nist.usgcb.rhel:obj:144120"/>
		</lin-def:partition_test>
    </tests>
    <objects>
		<lin-def:partition_object version="1" id="oval:gov.nist.usgcb.rhel:obj:144120">
			<lin-def:mount_point>/tmp</lin-def:mount_point>
		</lin-def:partition_object>
    </objects>
	<states>
	</states>
	<variables>
	</variables>
</oval_definitions>'''
    model = Model.load(None, ET.fromstring(test_xml))
    from scap.model.oval_5.defs.OvalDefinitionsElement import OvalDefinitionsElement
    assert isinstance(model, OvalDefinitionsElement)
开发者ID:cjaymes,项目名称:pyscap,代码行数:44,代码来源:test_defs_linux.py


示例16: test_load_element_append_type

def test_load_element_append_type():
    el = Model.load(None, ET.fromstring('''
        <test:AppendElementFixture xmlns:test="http://jaymes.biz/test">
        <test:append_type>1.1</test:append_type>
        <test:append_type>1.2</test:append_type>
        </test:AppendElementFixture>
        '''))

    assert isinstance(el, AppendElementFixture)

    assert hasattr(el, 'append_type')
    assert isinstance(el.append_type, ModelList)
    assert len(el.append_type) == 2

    assert isinstance(el.append_type[0], float)
    assert el.append_type[0] == 1.1

    assert isinstance(el.append_type[1], float)
    assert el.append_type[1] == 1.2
开发者ID:cjaymes,项目名称:pyscap,代码行数:19,代码来源:test_Model.py


示例17: test_load_element_append_class

def test_load_element_append_class():
    el = Model.load(None, ET.fromstring('''
        <test:AppendElementFixture xmlns:test="http://jaymes.biz/test">
        <test:append_class>test1</test:append_class>
        <test:append_class>test2</test:append_class>
        </test:AppendElementFixture>
        '''))

    assert isinstance(el, AppendElementFixture)

    assert hasattr(el, 'append_class')
    assert isinstance(el.append_class, ModelList)
    assert len(el.append_class) == 2

    assert isinstance(el.append_class[0], EnclosedFixture)
    assert el.append_class[0].text == 'test1'

    assert isinstance(el.append_class[1], EnclosedFixture)
    assert el.append_class[1].text == 'test2'
开发者ID:cjaymes,项目名称:pyscap,代码行数:19,代码来源:test_Model.py


示例18: test_in_and_out

def test_in_and_out():
    test_xml = b'<test:InitFixture xmlns:test="http://jaymes.biz/test" xmlns:test2="http://jaymes.biz/test2">' + \
        b'<test:list id="test1" />' + \
        b'<test:list id="test2" />' + \
        b'<test:list id="test3" />' + \
        b'<test:dict id="test4" />' + \
        b'<test:dict id="test5" />' + \
        b'<test:dict id="test6" />' + \
        b'<test:dict id="test7" />' + \
        b'<test:dict id="test8" />' + \
        b'<test:in_test id="test9" />' + \
        b'<test:dash-test id="test10" />' + \
        b'<test2:wildcard_element id="test11" />' + \
        b'<test:wildcard_element id="test12" />' + \
        b'<test:dict id="test13" />' + \
        b'<test:list id="test14" />' + \
        b'</test:InitFixture>'
    model = Model.load(None, ET.fromstring(test_xml))

    out_xml = ET.tostring(model.to_xml())
    print(test_xml)
    print(out_xml)
    assert out_xml == test_xml
开发者ID:cjaymes,项目名称:pyscap,代码行数:23,代码来源:test_Model.py


示例19: test_load_element_map_value_class

def test_load_element_map_value_class():
    el = Model.load(None, ET.fromstring('''
        <test:MapElementFixture xmlns:test="http://jaymes.biz/test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <test:map_value_class id="test1" tag="blue">text1</test:map_value_class>
        <test:map_value_class id="test2" tag="red">text2</test:map_value_class>
        </test:MapElementFixture>
        '''))

    assert isinstance(el, MapElementFixture)

    assert hasattr(el, 'map_value_class')
    assert len(el.map_value_class) == 2

    assert 'test1' in el.map_value_class
    assert isinstance(el.map_value_class['test1'], MappableElementFixture)
    assert el.map_value_class['test1'].id == 'test1'
    assert el.map_value_class['test1'].tag == 'blue'
    assert el.map_value_class['test1'].text == 'text1'

    assert 'test2' in el.map_value_class
    assert isinstance(el.map_value_class['test2'], MappableElementFixture)
    assert el.map_value_class['test2'].id == 'test2'
    assert el.map_value_class['test2'].tag == 'red'
    assert el.map_value_class['test2'].text == 'text2'
开发者ID:cjaymes,项目名称:pyscap,代码行数:24,代码来源:test_Model.py


示例20: test_parse_xsd

def test_parse_xsd():
    path = pathlib.Path(str(pytest.config.rootdir)) / 'tests' / 'model' / 'test_xs_stub.xsd'
    model = Model.load(None, ET.parse(str(path)).getroot())
开发者ID:cjaymes,项目名称:pyscap,代码行数:3,代码来源:test_xs_stub.py



注:本文中的scap.Model.Model类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python logger.exception函数代码示例发布时间:2022-05-27
下一篇:
Python scanner.Scanner类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap