16 Star 45 Fork 46

现任明教教主-乾颐堂/qytang_Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
2016.02.28 XML解析练习 1.87 KB
一键复制 编辑 原始数据 按行查看 历史
现任明教教主-乾颐堂 提交于 2016-02-27 12:25 . new file
#!/usr/bin/python3.4
# -*- coding=utf-8 -*-
from xml.etree.ElementTree import parse
import pprint
mapping = {}
tree = parse('PolicyConfig.xml')
root = tree.getroot()
rules = root.find('Policies').find('Authentication').find('rules').findall('rule')
mapping = {}
for rule in rules:
try:
name = rule.attrib['name']
result = rule.find('Result')
resultname = result.attrib['name']
id_source_rult = rule.find('IdentitySourceRules').find('rule').find('IdentitySourceResult')
id_source_name = id_source_rult.attrib['name']
print(('RuleName: ' + '%-25s' + ' Allowed_Proto:' + '%-20s') % (name, resultname))
print('\nID_Source:' + id_source_name)
print('-' * 75)
except:
pass
#####################################################################################################################
[root@Fedora python]# ./xmltest.py
RuleName: CCNPSecurity Allowed_Proto:PAP
ID_Source:QYTANG
---------------------------------------------------------------------------
RuleName: ASA Allowed_Proto:Default Network Access
ID_Source:QYTANG
---------------------------------------------------------------------------
RuleName: Wireless-Dot1x Allowed_Proto:Default Network Access
ID_Source:QYTANG_Cert
---------------------------------------------------------------------------
RuleName: Wired-Dot1x Allowed_Proto:Default Network Access
ID_Source:QYTANG_Cert
---------------------------------------------------------------------------
RuleName: Security-Rack-AAA Allowed_Proto:PAP
ID_Source:QYTANG
---------------------------------------------------------------------------
RuleName: Production-Network-AAA Allowed_Proto:PAP
ID_Source:QYTANG
---------------------------------------------------------------------------
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/qytang/qytang_Python.git
git@gitee.com:qytang/qytang_Python.git
qytang
qytang_Python
qytang_Python
master

搜索帮助