当前位置: 首页>>代码示例>>Python>>正文


Python SubElement.find方法代码示例

本文整理汇总了Python中xml.etree.ElementTree.SubElement.find方法的典型用法代码示例。如果您正苦于以下问题:Python SubElement.find方法的具体用法?Python SubElement.find怎么用?Python SubElement.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xml.etree.ElementTree.SubElement的用法示例。


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

示例1: create_monitoring_data_xml

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import find [as 别名]
def create_monitoring_data_xml(logger,all_md_list):
    try:
        # create <monitoring-data>
        xml_md = Element(const.XML_TAG_MON_DATA)

        # add <topology_list>
        xml_topol_list = SubElement(xml_md, const.XML_TAG_TOPOL_LIST)
        
        ### md_dict={type:switch,network_name:xxx,node_name:xxx,
        ###             port:xxx,val_list:list(val_dict[param_name:value])}
        for md_dict in all_md_list:
            xml_topology = xml_topol_list.find(".//{0}[@{1}='{2}']"
                                                .format(const.XML_TAG_TOPOL,const.XML_ATTR_NAME,md_dict['network_name']))
            if xml_topology is None:
                # add <topology type='pyshical' name='xxx'>
                xml_topology = SubElement(xml_topol_list, const.XML_TAG_TOPOL,
                                           {const.XML_ATTR_TYPE:const.TYPE_NW_PHYSICAL,
                                            const.XML_ATTR_NAME:md_dict['network_name']
                                                })
            

            xml_node = xml_topology.find(".//{0}[@{1}='{2}']"
                                                .format(const.XML_TAG_NODE,const.XML_ATTR_ID,md_dict['node_name']))
            if xml_node is None:
                # add <node id='xxx' type='xxx'>
                xml_node = SubElement(xml_topology, const.XML_TAG_NODE,
                                        {const.XML_ATTR_ID:md_dict['node_name'],
                                         const.XML_ATTR_TYPE:md_dict['type']
                                            })
            xml_port = xml_node.find(".//{0}[@{1}='{2}']"
                                            .format(const.XML_TAG_PORT,const.XML_ATTR_NUM,md_dict['port']))
            if xml_port is None:
                # add <port num='xxx'>
                xml_port = SubElement(xml_node, const.XML_TAG_PORT,
                                        {const.XML_ATTR_NUM:md_dict['port']})
            
            for val_dict in md_dict['val_list']:
                timestamp = val_dict['timestamp']

                for key, value in val_dict.iteritems():
                    if key == 'timestamp':
                        continue

                    xml_param = xml_port.find(".//{0}[@{1}='{2}']"
                                                    .format(const.XML_TAG_PARAM,const.XML_ATTR_TYPE,key))
                    if xml_param is None:
                        # add <parameter type='xxx'>
                        xml_param = SubElement(xml_port, const.XML_TAG_PARAM,
                                                {const.XML_ATTR_TYPE:key})

                    # add <value timestamp='xxx'>xxx</value>
                    SubElement(xml_param, const.XML_TAG_VAL,
                                    {const.XML_ATTR_TIME_STAMP:timestamp}).text = value

    except Exception:
        logger.exception('create_monitoring_data_xml')
        return ''

    return util.prettify(xml_md)
开发者ID:HalasNet,项目名称:felix,代码行数:61,代码来源:sdn_md.py

示例2: create_monitoring_data_xml

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import find [as 别名]
def create_monitoring_data_xml(logger,all_md_list):
    try:
        # create <monitoring-data>
        xml_md = Element(const.XML_TAG_MON_DATA)

        # add <topology_list>
        xml_topol_list = SubElement(xml_md, const.XML_TAG_TOPOL_LIST)
        
        ### md_dict={nw_name:xxx,nw_type:slice,link_name:xxx,link_type:tn,
        ###             val_list:list(val_dict[param_name:value])}
        for md_dict in all_md_list:
            xml_topology = xml_topol_list.find(".//{0}[@{1}='{2}']"
                                                .format(const.XML_TAG_TOPOL,const.XML_ATTR_NAME,md_dict['network_name']))
            if xml_topology is None:
                # add <topology type='slice' name='xxx'>
                xml_topology = SubElement(xml_topol_list, const.XML_TAG_TOPOL,
                                           {const.XML_ATTR_TYPE:md_dict['network_type'],
                                            const.XML_ATTR_NAME:md_dict['network_name']
                                                })
            

            xml_link = xml_topology.find(".//{0}[@{1}='{2}']"
                                                .format(const.XML_TAG_LINK,const.XML_ATTR_ID,md_dict['link_name']))
            if xml_link is None:
                # add <link id='xxx' type='xxx'>
                xml_link = SubElement(xml_topology, const.XML_TAG_LINK,
                                        {const.XML_ATTR_ID:md_dict['link_name'],
                                         const.XML_ATTR_TYPE:md_dict['link_type']
                                            })
             
            for val_dict in md_dict['val_list']:
                timestamp = val_dict['timestamp']
  
                for key, value in val_dict.iteritems():
                    if key == 'timestamp':
                        continue
  
                    xml_param = xml_link.find(".//{0}[@{1}='{2}']"
                                                    .format(const.XML_TAG_PARAM,const.XML_ATTR_TYPE,key))
                    if xml_param is None:
                        # add <parameter type='xxx'>
                        xml_param = SubElement(xml_link, const.XML_TAG_PARAM,
                                                {const.XML_ATTR_TYPE:key})
  
                    # add <value timestamp='xxx'>xxx</value>
                    SubElement(xml_param, const.XML_TAG_VAL,
                                    {const.XML_ATTR_TIME_STAMP:timestamp}).text = value

    except Exception:
        logger.exception('create_monitoring_data_xml')
        return ''
    return util.prettify(xml_md)
