def status_parser(self, response): """ commands that do NOT return an NFC result-code """ results = {'iseeprom': None, # 'true' if EEPROM 'lastnfcerror':0, # ignored here 'maxndef':None # actual driver buffer size } respLines = response.lines for line in respLines: try: # iseeprom value = PluginBase.find_one(line, "{{iseeprom=([\w]+)}}") if value is not False: if ("TRUE" == value.upper() or "1" == value): results['iseeprom'] = True else: results['iseeprom'] = False # max ndef value = PluginBase.find_one(line, "{{maxndef=([0-9]+)}}") if value is not False: results['maxndef'] = int(value) except re.error as e: # the framework gobbles errors in the plugin print("Regex error",e,"occured in",os.path.basename(__file__), "!!") raise e return results
def __mbedossocketParser(self, response): results = { 'socket_id': None, 'data_type': None, 'data': "", 'printed_bytes': None, 'sent_bytes': None, 'received_bytes': None, 'address': None, 'port': None, 'loop_id': None } respLines = response.lines part = None for line in respLines: ret = PluginBase.find_one(line, ".*sid: ([0-9]+)") if ret is not False: results['socket_id'] = ret ret = PluginBase.find_one( line, ".*(hex|string) data, printing .* bytes:") if ret is not False: results['data_type'] = ret ret = PluginBase.find_one(line, ".*data, printing (.*) bytes:") if ret is not False: part = "data" ret = PluginBase.find_one(line, "^Printed (.*) bytes$") if ret is not False: results['printed_bytes'] = int(ret) part = None if part == "data": ret = PluginBase.find_one(line, "^\d{4}: (.*)$") if ret is not False: results['data'] = results['data'] + ret ret = PluginBase.find_one(line, ".*sent: ([0-9]+) bytes") if ret is not False: results['sent_bytes'] = int(ret) ret = PluginBase.find_one(line, ".*received: ([0-9]+) bytes") if ret is not False: results['received_bytes'] = int(ret) ret = PluginBase.find_one(line, ".*address: ([0-9a-fxA-F:.]+)") if ret is not False: results['address'] = ret ret = PluginBase.find_one(line, ".*port: ([0-9]+)") if ret is not False: results['port'] = ret ret = PluginBase.find_one(line, ".*lid: ([0-9]+)") if ret is not False: results['loop_id'] = ret return results
def __ticker_parser(self, response): results = {} respLines = response.lines for line in respLines: ret = PluginBase.find_one(line, 'Ticker id: ([0-9]+)') if ret is not False: results['ticker_id'] = ret return results
def example_parser(self, data): """ A simple example parser that looks for one occurence of string 'one'. :param data: line of data as string :return: dict """ parsed = PluginBase.find_one(data, "one") return {"one_found": parsed}
def trace_parser(self, response): results = {'iseeprom': None, # 'true' if EEPROM 'lastnfcerror':None, # 0=OK >0 = error 'nfcmessage':None, # NDEF array of bytes 'protocols':None, # csv list 'uri_id':None} # nfc URI type identifier respLines = response.lines started_read_data = False partial_data = "" for line in respLines: try: value = PluginBase.find_one(line, "{{lastnfcerror=([0-9]+)}}") if value is not False: results['lastnfcerror'] = int(value) # {{nfcmessage=([0-9a-f\s]*)}} # message may be split over multiple lines, so we will start a search and wait until we get a }} pair data = PluginBase.find_one(line, "{{nfcmessage=([0-9a-f\s]*).*") if data is not False: started_read_data = True if started_read_data: # read data until we see a }} pair if "{{nfcmessage=" in line: line = line[13:] # trim header if PluginBase.find_one(line, ".*(}})") is not False: # search for end marker started_read_data = False line = line[:-2] # trim closing }} partial_data += line if not started_read_data: results['nfcmessage'] = self.convert_from_hex(partial_data) # t1t,t2t,t3t,isodep,nfcdef,t5t value = PluginBase.find_one(line, "{{protocols=(([\w]*,?)*)}}") if value is not False: results['protocols'] = value # a csv list # smartposter uri value = PluginBase.find_one(line, "{{uri_id=([0-9]+)}}") if value is not False: results['uri_id'] = int(value) except re.error as e: # the framework gobbles errors in the plugin print("Regex error",e,"occured in",os.path.basename(__file__), "!!") raise e return results