Exemplo n.º 1
0
 def pump_data(self, data_in=None, zero_inputs=True):  # << TO-DO Needs work
     ##, close_at_end=True):
     """Put the data into the pipeline by wrapping it in a Datapacket.
        Get the data out by temporarily sticking a Sink on the end,
        returning all the packets received.
        Remember to close the pipeline externally, if tidying up actions 
        need to be performed.
        
        
        If zero_inputs is True, reinitialise the variables before pumping 
        the new data in.  <<<<<<<zero_inputs<<<<<<<<< TO-DO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
     """
     pump_sink = df.Sink()
     self.last_filter.next_filter = pump_sink
     print '**10195** Connect (%s, pump_data) %s >>> %s' % (
         self.name, self.last_filter.name, pump_sink.name)
     try:
         data_in + []  # TO-DO: Better way to check the data type
     except TypeError:  # Not a list
         data_in = [data_in]
     for data in data_in:
         if data is None:
             ##                packet = None
             packet = dfb.DataPacket(None)  # Or ''??
         else:
             packet = dfb.DataPacket(str(data))
         if fut.debug > 1:  #pragma: nocover
             print '**3698**', 65 * '='
             if fut.debug > 2:  #pragma: nocover
                 show_data = '|'.join(fut.split_strings(str(data), 8))
                 print '**3705** data_in   = "%s"' % (
                     fut.data_to_hex_string(show_data[:80]))
         self.first_filter.send(packet)
     ##if close_at_end:
     ##self.first_filter.shut_down()
     # All data has arrived, so disconnect sink
     self.last_filter.next_filter = None
     # Store the full results packets in self.results in case they are
     # needed, returning the packet.data as a list.
     self.results = pump_sink.results
     # TO-DO: Decide about which data type here -- strings or lists
     ##        return pump_sink.results[-1].data
     if len(self.results) == 1:
         return self.results[0].data
     else:
         return [pkt.data for pkt in self.results]
Exemplo n.º 2
0
    def pump_data(self, data_in=None, zero_inputs=True): # << TO-DO Needs work
        ##, close_at_end=True):
        """Put the data into the pipeline by wrapping it in a Datapacket.
           Get the data out by temporarily sticking a Sink on the end,
           returning all the packets received.
           Remember to close the pipeline externally, if tidying up actions 
           need to be performed.
           
           
           If zero_inputs is True, reinitialise the variables before pumping 
           the new data in.  <<<<<<<zero_inputs<<<<<<<<< TO-DO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        """
        pump_sink = df.Sink()
        self.last_filter.next_filter = pump_sink
        print '**10195** Connect (%s, pump_data) %s >>> %s' % (
            self.name, self.last_filter.name, pump_sink.name)
        try:
            data_in + []           # TO-DO: Better way to check the data type
        except TypeError:  # Not a list
            data_in = [data_in]
        for data in data_in:
            if data is None:
##                packet = None
                packet = dfb.DataPacket(None)  # Or ''??
            else:
                packet = dfb.DataPacket(str(data))
            if fut.debug > 1:  #pragma: nocover
                print '**3698**', 65 * '='
                if fut.debug > 2:  #pragma: nocover
                    show_data = '|'.join(fut.split_strings(str(data), 8))
                    print '**3705** data_in   = "%s"' % (
                        fut.data_to_hex_string(show_data[:80]))
            self.first_filter.send(packet)
        ##if close_at_end:
            ##self.first_filter.shut_down()
        # All data has arrived, so disconnect sink
        self.last_filter.next_filter = None
        # Store the full results packets in self.results in case they are 
        # needed, returning the packet.data as a list.
        self.results = pump_sink.results
        # TO-DO: Decide about which data type here -- strings or lists
##        return pump_sink.results[-1].data
        if len(self.results) == 1:
            return self.results[0].data
        else:
            return [pkt.data for pkt in self.results]
Exemplo n.º 3
0
 def test_split_strings(self):
     self.assertEquals(fut.split_strings('ABCD', 2), ['AB', 'CD'])
     self.assertEquals(fut.split_strings('ABCDE', 2), ['AB', 'CD', 'E'])
     self.assertEquals(fut.split_strings('', 2), [])
     self.assertEquals(fut.split_strings('ABCDEF', 5), ['ABCDE', 'F'])
     self.assertRaises(ValueError, fut.split_strings, 'ABCDEF', 0)
 def test_split_strings(self):
     self.assertEquals(fut.split_strings('ABCD', 2), ['AB', 'CD'])
     self.assertEquals(fut.split_strings('ABCDE', 2), ['AB', 'CD', 'E'])
     self.assertEquals(fut.split_strings('', 2), [])
     self.assertEquals(fut.split_strings('ABCDEF', 5), ['ABCDE', 'F'])
     self.assertRaises(ValueError, fut.split_strings, 'ABCDEF', 0)