开发者ID:HalasNet,项目名称:felix,代码行数:54,代码来源:tn_md.py

示例3: test_buildperson3

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import find [as 别名]
    def test_buildperson3(self):
        tree = Element("worldCrises", {"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" : "wc.xsd"})
        
        person3 = Person(elemid = "null",
                   name = "nully",
                   info_type = "",
                   info_birthdate_time = "",
                   info_birthdate_day = 0,
                   info_birthdate_month = 0,
                   info_birthdate_year = 0,
                   info_birthdate_misc = "",
                   info_nationality = "",
                   info_biography = "",
                   
                   orgrefs = [],
                   crisisrefs = [])
        ptree = SubElement(tree, "person", {"id" : "null"})     
        XMLHelpers.buildPerson(ptree, person3)
        
        
        elemid = ptree.attrib['id']
        name = ptree.find('.//name').text
        info_type = ptree.find('.//info').find('.//type').text
        info_birthdate_time = ptree.find('.//info').find('.//birthdate').find('.//time').text
        info_birthdate_day = int(ptree.find('.//info').find('.//birthdate').find('.//day').text)
        info_birthdate_month = int(ptree.find('.//info').find('.//birthdate').find('.//month').text)
        info_birthdate_year = int(ptree.find('.//info').find('.//birthdate').find('.//year').text)
        info_birthdate_misc = ptree.find('.//info').find('.//birthdate').find('.//misc').text
        info_nationality = ptree.find('.//info').find('.//nationality').text
        info_biography = ptree.find('.//info').find('.//biography').text

        orgrefs = [x.attrib['idref'] for x in ptree.findall('.//org')]
        crisisrefs = [x.attrib['idref'] for x in ptree.findall('.//crisis')]
       

        self.assertEqual(elemid, person3.elemid)
        self.assert_(name == person3.name)
        self.assert_(info_type == person3.info_type)
        self.assert_(info_birthdate_time == person3.info_birthdate_time)
        self.assert_(info_birthdate_day == person3.info_birthdate_day)
        self.assert_(info_birthdate_month == person3.info_birthdate_month)
        self.assert_(info_birthdate_year == person3.info_birthdate_year)
        self.assert_(info_birthdate_misc == person3.info_birthdate_misc)
        self.assert_(info_nationality == person3.info_nationality)
        self.assert_(info_biography == person3.info_biography)
        self.assert_(orgrefs == person3.orgrefs)
        self.assert_(crisisrefs == person3.crisisrefs)
开发者ID:hychyc071,项目名称:cs373-wc1-tests,代码行数:49,代码来源:jromeem-TestWC1.py

示例4: test_buildperson2

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import find [as 别名]
    def test_buildperson2(self):
        tree = Element("worldCrises", {"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" : "wc.xsd"})
        
        person2 = Person(elemid = "sally",
                   name = "Sally",
                   info_type = "seahorse",
                   info_birthdate_time = "0:00PM",
                   info_birthdate_day = 1124,
                   info_birthdate_month = 1132,
                   info_birthdate_year = 19000,
                   info_birthdate_misc = "born in a clamshell...",
                   info_nationality = "French",
                   info_biography = "Sally was boring...",
                   
                   orgrefs = ["seahorse united", "seahorse liberation front"],
                   crisisrefs = ["swamp famine", "west swamp drought"])
        ptree = SubElement(tree, "person", {"id" : "sally"})  
        
        XMLHelpers.buildPerson(ptree, person2)
        
        elemid = ptree.attrib['id'],
        name = ptree.find('.//name').text
        info_type = ptree.find('.//info').find('.//type').text
        info_birthdate_time = ptree.find('.//info').find('.//birthdate').find('.//time').text
        info_birthdate_day = int(ptree.find('.//info').find('.//birthdate').find('.//day').text)
        info_birthdate_month = int(ptree.find('.//info').find('.//birthdate').find('.//month').text)
        info_birthdate_year = int(ptree.find('.//info').find('.//birthdate').find('.//year').text)
        info_birthdate_misc = ptree.find('.//info').find('.//birthdate').find('.//misc').text
        info_nationality = ptree.find('.//info').find('.//nationality').text
        info_biography = ptree.find('.//info').find('.//biography').text

        orgrefs = [x.attrib['idref'] for x in ptree.findall('.//org')]
        crisisrefs = [x.attrib['idref'] for x in ptree.findall('.//crisis')]
        
        self.assertEqual(elemid[0], person2.elemid)
        self.assert_(name == person2.name)
        self.assert_(info_type == person2.info_type)
        self.assert_(info_birthdate_time == person2.info_birthdate_time)
        self.assert_(info_birthdate_day == person2.info_birthdate_day)
        self.assert_(info_birthdate_month == person2.info_birthdate_month)
        self.assert_(info_birthdate_year == person2.info_birthdate_year)
        self.assert_(info_birthdate_misc == person2.info_birthdate_misc)
        self.assert_(info_nationality == person2.info_nationality)
        self.assert_(info_biography == person2.info_biography)
        self.assert_(orgrefs == person2.orgrefs)
        self.assert_(crisisrefs == person2.crisisrefs)
