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


Python ElementTree.parse方法代码示例

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


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

示例1: currency_data

# 需要导入模块: from elementtree.ElementTree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree.ElementTree import parse [as 别名]
 def currency_data(self, xml_url='http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml'):
     """Returns the most recent currency data with tuples."""
     now = datetime.now()
     today = u'-'.join([unicode(now.year), unicode(now.month), unicode(now.day)])
     if today == self.updated_date():
         return
     etree90 = ElementTree()
     try:
         data90 = urllib2.urlopen(xml_url)
         root90 = ElementTree.parse(etree90, data90)
         DATA90 = root90[2]
         DATA_list = []
         for DATA in DATA90:
             daily_data_list = []
             for daily_data in DATA:
                 daily_data_tuple = (daily_data.get('currency'), daily_data.get('rate'))
                 daily_data_list.append(daily_data_tuple)
             ddl = (DATA.get('time'), dict(daily_data_list))
             DATA_list.append(ddl)
             date = DATA_list[0][0]
         try:
             if self.date != date:
                 self.currencies = DATA_list
                 self.date = date
                 for date in self.currencies:
                     for key in date[1].keys():
                         if key not in self.codes:
                             self.codes.append(key)
                 self.amount_of_days = range(1,len(self.currencies)+1)
         except AttributeError:
             self.currencies = DATA_list
     except:
         pass
开发者ID:affinitic,项目名称:currency.converter,代码行数:35,代码来源:currency_data.py

示例2: tla_list

# 需要导入模块: from elementtree.ElementTree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree.ElementTree import parse [as 别名]
def tla_list(request):
    """
    """
    url = 'http://www.text-link-ads.com/xml.php?inventory_key=' + settings.TLA_INVENTORY_KEY + '&referer=' + request.META.get('REQUEST_URI', request.META.get('PATH_INFO', '/'))
    agent = '&user_agent=' + request.META['HTTP_USER_AGENT']
    links = ElementTree.parse(ElementTree(),urlopen(url+agent))
    return {
        'links': [ Link(link) for link in links ]
    }
开发者ID:alcides,项目名称:django-tla,代码行数:11,代码来源:tla.py

示例3: gettemp

# 需要导入模块: from elementtree.ElementTree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree.ElementTree import parse [as 别名]
def gettemp():
        cmd = [ "omreport", "chassis", "temps", "-fmt", "xml" ]
        (omstdin, omstdout) = popen2.popen2(cmd)               
        tree = ElementTree()                                   
        root = tree.parse(omstdin)                             
        iter = root.getiterator()                              
        sensors = []                                           
        for element in iter:                                   
                if element.tag == "TemperatureProbe":          
                        sensors.append(tempprobe(element))     
        return sensors                                         
开发者ID:japz,项目名称:check_dell,代码行数:13,代码来源:check_dell.py

示例4: getpdisks

# 需要导入模块: from elementtree.ElementTree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree.ElementTree import parse [as 别名]
def getpdisks(controller="0"):
        cmd = [ "omreport", "storage", "pdisk", "controller=" + controller, "-fmt", "xml" ]
        (omstdin, omstdout) = popen2.popen2(cmd)                                           
        tree = ElementTree()                                                               
        root = tree.parse(omstdin)                                                         
        iter = root.getiterator()                                                          
        pdisks = []                                                                        
        for element in iter:                                                               
                if element.tag == "DCStorageObject":                                       
                        pdisks.append(pdisk(element))                                      
        return pdisks                                                                      
开发者ID:japz,项目名称:check_dell,代码行数:13,代码来源:check_dell.py

示例5: GetElementsFromXML

# 需要导入模块: from elementtree.ElementTree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree.ElementTree import parse [as 别名]
    def GetElementsFromXML(self,filename):
        'Extracts a dictionary of elements from the gcc_xml file.'
        
        tree = ElementTree()
        try:
            tree.parse(filename)
        except ExpatError:
            raise InvalidXMLError, 'Not a XML file: %s' % filename

        root = tree.getroot()
        if root.tag != 'GCC_XML':
            raise InvalidXMLError, 'Not a valid GCC_XML file'

        # build a dictionary of id -> element, None
        elementlist = root.getchildren()
        elements = {}
        for element in elementlist:
            id = element.get('id')
            if id:
                elements[id] = element, None
        return elements
开发者ID:Karlan88,项目名称:xray,代码行数:23,代码来源:GCCXMLParser.py

示例6: getpower

