本文整理汇总了Python中lib.Util.prettfyXmlByString方法的典型用法代码示例。如果您正苦于以下问题:Python Util.prettfyXmlByString方法的具体用法?Python Util.prettfyXmlByString怎么用?Python Util.prettfyXmlByString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.Util
的用法示例。
在下文中一共展示了Util.prettfyXmlByString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doService
# 需要导入模块: from lib import Util [as 别名]
# 或者: from lib.Util import prettfyXmlByString [as 别名]
def doService(httpMethod, url, credential, requestBody=None):
Security.addProvider(MySSLProvider())
Security.setProperty("ssl.TrustManagerFactory.algorithm", "TrustAllCertificates")
HttpsURLConnection.setDefaultHostnameVerifier(MyHostnameVerifier())
urlObj = URL(url)
con = urlObj.openConnection()
con.setRequestProperty("Accept", "application/xml")
con.setRequestProperty("Content-Type", "application/xml")
con.setRequestProperty("Authorization", credential)
con.setDoInput(True);
if httpMethod == 'POST':
con.setDoOutput(True)
con.setRequestMethod(httpMethod)
output = DataOutputStream(con.getOutputStream());
if requestBody:
output.writeBytes(requestBody);
output.close();
responseCode = con.getResponseCode()
logger.info('response code: ' + str(responseCode))
responseMessage = con.getResponseMessage()
logger.info('response message: ' + str(responseMessage))
contentLength = con.getHeaderField('Content-Length')
logger.info('content length: ' + str(contentLength))
stream = None
if responseCode == 200 or responseCode == 201 or responseCode == 202:
stream = con.getInputStream()
elif contentLength:
stream = con.getErrorStream()
if stream:
dataString = getStreamData(stream)
logger.info(httpMethod + ' url: ' + url)
if not url.endswith('.xsd') and len(dataString) < 4096:
xmlStr = Util.prettfyXmlByString(dataString)
logger.info(httpMethod + ' result: \n\n' + xmlStr)
else:
logger.info('response body too big, no print out')
if responseCode == 200 or responseCode == 201 or responseCode == 202:
return dataString
else:
''' to mark the case failed if response code is not 200-202 '''
return None
else:
logger.error('')
logger.error('---------------------------------------------------------------------------------------------------')
logger.error('-------->>> Input or Error stream is None, it may be a defect if it is positive test case')
logger.error('---------------------------------------------------------------------------------------------------')
logger.error('')
return None
示例2: verifyCreate
# 需要导入模块: from lib import Util [as 别名]
# 或者: from lib.Util import prettfyXmlByString [as 别名]
def verifyCreate(self):
if self.mySubClassName != 'Pod' and self.isOffLine and self.createTaskXml: self.logger.info(Util.prettfyXmlByString(self.createTaskXml))
NsmUtil.printHeadLine2('START: create response verification: parameters from request body')
status = True
for key, value in self.requestParams.items():
keyItems = key.split('.')
pattern = None
if key.endswith('.ipv4.start'):
pattern = '<ipv4Start>' + value + '</ipv4Start>'
elif key.endswith('.ipv4.end'):
pattern = '<ipv4End>' + value + '</ipv4End>'
elif key.endswith('.ipv4') or key.endswith('.mask') or key.endswith('.protocol') or key.endswith('.start') or key.endswith('.end') or key.endswith('.ASNumber') or key.endswith('.uid') or key == 'name' or key == 'description':
pattern = '<' + keyItems[-1] + '>' + value + '</' + keyItems[-1] + '>'
elif key.endswith('.netmask'):
pattern = '<integer>' + value + '</integer>'
elif key.startswith('serverfarm.probe.') or key == 'lb.algorithm':
pattern = '<string>' + value + '</string>'
elif key.endswith('redirect.port'):
pattern = '<redirectPort>' + value + '</redirectPort>'
if pattern:
if self.createTaskXml.find(pattern) < 0:
status = False
NsmUtil.printStatusHeadLine2('Failed: pattern not found: ' + pattern)
else:
NsmUtil.printStatusHeadLine2('Passed: pattern found: ' + pattern)
NsmUtil.printHeadLine2('END: create response verification: parameters from request body')
return status
示例3: verifyUpdate
# 需要导入模块: from lib import Util [as 别名]
# 或者: from lib.Util import prettfyXmlByString [as 别名]
def verifyUpdate(self, updateVerificationPatternList, storage):
if self.mySubClassName != 'Pod' and self.isOffLine and self.updateTaskXml: self.logger.info(Util.prettfyXmlByString(self.updateTaskXml))
NsmUtil.printHeadLine2('START: update response verification: parameters from request body')
status = True
for pattern in updateVerificationPatternList:
if self.updateTaskXml.find(pattern) < 0:
status = False
NsmUtil.printStatusHeadLine2('Failed: pattern not found: ' + pattern)
else:
NsmUtil.printStatusHeadLine2('Passed: pattern found: ' + pattern)
NsmUtil.printHeadLine2('END: update response verification: parameters from request body')
return status