开发者ID:jromeem,项目名称:cs373-wc,代码行数:48,代码来源:TestWC1.py

示例5: test_buildperson1

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import find [as 别名]
    def test_buildperson1(self):
        tree = Element("worldCrises", {"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" : "wc.xsd"})
        
        person1 = Person(elemid = "bobs",
                   name = "Bob",
                   info_type = "Salamander",
                   info_birthdate_time = "12:00PM",
                   info_birthdate_day = 12,
                   info_birthdate_month = 12,
                   info_birthdate_year = 1900,
                   info_birthdate_misc = "born under the full moon...",
                   info_nationality = "Swedish",
                   info_biography = "Bob swam a lot, as salamanders do...",
                   
                   orgrefs = ["salamanders united", "salamander liberation front"],
                   crisisrefs = ["swamp famine", "west swamp drought"])
        ptree = SubElement(tree, "person", {"id" : "bobs"})     
        XMLHelpers.buildPerson(ptree, person1)
        
        elemid = ptree.attrib['id'],
        name = ptree.find('.//name').text
        info_type = ptree.find('.//info').find('.//type').text
        info_birthdate_time = ptree.find('.//info').find('.//birthdate').find('.//time').text
        info_birthdate_day = int(ptree.find('.//info').find('.//birthdate').find('.//day').text)
        info_birthdate_month = int(ptree.find('.//info').find('.//birthdate').find('.//month').text)
        info_birthdate_year = int(ptree.find('.//info').find('.//birthdate').find('.//year').text)
        info_birthdate_misc = ptree.find('.//info').find('.//birthdate').find('.//misc').text
        info_nationality = ptree.find('.//info').find('.//nationality').text
        info_biography = ptree.find('.//info').find('.//biography').text

        orgrefs = [x.attrib['idref'] for x in ptree.findall('.//org')]
        crisisrefs = [x.attrib['idref'] for x in ptree.findall('.//crisis')]
              
        self.assertEqual(elemid[0], person1.elemid)
        self.assert_(name == person1.name)
        self.assert_(info_type == person1.info_type)
        self.assert_(info_birthdate_time == person1.info_birthdate_time)
        self.assert_(info_birthdate_day == person1.info_birthdate_day)
        self.assert_(info_birthdate_month == person1.info_birthdate_month)
        self.assert_(info_birthdate_year == person1.info_birthdate_year)
        self.assert_(info_birthdate_misc == person1.info_birthdate_misc)
        self.assert_(info_nationality == person1.info_nationality)
        self.assert_(info_biography == person1.info_biography)
        self.assert_(orgrefs == person1.orgrefs)
        self.assert_(crisisrefs == person1.crisisrefs)
开发者ID:hychyc071,项目名称:cs373-wc1-tests,代码行数:47,代码来源:jromeem-TestWC1.py