# 需要导入模块: from elementtree.ElementTree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree.ElementTree import parse [as 别名]
def getpower():
        cmd = [ "omreport", "chassis", "pwrsupplies", "-fmt", "xml" ]
        (omstdin, omstdout) = popen2.popen2(cmd)                     
        tree = ElementTree()                                         
        root = tree.parse(omstdin)                                   
        iter = root.getiterator()                                    
        status = ""                                                  
        pwrsupplies = []                                             
        for element in iter:                                         
                if element.tag == "Redundancy":                      
                        status = element.get("status")               
                        redunstatus = element.findtext("RedunStatus")
                if element.tag == "PowerSupply":                     
                        pwrsupplies.append(powersupply(element))     
        return [(status, redunstatus), pwrsupplies]                  
开发者ID:japz,项目名称:check_dell,代码行数:17,代码来源:check_dell.py

示例7: exit

# 需要导入模块: from elementtree.ElementTree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree.ElementTree import parse [as 别名]
comp_path = os.path.join(persistence_path, "Component")
prop_path = os.path.join(persistence_path, "Property")
if not os.path.exists(persistence_path) or \
        not os.path.exists(cat_path) or \
        not os.path.exists(comp_path) or \
        not os.path.exists(prop_path):
    print "INVALID PROJECT DIRECTORY"
    exit(0)
    
et = ElementTree()
    
#transform categories
print "Transforming Categories..."
for cat_fname in os.listdir(cat_path):
    fpath = os.path.join(cat_path, cat_fname)
    et.parse(fpath)
    version = et.getroot().get("version")
    if not version:
        print "\tTransforming %s..." % cat_fname
        root = Element("category",
                        {"version": "1.1",
                         "name": et.find("name").text.strip(),
                         "description": et.find("description").text.strip()})
        et = ElementTree(root)
        et.write(fpath, indent=True)
    elif version == "1.0":
        print "\tTransforming %s..." % cat_fname
        root = Element("category",
                        {"version": "1.1",
                         "name": et.getroot().get("name"),
                         "description": et.getroot().get("description")})
开发者ID:thousandparsec-obsolete,项目名称:tpruledev,代码行数:33,代码来源:transform_objects.py

示例8: len

# 需要导入模块: from elementtree.ElementTree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree.ElementTree import parse [as 别名]
#!/usr/bin/python
import sys
from elementtree.ElementTree import ElementTree

COLOR_NONE = "\033[m"
COLOR_GREEN = "\033[01;32m"
COLOR_RED = "\033[01;31m"
COLOR_YELLOW = "\033[01;33m"

if len(sys.argv) < 2:
    print "Error: Params not well defined"

xml_paths = sys.argv[1:] 

for xml_path in xml_paths:
    tree = ElementTree()
    
    try:
        tree.parse(xml_path)
    except:
        print COLOR_RED + "ERROR:[ " + COLOR_YELLOW + xml_path + COLOR_RED + " ] is not a well formed xml file!!!!" + COLOR_NONE
        continue
    print COLOR_GREEN + "Info:[ " + COLOR_YELLOW + xml_path + COLOR_GREEN + " ] The XML file is normal!" + COLOR_NONE
开发者ID:DreamsFuture,项目名称:pytools,代码行数:25,代码来源:xmlwf_check.py

示例9: dir

# 需要导入模块: from elementtree.ElementTree import ElementTree [as 别名]
# 或者: from elementtree.ElementTree.ElementTree import parse [as 别名]
	"Titles" : (TitlesToXML, XMLToTitles),
	"Fonts" : (ListToXML, XMLToList),
	#"Rectangles" : (ListToXML, XMLToList),
	#"" : XMLToMenuItems,
	#"" : XMLToMenuItems,


}



if __name__ == "__main__":

	import sys	
	from elementtree import ElementTree
	parsed = ElementTree.parse(sys.argv[1])	
	
	props = {}
	
	print dir(parsed)
	for ctrl in parsed.findall("CONTROL"):
		print ControlFromXML(ctrl)
		sys.exit()
	
		props['ClientRect'] = ParseRect(ctrl.find("CLIENTRECT"))
			
		props['Rectangle'] = ParseRect(ctrl.find("RECTANGLE"))

		props['Font'] = ParseLogFont(ctrl.find("FONT"))
		
		props['Titles'] = ParseTitles(ctrl.find("TITLES"))
开发者ID:KovalevAndrey,项目名称:pywinauto,代码行数:33,代码来源:__DeadCodeRepository__.py


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