def test_get_all_collections(): eimml = xmlobjects.fromstring(eimml_example) collection_uuid = str(uuid.uuid1()) record_uuid = str(uuid.uuid1()) eimml['uuid'] = collection_uuid for record in eimml.recordset.record: record.uuid = record_uuid if hasattr(record, 'icalUid'): record.icalUid = collection_uuid client.mc_publish_collection(eimml) assert client.response.status == 201 collections[eimml['uuid']] = { 'xobj': eimml, 'token': client.response.getheader('X-MorseCode-SyncToken') } path = client._cosmo_path + 'mc/user/%s' % client._username client.get(path, headers={'content-type': 'application/eim+xml; charset=UTF-8'}) assert client.response.status == 200 xobj = xmlobjects.fromstring(client.response.body) assert len( xobj.collection ) is 4 # cosmolib creates one calendar collection so we should have 3
def xml_to_object(): global file_paths try: csvfile=open('result.csv', 'wb') csvwriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) for file_path in file_paths: log_file=open(file_path, "r") log_string=log_file.read() xobj=xmlobjects.fromstring(log_string) #for raw_count in xobj.Raw_Count_Averages.data: # print raw_count #print xobj.Raw_Count_Averages.data csvwriter.writerow([xobj.Serial_Number, str(xobj.Test_Time), str(xobj.Error_Code) , xobj.Test_Station]) print xobj.Serial_Number+"\t"+xobj.Test_Time csvfile.close() except TypeError as e: print file_path + ": " + e.args[0] except Exception as e: print e except : print file_path + " Unexpected error:", sys.exc_info()[0]
def get_data(self): try: log_file = open(self.configFile, "r") log_string = unicode(log_file.read()) data_obj = xmlobjects.fromstring(log_string) return data_obj except Exception, e: print self.configFile + " get_data: " + str(e) return 0
def get_data(self, singlefile): ''' get signal list from singlefile; ''' try: log_file = open(singlefile, "r") log_string = unicode(log_file.read()) data_obj = xmlobjects.fromstring(log_string) return data_obj except Exception, e: print singlefile + " get_data: " + str(e) return 0
def test_get_all_collections(): eimml = xmlobjects.fromstring(eimml_example) collection_uuid = str(uuid.uuid1()) record_uuid = str(uuid.uuid1()) eimml['uuid'] = collection_uuid for record in eimml.recordset.record: record.uuid = record_uuid if hasattr(record, 'icalUid'): record.icalUid = collection_uuid client.mc_publish_collection(eimml) assert client.response.status == 201 collections[eimml['uuid']] = {'xobj':eimml, 'token':client.response.getheader('X-MorseCode-SyncToken')} path = client._cosmo_path+'mc/user/%s' % client._username client.get(path, headers={'content-type':'application/eim+xml; charset=UTF-8'}) assert client.response.status == 200 xobj = xmlobjects.fromstring(client.response.body) assert len(xobj.collection) is 4 # cosmolib creates one calendar collection so we should have 3
def get_lists(self, serialnumber): ''' get signal list from file; ''' myfile = self.__get_file(serialnumber) self.__cleanup_xml(myfile) log_file = open(myfile, "r") log_string = log_file.read() data_obj = xmlobjects.fromstring(log_string) data_list = [] for d in data_obj.signal_value.data: data_list.append(int(d)) return data_list
def test_publish(): eimml = xmlobjects.fromstring(eimml_example) collection_uuid = str(uuid.uuid1()) record_uuid = str(uuid.uuid1()) eimml['uuid'] = collection_uuid for record in eimml.recordset.record: record.uuid = record_uuid if hasattr(record, 'icalUid'): record.icalUid = collection_uuid client.mc_publish_collection(eimml) assert client.response.status == 201 collections[eimml['uuid']] = {'xobj':eimml, 'token':client.response.getheader('X-MorseCode-SyncToken')} collections['example'] = collections[eimml['uuid']]
def get_lists(self, file): ''' get signal list from file; ''' log_file = open(file,"r") log_string = log_file.read() data_obj = xmlobjects.fromstring(log_string) (dir, filename) = os.path.split(file) (serialnumber, ext) = os.path.splitext(filename) #print serialnumber data_list = ["'"+serialnumber+"'", "Signal",] for d in data_obj.signal_value.data: data_list.append(int(d)) return data_list
def get_lists(self, file): ''' get signal list from file; ''' log_file = open(file, "r") log_string = log_file.read() data_obj = xmlobjects.fromstring(log_string) (dir, filename) = os.path.split(file) (serialnumber, ext) = os.path.splitext(filename) #print serialnumber data_list = ["'" + serialnumber + "'", "Signal"] for d in data_obj.signal_value.data: data_list.append(int(d)) return data_list
def test_publish(): eimml = xmlobjects.fromstring(eimml_example) collection_uuid = str(uuid.uuid1()) record_uuid = str(uuid.uuid1()) eimml['uuid'] = collection_uuid for record in eimml.recordset.record: record.uuid = record_uuid if hasattr(record, 'icalUid'): record.icalUid = collection_uuid client.mc_publish_collection(eimml) assert client.response.status == 201 collections[eimml['uuid']] = { 'xobj': eimml, 'token': client.response.getheader('X-MorseCode-SyncToken') } collections['example'] = collections[eimml['uuid']]
def xml_to_object(): global file_paths try: csvfile = open('result.csv', 'wb') csvwriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) for file_path in file_paths: log_file = open(file_path, "r") log_string = log_file.read() xobj = xmlobjects.fromstring(log_string) #for raw_count in xobj.Raw_Count_Averages.data: # print raw_count #print xobj.Raw_Count_Averages.data csvwriter.writerow([ xobj.Serial_Number, str(xobj.Test_Time), str(xobj.Error_Code), xobj.Test_Station ]) print xobj.Serial_Number + "\t" + xobj.Test_Time csvfile.close() except TypeError as e: print file_path + ": " + e.args[0] except Exception as e: print e except: print file_path + " Unexpected error:", sys.exc_info()[0]
def test_parser(): def fallback(self, value): """Fallback method to return best type converter for a given value""" # Cascading logic that tries it's best to return the proper type converter for a given value if value is None or value == '': return None if value.find('.') is not -1: try: return float(value) except: pass if value.find('T') is not -1: try: return str(value) except: pass try: return int(value) except: return str(value) xmlobjects.Parser.fallback = fallback parser = xmlobjects.Parser() example = """<?xml version='1.0' encoding='UTF-8'?> <eim:collection xmlns:eim="http://osafoundation.org/eim" uuid="f230dcd4-7c32-4c3f-908b-d92081cc9a89" name="Cosmo"> <eim:recordset uuid="e55b5f1c-a20d-4d47-acda-c43049967281"> <item:record xmlns:item="http://osafoundation.org/eim/item"> <item:uuid eim:type="text" eim:key="true">e55b5f1c-a20d-4d47-acda-c43049967281</item:uuid> <item:title eim:type="text">Welcome to Cosmo!</item:title> <item:triageStatus eim:type="text" /> <item:triageStatusChanged eim:type="decimal" /> <item:lastModifiedBy eim:type="text" /> <item:createdOn eim:type="timestamp">2006-12-19T11:09:44Z</item:createdOn> </item:record> <note:record xmlns:note="http://osafoundation.org/eim/note"> <note:uuid eim:type="text" eim:key="true">e55b5f1c-a20d-4d47-acda-c43049967281</note:uuid> <note:body eim:type="clob">Welcome to Cosmo!</note:body> <note:icalUid eim:type="text">bc54d532-ad87-4c47-b37c-44d23e4f8850</note:icalUid> </note:record> <event:record xmlns:event="http://osafoundation.org/eim/event"> <event:uuid eim:type="text" eim:key="true">e55b5f1c-a20d-4d47-acda-c43049967281</event:uuid> <event:dtstart eim:type="text">20061220T090000</event:dtstart> <event:dtend eim:type="text">20061220T100000</event:dtend> <event:location eim:type="text" /> <event:rrule eim:type="text" /> <event:exrule eim:type="text" /> <event:rdate eim:type="text" /> <event:exdate eim:type="text" /> <event:recurrenceId eim:type="text" /> <event:status eim:type="text" /> </event:record> </eim:recordset> </eim:collection>""" xobj = xmlobjects.fromstring(example) tree = ElementTree.fromstring(example) assert ElementTree.tostring(tree).replace('\n ', '').replace('\n ', '').replace('\n ', '').replace('\n', '').replace('\n ', '') == xmlobjects.tostring(xobj)