def retrieve_flows(self, ids=None): flows = [] with self.con as con: if not ids: sql = "SELECT f.content, b.type_id, b.content " \ "FROM flow f " \ "LEFT OUTER JOIN body b ON f.id = b.flow_id;" rows = con.execute(sql).fetchall() else: sql = "SELECT f.content, b.type_id, b.content " \ "FROM flow f " \ "LEFT OUTER JOIN body b ON f.id = b.flow_id " \ f"AND f.id IN ({','.join(['?' for _ in range(len(ids))])});" rows = con.execute(sql, ids).fetchall() for row in rows: flow = protobuf.loads(row[0]) if row[1]: typ = self.type_mappings["body"][row[1]] if typ and row[2]: setattr(getattr(flow, typ), "content", row[2]) flow = self._reassemble(flow) flows.append(flow) return flows
def load(self): flows = [] self._c.execute('SELECT pbuf_blob FROM FLOWS') for row in self._c.fetchall(): flows.append((protobuf.loads(row[0]))) return flows
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_loads(self): b = b"blobs" with pytest.raises(exceptions.TypeError): protobuf.loads(b, 'not-http')