示例6: test_buildcrisis3

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import find [as 别名]
    def test_buildcrisis3(self):
        tree = Element("worldCrises", {"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" : "wc.xsd"})
        crisis1 = Crisis(

                elemid = "blank",
                name = "",
                misc = "",
                
                info_history = "",
                info_help = "",
                info_resources = "",
                info_type = "",


                
                date_time = "",
                date_day = 0,
                date_month = 0,
                date_year = 20,
                date_misc = "",
                

                location_city = "",
                location_region = "",

                location_country = "",
                
                impact_human_deaths = 0,
                impact_human_displaced = 0,
                impact_human_injured = 0,

                impact_human_missing = 0,
                impact_human_misc = "",
                
                impact_economic_amount = 0,
                impact_economic_currency = "",
                impact_economic_misc = "",
                
                orgrefs = ["", ""],
                personrefs = ["", ""]


                )
        ctree = SubElement(tree, "crisis", {"id" : "blank"})
        XMLHelpers.buildCrisis(ctree, crisis1)


        elemid = ctree.attrib['id']
        name = ctree.find('.//name').text
        misc = ctree.find('.//misc').text
        info_history = ctree.find('.//history').text
        info_help = ctree.find('.//help').text
        info_resources = ctree.find('.//resources').text
        info_type = ctree.find('.//type').text
        date_time = ctree.find('.//time').find('.//time').text
        date_day = int(ctree.find('.//time').find('.//day').text)
        date_month = int(ctree.find('.//time').find('.//month').text)
        date_year = int(ctree.find('.//time').find('.//year').text)
        date_misc = ctree.find('.//time').find('.//misc').text
        location_city = ctree.find('.//loc').find('.//city').text
        location_region = ctree.find('.//loc').find('.//region').text
        location_country = ctree.find('.//loc').find('.//country').text
        impact_human_deaths = int(ctree.find('.//impact').find('.//human').find('.//deaths').text)
        impact_human_displaced = int(ctree.find('.//impact').find('.//human').find('.//displaced').text)
        impact_human_injured = int(ctree.find('.//impact').find('.//human').find('.//injured').text)
        impact_human_missing = int(ctree.find('.//impact').find('.//human').find('.//missing').text)
        impact_human_misc = ctree.find('.//impact').find('.//human').find('.//misc').text
        impact_economic_amount = int(ctree.find('.//impact').find('.//economic').find('.//amount').text)
        impact_economic_currency = ctree.find('.//impact').find('.//economic').find('.//currency').text
        impact_economic_misc = ctree.find('.//impact').find('.//economic').find('.//misc').text
        orgrefs = [x.attrib['idref'] for x in ctree.findall('.//org')]
        personrefs = [x.attrib['idref'] for x in ctree.findall('.//person')]


        self.assert_(elemid == crisis1.elemid)
        self.assert_(name == crisis1.name)
        self.assert_(misc == crisis1.misc)
        self.assert_(info_history == crisis1.info_history)
        self.assert_(info_help == crisis1.info_help)
        self.assert_(info_resources == crisis1.info_resources)
        self.assert_(info_type == crisis1.info_type)
        self.assert_(date_time == crisis1.date_time)
        self.assert_(date_day == crisis1.date_day)
        self.assert_(date_month == crisis1.date_month)
        self.assert_(date_year == crisis1.date_year)
        self.assert_(date_misc == crisis1.date_misc)
        self.assert_(location_city == crisis1.location_city)

        self.assert_(location_region == crisis1.location_region)
        self.assert_(location_country == crisis1.location_country)
        self.assert_(impact_human_deaths == crisis1.impact_human_deaths)
        self.assert_(impact_human_displaced == crisis1.impact_human_displaced)
        self.assert_(impact_human_injured == crisis1.impact_human_injured)
        self.assert_(impact_human_missing == crisis1.impact_human_missing)
        self.assert_(impact_human_misc == crisis1.impact_human_misc)
        #self.assert_(impact_economic_amount == crisis1.impact_econmic_amount)
        self.assert_(impact_economic_currency == crisis1.impact_economic_currency)
        self.assert_(impact_economic_misc == crisis1.impact_economic_misc)
        self.assert_(orgrefs == crisis1.orgrefs)
        self.assert_(personrefs == crisis1.personrefs)
开发者ID:hychyc071,项目名称:cs373-wc1-tests,代码行数:102,代码来源:jromeem-TestWC1.py

