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


Python Util.prettifyXmlByElement方法代码示例

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


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

示例1: createRequestBodyProperty

# 需要导入模块: from lib import Util [as 别名]
# 或者: from lib.Util import prettifyXmlByElement [as 别名]
 def createRequestBodyProperty(className, objectName, objectDescription=None, metaPropertiesList=None, storage=None):
     
     updateVerificationPatternList = []
     
     xmlHeadLine = '<?xml version="1.0" encoding="UTF-8"?>'
     topAttributeMap = {
         'xmlns': 'http://www.cisco.com/NetworkServicesManager/1.1', 
         'xmlns:ns2': 'http://www.w3.org/2005/Atom'
     }
     className = className[0].lower() + className[1:]
     #NsmUtil.__logger.debug(metaPropertiesList)
     #NsmUtil.__logger.debug('class name: ' + className)
     if className.endswith('Zone'): className = 'zone'
     elif className.endswith('AccessVlan'): className = 'networkSegment'
     elif className.endswith('Connection'): className = 'externalNetworkConnection'
     elif className.endswith('Service'): className = 'servicePolicy'
     
     tagTop = Element(className, topAttributeMap)
     
     ### name can't be None
     if not objectName: 
         NsmUtil.__logger.error('Name can not be None')
         return None
     
     tagName = SubElement(tagTop, 'name')
     tagName.text = objectName
     updateVerificationPatternList.append('<name>' + objectName + '</name>')
     
     if objectDescription:
         tagDescription = SubElement(tagTop, 'description')
         tagDescription.text = objectDescription
         updateVerificationPatternList.append('<description>' + objectDescription + '</description>')
     
     tagProperties = SubElement(tagTop, 'properties')
     if metaPropertiesList and storage: 
         for metaProperties in metaPropertiesList:
             tagProperty = SubElement(tagProperties, 'property')
             
             tagName = SubElement(tagProperty, 'name')
             tagName.text = metaProperties[0]
             updateVerificationPatternList.append('<name>' + tagName.text + '</name>')
             
             tagType = SubElement(tagProperty, 'type')
             tagType.text = metaProperties[1]
             updateVerificationPatternList.append('<type>' + tagType.text + '</type>')
             
             grandParentTag = tagProperties
             parentTag = tagProperty
             for oneItem in metaProperties[2:]:
                 #NsmUtil.__logger.debug('oneItem: ' + oneItem)
                 if not oneItem:
                     continue
                 elif oneItem == '<up>':
                     parentTag = grandParentTag
                     # after <up>, no way to find the grandParentTag
                 elif oneItem.find('=') > 0:
                     subItems = oneItem.split('=')
                     tag = subItems[0]
                     text = subItems[1]
                     if tag == 'uid' and text.find('{') == 0:
                         text = text.replace('{', '')
                         text = text.replace('}', '')
                         text = NsmUtil.getUid(storage['_uidList'], text)
                         thisTag = SubElement(parentTag, tag)
                         thisTag.text = text
                         updateVerificationPatternList.append('<' + tag + '>' + text + '</' + tag + '>')
                     elif tag.endswith('ipv4Start'):
                         ipv4AddressList = None
                         if text == '{InternetEdgeZoneLayer3VlanReservedIpAddress}':
                             ipv4AddressList = storage['_internetEdgeZoneLayer3VlanReservedIpAddressList']
                         elif text == '{SecuredInternetEdgeZoneLayer3VlanReservedIpAddress}':
                             ipv4AddressList = storage['_securedInternetEdgeZoneLayer3VlanReservedIpAddressList']
                         text = ipv4AddressList.pop()
                         thisStartTag = SubElement(parentTag, tag)
                         thisStartTag.text = text
                         updateVerificationPatternList.append('<' + tag + '>' + text + '</' + tag + '>')
                         thisEndTag = SubElement(parentTag, 'ipv4End')
                         thisEndTag.text = text
                         updateVerificationPatternList.append('<' + tag + '>' + text + '</' + tag + '>')
                     else:
                         thisTag = SubElement(parentTag, tag)
                         thisTag.text = text
                         updateVerificationPatternList.append('<' + tag + '>' + text + '</' + tag + '>')
                 else:
                     thisTag = SubElement(parentTag, oneItem)
                     grandParentTag = parentTag
                     parentTag = thisTag
     
     #print tostring(tagTop)
     xmlStr = Util.prettifyXmlByElement(tagTop)
     NsmUtil.__logger.info('update request body: \n\n' + xmlStr)
     return xmlHeadLine + tostring(tagTop), updateVerificationPatternList
开发者ID:huhe56,项目名称:nsm-rest-api,代码行数:94,代码来源:nsmUtil.py


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