def get_structs_from_logs(logdir, count=0, frame_count=0, older_first=False, filter_func=None): """Uses get_ascii_from_logs to get ascii frames and then it parses them using construct. Notice that parsing may fail and/or """ from protocols.constructs import MaraFrame from protocols.constructs.structs import hexstr2buffer from construct import FieldError count = 0 filters = build_filter_funcs(filter_func) for ascii_frame in get_ascii_from_logs(logdir, count=count, frame_count=0, # Cutting at upper level older_first=older_first): buffer = hexstr2buffer(ascii_frame) try: container = MaraFrame.parse(buffer) except (ValueError, FieldError): continue if not filters(container): continue yield container count += 1 if frame_count and count > frame_count: break
def get_structs_from_logs(logdir, count=0, frame_count=0, older_first=False, filter_func=None): """Uses get_ascii_from_logs to get ascii frames and then it parses them using construct. Notice that parsing may fail and/or """ from protocols.constructs import MaraFrame from protocols.constructs.structs import hexstr2buffer from construct import FieldError count = 0 filters = build_filter_funcs(filter_func) for ascii_frame in get_ascii_from_logs( logdir, count=count, frame_count=0, # Cutting at upper level older_first=older_first): buffer = hexstr2buffer(ascii_frame) try: container = MaraFrame.parse(buffer) except (ValueError, FieldError): continue if not filters(container): continue yield container count += 1 if frame_count and count > frame_count: break
def sendFixedRespose(self): bad_data = ( 'FE 08 0A 01 06 10 F1 E6 19 16 2D 2A 00 40 01 A4 50 00 00 00 00 00 00 00 00' '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' ) self.transport.write(hexstr2buffer(bad_data))
def _process_str_frame(self, a_text_frame, **flags): """ Creates crecords from frame into a COMaster entity tree. This **should** not be used in poll function. It's a helper for commandline for easy recovery of not saved frames. Accepts a frame per line. @return True on success, False otherwise """ from protocols.constructs.structs import hexstr2buffer from protocols.constructs import MaraFrame buff = hexstr2buffer(a_text_frame) frame = MaraFrame.parse(buff) success = True try: self.process_frame(frame) except Exception: success = False return success
def setUp(self): buffer = hexstr2buffer(FRAME) payload = MaraFrame.parse(buffer).palyload_10 ied = IEDFactory()