Beispiel #1
0
 def stream(self) -> Iterable[flow.Flow]:
     """
         Yields Flow objects from the dump.
     """
     try:
         while True:
             # FIXME: This cast hides a lack of dynamic type checking
             loaded = cast(
                 Dict[Union[bytes, str], Any],
                 tnetstring.load(self.fo),
             )
             try:
                 mdata = compat.migrate_flow(loaded)
             except ValueError as e:
                 raise exceptions.FlowReadException(str(e))
             if mdata["type"] not in FLOW_TYPES:
                 raise exceptions.FlowReadException("Unknown flow type: {}".format(mdata["type"]))
             yield FLOW_TYPES[mdata["type"]].from_state(mdata)
     except ValueError as e:
         if str(e) == "not a tnetstring: empty file":
             return  # Error is due to EOF
         raise exceptions.FlowReadException("Invalid data format.")
Beispiel #2
0
 def stream(self) -> Iterable[flow.Flow]:
     """
         Yields Flow objects from the dump.
     """
     try:
         while True:
             # FIXME: This cast hides a lack of dynamic type checking
             loaded = cast(
                 Dict[Union[bytes, str], Any],
                 tnetstring.load(self.fo),
             )
             try:
                 mdata = compat.migrate_flow(loaded)
             except ValueError as e:
                 raise exceptions.FlowReadException(str(e))
             if mdata["type"] not in FLOW_TYPES:
                 raise exceptions.FlowReadException(
                     "Unknown flow type: {}".format(mdata["type"]))
             yield FLOW_TYPES[mdata["type"]].from_state(mdata)
     except (ValueError, TypeError, IndexError) as e:
         if str(e) == "not a tnetstring: empty file":
             return  # Error is due to EOF
         raise exceptions.FlowReadException("Invalid data format.")