示例7: test_buildcrisis2

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import find [as 别名]
    def test_buildcrisis2(self):
        tree = Element("worldCrises", {"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" : "wc.xsd"})
        crisis1 = Crisis(

                elemid = "plagues",
                name = "plagues",
                misc = "aids virus",
                
                info_history = "last year",
                info_help = "help",
                info_resources = "aids awareness",
                info_type = "virus attack",


                
                date_time = "1 pm",
                date_day = 1,
                date_month = 8,
                date_year = 1966,
                date_misc = "still happening",
                

                location_city = "LA",
                location_region = "California",

                location_country = "USA",
                
                impact_human_deaths = 20000,
                impact_human_displaced = 2540,
                impact_human_injured = 1123,

                impact_human_missing = 332,
                impact_human_misc = "none",
                
                impact_economic_amount = 442100,
                impact_economic_currency = "dollars",
                impact_economic_misc = "misc",
                
                orgrefs = ["dea", "cia"],
                personrefs = ["Magic Johnson", "me"]


                )
        ctree = SubElement(tree, "crisis", {"id" : "plagues"})
        XMLHelpers.buildCrisis(ctree, crisis1)


        elemid = ctree.attrib['id']
        name = ctree.find('.//name').text
        misc = ctree.find('.//misc').text
        info_history = ctree.find('.//history').text
        info_help = ctree.find('.//help').text
        info_resources = ctree.find('.//resources').text
        info_type = ctree.find('.//type').text
        date_time = ctree.find('.//time').find('.//time').text
        date_day = int(ctree.find('.//time').find('.//day').text)
        date_month = int(ctree.find('.//time').find('.//month').text)
        date_year = int(ctree.find('.//time').find('.//year').text)
        date_misc = ctree.find('.//time').find('.//misc').text
        location_city = ctree.find('.//loc').find('.//city').text
        location_region = ctree.find('.//loc').find('.//region').text
        location_country = ctree.find('.//loc').find('.//country').text
        impact_human_deaths = int(ctree.find('.//impact').find('.//human').find('.//deaths').text)
        impact_human_displaced = int(ctree.find('.//impact').find('.//human').find('.//displaced').text)
        impact_human_injured = int(ctree.find('.//impact').find('.//human').find('.//injured').text)
        impact_human_missing = int(ctree.find('.//impact').find('.//human').find('.//missing').text)
        impact_human_misc = ctree.find('.//impact').find('.//human').find('.//misc').text
        impact_economic_amount = int(ctree.find('.//impact').find('.//economic').find('.//amount').text)
        impact_economic_currency = ctree.find('.//impact').find('.//economic').find('.//currency').text
        impact_economic_misc = ctree.find('.//impact').find('.//economic').find('.//misc').text
        orgrefs = [x.attrib['idref'] for x in ctree.findall('.//org')]
        personrefs = [x.attrib['idref'] for x in ctree.findall('.//person')]


        self.assert_(elemid == crisis1.elemid)
        self.assert_(name == crisis1.name)
        #self.assert_(misc == crisis1.misc)
        self.assert_(info_history == crisis1.info_history)
        self.assert_(info_help == crisis1.info_help)
        self.assert_(info_resources == crisis1.info_resources)
        self.assert_(info_type == crisis1.info_type)
        self.assert_(date_time == crisis1.date_time)
        self.assert_(date_day == crisis1.date_day)
        self.assert_(date_month == crisis1.date_month)
        self.assert_(date_year == crisis1.date_year)
        self.assert_(date_misc == crisis1.date_misc)
        self.assert_(location_city == crisis1.location_city)

        self.assert_(location_region == crisis1.location_region)
        self.assert_(location_country == crisis1.location_country)
        self.assert_(impact_human_deaths == crisis1.impact_human_deaths)
        self.assert_(impact_human_displaced == crisis1.impact_human_displaced)
        self.assert_(impact_human_injured == crisis1.impact_human_injured)
        self.assert_(impact_human_missing == crisis1.impact_human_missing)
        self.assert_(impact_human_misc == crisis1.impact_human_misc)
        #self.assert_(impact_economic_amount == crisis1.impact_econmic_amount)
        self.assert_(impact_economic_currency == crisis1.impact_economic_currency)
        self.assert_(impact_economic_misc == crisis1.impact_economic_misc)
        self.assert_(orgrefs == crisis1.orgrefs)
        self.assert_(personrefs == crisis1.personrefs)
开发者ID:hychyc071,项目名称:cs373-wc1-tests,代码行数:102,代码来源:jromeem-TestWC1.py

示例8: test_buildorg3

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import find [as 别名]
    def test_buildorg3(self):
        tree = Element("worldCrises", {"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" : "wc.xsd"})
        
        organization3 = Organization(elemid = "new1",
    
                                    name = "n2123",
    
                                    info_type = "stant",
                                    info_history = "sadvass",
                                    info_contacts_phone = "sdfasdc2345",
                                    info_contacts_email = "asdjhkch234",
                                    info_contacts_address = "Japan",
                                    info_contacts_city = "hates",
                                    info_contacts_state = "baka",
                                    info_contacts_country = "gaijins",
                                    info_contacts_zip = "who",
    
                                    info_loc_city = "act",
                                    info_loc_region = "like",
                                    info_loc_country = "weaboos",
    
                                    personrefs = ["sushi", "fish"],
                                    crisisrefs = ["perl harbor", "atom bombs"],
    
                                    misc = "")

        otree = SubElement(tree, "organization", {"id" : "new1"})     
        XMLHelpers.buildOrganization(otree, organization3)
        
        elemid = otree.attrib['id'],
        name = otree.find('.//name').text
        info_type = otree.find('.//info').find('.//type').text
        info_history = otree.find('.//info').find('.//history').text
        info_contacts_phone = otree.find('.//info').find('.//contact').find('.//phone').text
        info_contacts_email = otree.find('.//info').find('.//contact').find('.//email').text
        info_contacts_address = otree.find('.//info').find('.//contact').find('.//mail').find('.//address').text
        info_contacts_city = otree.find('.//info').find('.//contact').find('.//mail').find('.//city').text
        info_contacts_state = otree.find('.//info').find('.//contact').find('.//mail').find('.//state').text
        info_contacts_country = otree.find('.//info').find('.//contact').find('.//mail').find('.//country').text
        info_contacts_zip = otree.find('.//info').find('.//contact').find('.//mail').find('.//zip').text
        info_loc_city = otree.find('.//info').find('.//loc').find('.//city').text
        info_loc_region = otree.find('.//info').find('.//loc').find('.//region').text
        info_loc_country = otree.find('.//info').find('.//loc').find('.//country').text

        personrefs = [x.attrib['idref'] for x in otree.findall('.//person')]
        crisisrefs = [x.attrib['idref'] for x in otree.findall('.//crisis')]
        misc = otree.find('.//misc').text
        
        #self.assert_(elemid == organization3.elemid)
        self.assert_(name == organization3.name)
        self.assert_(info_type == organization3.info_type)
        self.assert_(info_history == organization3.info_history)
        self.assert_(info_contacts_phone == organization3.info_contacts_phone)
        self.assert_(info_contacts_email == organization3.info_contacts_email)
        self.assert_(info_contacts_address == organization3.info_contacts_address)
        self.assert_(info_contacts_city == organization3.info_contacts_city)
        self.assert_(info_contacts_state == organization3.info_contacts_state)
        self.assert_(info_contacts_country == organization3.info_contacts_country)
        self.assert_(info_contacts_zip == organization3.info_contacts_zip)
        self.assert_(info_loc_city == organization3.info_loc_city)
        self.assert_(info_loc_region == organization3.info_loc_region)
        self.assert_(info_loc_country == organization3.info_loc_country)
        self.assert_(misc == organization3.misc)
        self.assert_(personrefs == organization3.personrefs)
        self.assert_(crisisrefs == organization3.crisisrefs)
