Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
ASCommandResponse.py74 linesDownload Raw Back to wbxml
1#!/usr/bin/env python32'''3@author: David Shaw, shawd@vmware.com4 5Inspired by EAS Inspector for Fiddler6https://easinspectorforfiddler.codeplex.com7 8----- The MIT License (MIT) ----- 9Filename: ASCommandResponse.py10Copyright (c) 2014, David P. Shaw11 12Permission is hereby granted, free of charge, to any person obtaining a copy13of this software and associated documentation files (the "Software"), to deal14in the Software without restriction, including without limitation the rights15to use, copy, modify, merge, publish, distribute, sublicense, and/or sell16copies of the Software, and to permit persons to whom the Software is17furnished to do so, subject to the following conditions:18 19The above copyright notice and this permission notice shall be included in20all copies or substantial portions of the Software.21 22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN28THE SOFTWARE.29'''30from .ASWBXML import ASWBXML31import logging32 33class ASCommandResponse:34 35	def __init__(self, response):36		self.wbxmlBody = response37		try:38			if ( len(response) > 0):39				self.xmlString = self.decodeWBXML(self.wbxmlBody)40			else:41				raise ValueError("Empty WBXML body passed")42		except Exception as e:43			self.xmlString = None44			raise ValueError("Error: {0}".format(e))45 46	def getWBXMLBytes(self):47		return self.wbxmlBytes48	49	def getXMLString(self):50		return self.xmlString51	52	def decodeWBXML(self, body):53		self.instance = ASWBXML()54		self.instance.loadBytes(body)55		return self.instance.getXml()56 57if __name__ == "__main__":58	import os	59	logging.basicConfig(level=logging.INFO)60 61	projectDir = os.path.dirname(os.path.realpath("."))62	samplesDir = os.path.join(projectDir, "Samples/")63	listOfSamples = os.listdir(samplesDir)64 65	for filename in listOfSamples:66		with open(samplesDir + os.sep + filename, "rb") as f:67			byteWBXML = f.read()68 69		logging.info("-"*100)70		logging.info(filename)71		logging.info("-"*100)72		instance = ASCommandResponse(byteWBXML)73		logging.info(instance.xmlString)74 
codekingpro/portable-devtools · Team Ai