def store(self, flows): blobs = [] for flow in flows: blobs.append((protobuf.dumps(flow), )) with self._con: self._con.executemany('INSERT INTO FLOWS (pbuf_blob) values (?)', blobs)
def store_flows(self, flows): body_buf = [] flow_buf = [] for flow in flows: self.id_ledger.add(flow.id) self._disassemble(flow) f = copy.copy(flow) f.request = copy.deepcopy(flow.request) if flow.response: f.response = copy.deepcopy(flow.response) f.id = flow.id if len(f.request.content ) > self.content_threshold and f.id not in self.body_ledger: body_buf.append((f.id, 1, f.request.content)) f.request.content = b"" self.body_ledger.add(f.id) if f.response and f.id not in self.body_ledger: if len(f.response.content) > self.content_threshold: body_buf.append((f.id, 2, f.response.content)) f.response.content = b"" flow_buf.append((f.id, protobuf.dumps(f))) self.con.executemany("INSERT OR REPLACE INTO flow VALUES(?, ?);", flow_buf) if body_buf: self.con.executemany( "INSERT INTO body (flow_id, type_id, content) VALUES(?, ?, ?);", body_buf) self.con.commit()
def store_flows(self, flows): body_buf = [] flow_buf = [] for flow in flows: self.id_ledger.add(flow.id) self._disassemble(flow) f = copy.copy(flow) f.request = copy.deepcopy(flow.request) if flow.response: f.response = copy.deepcopy(flow.response) f.id = flow.id if len(f.request.content) > self.content_threshold and f.id not in self.body_ledger: body_buf.append((f.id, 1, f.request.content)) f.request.content = b"" self.body_ledger.add(f.id) if f.response and f.id not in self.body_ledger: if len(f.response.content) > self.content_threshold: body_buf.append((f.id, 2, f.response.content)) f.response.content = b"" flow_buf.append((f.id, protobuf.dumps(f))) self.con.executemany("INSERT OR REPLACE INTO flow VALUES(?, ?);", flow_buf) if body_buf: self.con.executemany("INSERT INTO body (flow_id, type_id, content) VALUES(?, ?, ?);", body_buf) self.con.commit()
def test_roundtrip_http_flow_only_req(self): f = tflow.tflow() f.reply = None pf = protobuf.dumps(f) lf = protobuf.loads(pf, "http") assert f.__dict__ == lf.__dict__
def test_unsupported_dumps(self): w = tflow.twebsocketflow() with pytest.raises(exceptions.TypeError): protobuf.dumps(w)
def store(self, flows): blobs = [] for flow in flows: blobs.append((protobuf.dumps(flow),)) with self._con: self._con.executemany('INSERT INTO FLOWS (pbuf_blob) values (?)', blobs)