开发者ID:hychyc071,项目名称:cs373-wc1-tests,代码行数:67,代码来源:jromeem-TestWC1.py

示例9: test_buildorg2

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import find [as 别名]
    def test_buildorg2(self):
        tree = Element("worldCrises", {"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" : "wc.xsd"})
        
        organization2 = Organization(elemid = "crap",
    
                                    name = "crap",
    
                                    info_type = "",
                                    info_history = "",
                                    info_contacts_phone = "",
                                    info_contacts_email = "",
                                    info_contacts_address = "",
                                    info_contacts_city = "",
                                    info_contacts_state = "",
                                    info_contacts_country = "",
                                    info_contacts_zip = "",
    
                                    info_loc_city = "",
                                    info_loc_region = "",
                                    info_loc_country = "",
    
                                    personrefs = [],
                                    crisisrefs = [],
    
                                    misc = "")

        otree = SubElement(tree, "organization", {"id" : "crap"})     
        XMLHelpers.buildOrganization(otree, organization2)
        
        elemid = otree.attrib['id'],
        name = otree.find('.//name').text
        info_type = otree.find('.//info').find('.//type').text
        info_history = otree.find('.//info').find('.//history').text
        info_contacts_phone = otree.find('.//info').find('.//contact').find('.//phone').text
        info_contacts_email = otree.find('.//info').find('.//contact').find('.//email').text
        info_contacts_address = otree.find('.//info').find('.//contact').find('.//mail').find('.//address').text
        info_contacts_city = otree.find('.//info').find('.//contact').find('.//mail').find('.//city').text
        info_contacts_state = otree.find('.//info').find('.//contact').find('.//mail').find('.//state').text
        info_contacts_country = otree.find('.//info').find('.//contact').find('.//mail').find('.//country').text
        info_contacts_zip = otree.find('.//info').find('.//contact').find('.//mail').find('.//zip').text
        info_loc_city = otree.find('.//info').find('.//loc').find('.//city').text
        info_loc_region = otree.find('.//info').find('.//loc').find('.//region').text
        info_loc_country = otree.find('.//info').find('.//loc').find('.//country').text

        personrefs = [x.attrib['idref'] for x in otree.findall('.//person')]
        crisisrefs = [x.attrib['idref'] for x in otree.findall('.//crisis')]
        misc = otree.find('.//misc').text
        
        #self.assert_(elemid == organization2.elemid)
        self.assert_(name == organization2.name)
        self.assert_(info_type == organization2.info_type)
        self.assert_(info_history == organization2.info_history)
        self.assert_(info_contacts_phone == organization2.info_contacts_phone)
        self.assert_(info_contacts_email == organization2.info_contacts_email)
        self.assert_(info_contacts_address == organization2.info_contacts_address)
        self.assert_(info_contacts_city == organization2.info_contacts_city)
        self.assert_(info_contacts_state == organization2.info_contacts_state)
        self.assert_(info_contacts_country == organization2.info_contacts_country)
        self.assert_(info_contacts_zip == organization2.info_contacts_zip)
        self.assert_(info_loc_city == organization2.info_loc_city)
        self.assert_(info_loc_region == organization2.info_loc_region)
        self.assert_(info_loc_country == organization2.info_loc_country)
        self.assert_(misc == organization2.misc)
        self.assert_(personrefs == organization2.personrefs)
        self.assert_(crisisrefs == organization2.crisisrefs)
