async def __call__(self): # Receive all packets all_packets = {k: [] for k in self.inputs.keys()} async for packet_dict in self.inputs: for port, packet in packet_dict.items(): all_packets[port].append(packet) async with self.outputs.OUT: for it, p in enumerate(self._fun(all_packets.values())): # Create substream substream = [IP.OpenBracket()] + [p1.copy() for p1 in p ] + [IP.CloseBracket()] # Send packets in substream for p1 in substream: await self.outputs.OUT.send_packet(p1) await asyncio.sleep(0)
def send_to_all(self, data): # Send self.log.debug("Sending '{}' to all output ports".format(data)) packets = { p: IP.InformationPacket(data, owner=self) for p, v in self.outputs.items() } futures = self.outputs.send_packets(packets) return futures
async def __call__(self): pattern = await self.inputs.pattern.receive() while True: p = await self.inputs.IN.receive_packet() p1 = IP.InformationPacket(p.path.replace(*self.pattern), owner=self) p.drop() await self.outputs.OUT.send_packet(p1) await asyncio.sleep(0)
async def __call__(self): pattern = await self.inputs.pattern.receive() files = _glob.glob(pattern) start_message = "using glob pattern {} will emit {} files: {}".format( pattern, len(files), files) self.log.info(start_message) for file in files: p = IP.InformationPacket(_path.Path(file), owner=self) await self.outputs.OUT.send_packet(p) await asyncio.sleep(0) stop_message = "exahusted list of files" self._log.info(stop_message) await self.close_downstream()
async def __call__(self): for file in self.files: p = IP.InformationPacket(file, owner=self) await self.outputs.OUT.send_packet(p) await asyncio.sleep(0) await self.close_downstream()
def testCopy(self): a = IP.FilePacket('a') b = a.copy() print(a, b)
def testFilePacket(self): unique_file = os.path.dirname(__file__) + '/' + str(uuid.uuid4()) b = IP.FilePacket(unique_file) print(str(b))
def testRepr(self): a = IP.InformationPacket('a') print(str(a))