def parseSEED(self, data, expected_length=0): """ If number of FIR coefficients are larger than maximal blockette size of 9999 chars a follow up blockette with the same blockette id and response lookup key is expected - this is checked here. """ # convert to stream for test issues if isinstance(data, bytes): expected_length = len(data) data = io.BytesIO(data) elif isinstance(data, (str, native_str)): raise TypeError("Data must be bytes, not string") # get current lookup key pos = data.tell() data.read(7) global_lookup_key = int(data.read(4)) data.seek(pos) # read first blockette temp = io.BytesIO() temp.write(data.read(expected_length)) # check next blockettes while True: # save position pos = data.tell() try: blockette_id = int(data.read(3)) except ValueError: break if blockette_id != 41: # different blockette id -> break break blockette_length = int(data.read(4)) lookup_key = int(data.read(4)) if lookup_key != global_lookup_key: # different lookup key -> break break # ok follow up blockette found - skip some unneeded fields self.fields[1].read(data) self.fields[2].read(data) self.fields[3].read(data) self.fields[4].read(data) self.fields[5].read(data) # remaining length in current blockette length = pos - data.tell() + blockette_length # read follow up blockette and append it to temporary blockette temp.write(data.read(length)) # reposition file pointer data.seek(pos) # parse new combined temporary blockette temp.seek(0, os.SEEK_END) _len = temp.tell() temp.seek(0) Blockette.parseSEED(self, temp, expected_length=_len)
def parseSEED(self, data, expected_length=0): """ If number of FIR coefficients are larger than maximal blockette size of 9999 chars a follow up blockette with the same blockette id and response lookup key is expected - this is checked here. """ # convert to stream for test issues if isinstance(data, bytes): expected_length = len(data) data = compatibility.BytesIO(data) elif isinstance(data, (str, native_str)): raise TypeError("Data must be bytes, not string") # get current lookup key pos = data.tell() data.read(7) global_lookup_key = int(data.read(4)) data.seek(pos) # read first blockette temp = compatibility.BytesIO() temp.write(data.read(expected_length)) # check next blockettes while True: # save position pos = data.tell() try: blockette_id = int(data.read(3)) except ValueError: break if blockette_id != 41: # different blockette id -> break break blockette_length = int(data.read(4)) lookup_key = int(data.read(4)) if lookup_key != global_lookup_key: # different lookup key -> break break # ok follow up blockette found - skip some unneeded fields self.fields[1].read(data) self.fields[2].read(data) self.fields[3].read(data) self.fields[4].read(data) self.fields[5].read(data) # remaining length in current blockette length = pos - data.tell() + blockette_length # read follow up blockette and append it to temporary blockette temp.write(data.read(length)) # reposition file pointer data.seek(pos) # parse new combined temporary blockette temp.seek(0, os.SEEK_END) _len = temp.tell() temp.seek(0) Blockette.parseSEED(self, temp, expected_length=_len)
def getXML(self, *args, **kwargs): xml = Blockette.getXML(self, *args, **kwargs) if self.xseed_version == '1.0': msg = 'The xsd-validation file for XML-SEED version 1.0 does ' + \ 'not support Blockette 62. It will be written but ' + \ 'please be aware that the file cannot be validated.\n' + \ 'If you want to validate your file please use XSEED ' + \ 'version 1.1.\n' sys.stdout.write(msg) return xml
def getXML(self, *args, **kwargs): xml = Blockette.getXML(self, *args, **kwargs) if self.xseed_version == '1.0': xml.find('FIR_coefficient').tag = 'fir_coefficient' return xml
def parseXML(self, xml_doc, *args, **kwargs): if self.xseed_version == '1.0': xml_doc.find('fir_coefficient').tag = 'FIR_coefficient' Blockette.parseXML(self, xml_doc, *args, **kwargs)
def getXML(self, *args, **kwargs): xml = Blockette.getXML(self, *args, **kwargs) if self.xseed_version == '1.0': xml.tag = 'response_poles_and_zeros' return xml
def getXML(self, *args, **kwargs): xml = Blockette.getXML(self, *args, **kwargs) if self.xseed_version == '1.0': xml.tag = 'response_coefficients' return xml
def getXML(self, *args, **kwargs): xml = Blockette.getXML(self, *args, **kwargs) if self.xseed_version == '1.0': xml.tag = 'reponse_list' return xml
def getXML(self, *args, **kwargs): xml = Blockette.getXML(self, *args, **kwargs) if self.xseed_version == "1.0": xml.find("FIR_coefficient").tag = "fir_coefficient" return xml
def parseXML(self, xml_doc, *args, **kwargs): if self.xseed_version == "1.0": xml_doc.find("fir_coefficient").tag = "FIR_coefficient" Blockette.parseXML(self, xml_doc, *args, **kwargs)