开发者ID:hychyc071,项目名称:cs373-wc1-tests,代码行数:67,代码来源:jromeem-TestWC1.py

示例10: test_buildorg1

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import find [as 别名]
    def test_buildorg1(self):
        tree = Element("worldCrises", {"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" : "wc.xsd"})
        
        organization1 = Organization(elemid = "Franch",
    
                                    name = "French pride",
    
                                    info_type = "non-existant",
                                    info_history = "white flags",
                                    info_contacts_phone = "1234567890",
                                    info_contacts_email = "[email protected]",
                                    info_contacts_address = "French",
                                    info_contacts_city = "Paris",
                                    info_contacts_state = "Canada",
                                    info_contacts_country = "USA",
                                    info_contacts_zip = "7890",
    
                                    info_loc_city = "Alaska",
                                    info_loc_region = "Ukraine",
                                    info_loc_country = "Antarctica",
    
                                    personrefs = ["baquettes", "crumpets"],
                                    crisisrefs = ["war", "nazis"],
    
                                    misc = "")

        otree = SubElement(tree, "organization", {"id" : "Franch"})     
        XMLHelpers.buildOrganization(otree, organization1)
        
        elemid = otree.attrib['id'],
        name = otree.find('.//name').text
        info_type = otree.find('.//info').find('.//type').text
        info_history = otree.find('.//info').find('.//history').text
        info_contacts_phone = otree.find('.//info').find('.//contact').find('.//phone').text
        info_contacts_email = otree.find('.//info').find('.//contact').find('.//email').text
        info_contacts_address = otree.find('.//info').find('.//contact').find('.//mail').find('.//address').text
        info_contacts_city = otree.find('.//info').find('.//contact').find('.//mail').find('.//city').text
        info_contacts_state = otree.find('.//info').find('.//contact').find('.//mail').find('.//state').text
        info_contacts_country = otree.find('.//info').find('.//contact').find('.//mail').find('.//country').text
        info_contacts_zip = otree.find('.//info').find('.//contact').find('.//mail').find('.//zip').text
        info_loc_city = otree.find('.//info').find('.//loc').find('.//city').text
        info_loc_region = otree.find('.//info').find('.//loc').find('.//region').text
        info_loc_country = otree.find('.//info').find('.//loc').find('.//country').text

        personrefs = [x.attrib['idref'] for x in otree.findall('.//person')]
        crisisrefs = [x.attrib['idref'] for x in otree.findall('.//crisis')]
        misc = otree.find('.//misc').text
        
        #self.assert_(elemid == organization1.elemid)
        self.assert_(name == organization1.name)
        self.assert_(info_type == organization1.info_type)
        self.assert_(info_history == organization1.info_history)
        self.assert_(info_contacts_phone == organization1.info_contacts_phone)
        self.assert_(info_contacts_email == organization1.info_contacts_email)
        self.assert_(info_contacts_address == organization1.info_contacts_address)
        self.assert_(info_contacts_city == organization1.info_contacts_city)
        self.assert_(info_contacts_state == organization1.info_contacts_state)
        self.assert_(info_contacts_country == organization1.info_contacts_country)
        self.assert_(info_contacts_zip == organization1.info_contacts_zip)
        self.assert_(info_loc_city == organization1.info_loc_city)
        self.assert_(info_loc_region == organization1.info_loc_region)
        self.assert_(info_loc_country == organization1.info_loc_country)
        self.assert_(misc == organization1.misc)
        self.assert_(personrefs == organization1.personrefs)
        self.assert_(crisisrefs == organization1.crisisrefs)
开发者ID:hychyc071,项目名称:cs373-wc1-tests,代码行数:67,代码来源:jromeem-TestWC1.py

示例11: sorted

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import find [as 别名]
sites = sorted([site for site in resources.keys() if site != 'global'])
kavlan = resources['global']['kavlan']
hosts = []
for site in sites:
    hosts += map(lambda host: get_kavlan_host_name(host,
                    kavlan), resources[site]['hosts'])


for host in hosts:
    site = get_host_site(host)
    if state.find("./site[@id='" + site+ "']"):
        el_site = state.find("./site[@id='" + site+ "']")
    else:
        el_site = SubElement(state, 'site', attrib={'id': site})
    cluster = get_host_cluster(host)
    if el_site.find("./cluster[@id='" + cluster + "']"):
        el_cluster = el_site.find("./cluster[@id='" + cluster+ "']")
    else: 
        el_cluster =  SubElement(el_site, 'cluster', attrib={'id': cluster})
    SubElement(el_cluster, 'host', attrib={'id': host})



