def testboolean(self): '''boolean dump and load''' obj = {'bool': True} xml = '<bool>true</bool>' self.assertEqual(obj, xon.loads(xml, convertvalues=True)) self.assertEqual(xml, xon.dumps(obj, convertvalues=True)) obj = {'bool': False} xml = '<bool>false</bool>' self.assertEqual(obj, xon.loads(xml, convertvalues=True)) self.assertEqual(xml, xon.dumps(obj, convertvalues=True))
def testboolean(self): """boolean dump and load""" obj = {"bool": True} xml = "<bool>true</bool>" self.assertEqual(obj, xon.loads(xml, convertvalues=True)) self.assertEqual(xml, xon.dumps(obj, convertvalues=True)) obj = {"bool": False} xml = "<bool>false</bool>" self.assertEqual(obj, xon.loads(xml, convertvalues=True)) self.assertEqual(xml, xon.dumps(obj, convertvalues=True))
def testwrap(self): '''wrap an arbitrary object in a parent tag''' obj = {'one': 'two', 'three': ['four', 'five']} xml = ('<wrapper><three>four</three><three>five</three>' '<one>two</one></wrapper>') self.assertEqual(obj, xon.loads(xml, unwrap=True)) self.assertEqual(xml, xon.dumps(obj, wrap='wrapper'))
def testwrap(self): '''wrap an arbitrary object in a parent tag''' obj = {'one': 'two', 'three': ['four', 'five']} xml = ('<wrapper><one>two</one>' '<three>four</three><three>five</three></wrapper>') self.assertEqual(obj, xon.loads(xml, unwrap=True)) self.assertEqual(xml, xon.dumps(obj, wrap='wrapper'))
def method_call(self, method_calls): api_dict = { 'api': { 'authentication': { 'api_key': self.api_key, 'shared_secret': self.api_secret, }, 'data': method_calls, }, } request_xml = xon.dumps(api_dict) self.last_request = request_xml params = urllib.urlencode({'data': request_xml,}) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} url = 'https://echo.bluehornet.com/api/xmlrpc/index.php' request = urllib2.Request(url, params, headers) response = urllib2.urlopen(request) response_xml = response.read() return xon.loads(response_xml)
def method_call(self, method_calls): api_dict = { 'api': { 'authentication': { 'api_key': self.api_key, 'shared_secret': self.api_secret, }, 'data': method_calls, }, } request_xml = xon.dumps(api_dict) self.last_request = request_xml params = urllib.urlencode({ 'data': request_xml, }) headers = { "Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain" } url = 'https://echo.bluehornet.com/api/xmlrpc/index.php' request = urllib2.Request(url, params, headers) response = urllib2.urlopen(request) response_xml = response.read() return xon.loads(response_xml)
def testint(self): """integer dump and load""" obj = {"int": 10} xml = "<int>10</int>" self.assertEqual(obj, xon.loads(xml, convertvalues=True)) self.assertEqual(xml, xon.dumps(obj, convertvalues=True))
def testroundtrip(self): """roundtrip objects to XON and back""" for obj, xml in self.dumps: self.assertEqual(obj, xon.loads(xon.dumps(obj)))
def testloads(self): """loading of XON strings to objects""" for xml, obj in self.loads: self.assertEqual(xon.loads(xml), obj)
def testunicode(self): '''unicode string dump and load''' obj = {'unicode': u'a string\u2014in Unicode'} xml = '<unicode>a string—in Unicode</unicode>' self.assertEqual(obj, xon.loads(xml)) self.assertEqual(xml, xon.dumps(obj))
def testunicode(self): """unicode string dump and load""" obj = {"unicode": u"a string\u2014in Unicode"} xml = "<unicode>a string—in Unicode</unicode>" self.assertEqual(obj, xon.loads(xml)) self.assertEqual(xml, xon.dumps(obj))
def testint(self): '''integer dump and load''' obj = {'int': 10} xml = '<int>10</int>' self.assertEqual(obj, xon.loads(xml, convertvalues=True)) self.assertEqual(xml, xon.dumps(obj, convertvalues=True))
def testroundtrip(self): '''roundtrip objects to XON and back''' for obj, xml in self.dumps: self.assertEqual(obj, xon.loads(xon.dumps(obj)))
def testloads(self): '''loading of XON strings to objects''' for xml, obj in self.loads: self.assertEqual(xon.loads(xml), obj)
type=str) # specify output file parser.add_argument('--outfile', '-o', help="output XML file", default='integer.json', dest='outfile_name', required=False, type=str) args = parser.parse_args() with open(args.infile_name) as f: xml_data = f.read().replace('\n', '') # json_data is type 'dict' json_data = xon.loads(xml_data) # pprint.pprint(json_data) # actions - a list actions = json_data['vistrail']['action'] output = {} output['connections'] = [] output['uid'] = 0 output['groups'] = [] # workflow output['workflowState'] = {} output['workflowState']['abstract'] = False output['workflowState']['context'] = {} # workflow/context
def testfloat(self): """float dump and load""" obj = {"float": 123.456} xml = "<float>123.456</float>" self.assertEqual(obj, xon.loads(xml, convertvalues=True)) self.assertEqual(xml, xon.dumps(obj, convertvalues=True))
def testfloat(self): '''float dump and load''' obj = {'float': 123.456} xml = '<float>123.456</float>' self.assertEqual(obj, xon.loads(xml, convertvalues=True)) self.assertEqual(xml, xon.dumps(obj, convertvalues=True))
def testwrap(self): """wrap an arbitrary object in a parent tag""" obj = {"one": "two", "three": ["four", "five"]} xml = "<wrapper><one>two</one>" "<three>four</three><three>five</three></wrapper>" self.assertEqual(obj, xon.loads(xml, unwrap=True)) self.assertEqual(xml, xon.dumps(obj, wrap="wrapper"))