while True:
    for host, vms in list_vm(hosts).iteritems():
        el_host = state.find(".//host/[@id='" + host + "']")
        for vm in vms:
            SubElement(el_host, 'vm', attrib={'id': vm['id']})
    topology_plot(state, show=True)
    for vm in state.findall('vm'):
        root.remove(vm)
开发者ID:badock,项目名称:vm5k,代码行数:33,代码来源:liveplot.py

示例12: test_buildcrisis1

# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import find [as 别名]
    def test_buildcrisis1(self):
        tree = Element("worldCrises", {"xmlns:xsi" : "http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation" : "wc.xsd"})
        crisis1 = Crisis(

                    elemid = "hunger",
                    name = "hunger",
                    misc = "na",
                    
                    info_history = "this year",
                    info_help = "help",
                    info_resources = "awareness",
                    info_type = "hunger attack",

                    date_time = "11 am",
                    date_day = 18,
                    date_month = 03,
                    date_year = 2012,
                    date_misc = "still alive",
                    
                    location_city = "houston",
                    location_region = "texas",

                    location_country = "USA",
                    
                    impact_human_deaths = 200,
                    impact_human_displaced = 20,
                    impact_human_injured = 1,

                    impact_human_missing = 32,
                    impact_human_misc = "none",
                    
                    impact_economic_amount = 400,
                    impact_economic_currency = "yen",
                    impact_economic_misc = "misc",
                    
                    orgrefs = ["dea", "cia"],
                    personrefs = ["you", "me"]
                    )
        
        ctree = SubElement(tree, "crisis", {"id" : "hunger"})
        XMLHelpers.buildCrisis(ctree, crisis1)


        elemid = ctree.attrib['id']
        name = ctree.find('.//name').text
        misc = ctree.find('./misc').text
        info_history = ctree.find('.//history').text
        info_help = ctree.find('.//help').text
        info_resources = ctree.find('.//resources').text
        info_type = ctree.find('.//type').text
        date_time = ctree.find('.//time').find('.//time').text
        date_day = int(ctree.find('.//time').find('.//day').text)
        date_month = int(ctree.find('.//time').find('.//month').text)
        date_year = int(ctree.find('.//time').find('.//year').text)
        date_misc = ctree.find('.//time').find('.//misc').text
        location_city = ctree.find('.//loc').find('.//city').text
        location_region = ctree.find('.//loc').find('.//region').text
        location_country = ctree.find('.//loc').find('.//country').text
        impact_human_deaths = int(ctree.find('.//impact').find('.//human').find('.//deaths').text)
        impact_human_displaced = int(ctree.find('.//impact').find('.//human').find('.//displaced').text)
        impact_human_injured = int(ctree.find('.//impact').find('.//human').find('.//injured').text)
        impact_human_missing = int(ctree.find('.//impact').find('.//human').find('.//missing').text)
        impact_human_misc = ctree.find('.//impact').find('.//human').find('.//misc').text
        impact_economic_amount = int(ctree.find('.//impact').find('.//economic').find('.//amount').text)
        impact_economic_currency = ctree.find('.//impact').find('.//economic').find('.//currency').text
        impact_economic_misc = ctree.find('.//impact').find('.//economic').find('.//misc').text
        orgrefs = [x.attrib['idref'] for x in ctree.findall('.//org')]
        personrefs = [x.attrib['idref'] for x in ctree.findall('.//person')]


        self.assert_(elemid == crisis1.elemid)
        self.assert_(name == crisis1.name)
        self.assertEqual(misc , crisis1.misc)
        self.assert_(info_history == crisis1.info_history)
        self.assert_(info_help == crisis1.info_help)
        self.assert_(info_resources == crisis1.info_resources)
        self.assert_(info_type == crisis1.info_type)
        self.assert_(date_time == crisis1.date_time)
        self.assert_(date_day == crisis1.date_day)
        self.assert_(date_month == crisis1.date_month)
        self.assert_(date_year == crisis1.date_year)
        self.assert_(date_misc == crisis1.date_misc)
        self.assert_(location_city == crisis1.location_city)

        self.assert_(location_region == crisis1.location_region)
        self.assert_(location_country == crisis1.location_country)
        self.assert_(impact_human_deaths == crisis1.impact_human_deaths)
        self.assert_(impact_human_displaced == crisis1.impact_human_displaced)
        self.assert_(impact_human_injured == crisis1.impact_human_injured)
        self.assert_(impact_human_missing == crisis1.impact_human_missing)
        self.assert_(impact_human_misc == crisis1.impact_human_misc)
        self.assert_(impact_economic_amount == crisis1.impact_economic_amount)
        self.assert_(impact_economic_currency == crisis1.impact_economic_currency)
        self.assert_(impact_economic_misc == crisis1.impact_economic_misc)
        self.assert_(orgrefs == crisis1.orgrefs)
        self.assert_(personrefs == crisis1.personrefs)
开发者ID:jromeem,项目名称:cs373-wc,代码行数:98,代码来源:TestWC1.py


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