Exemple #1
0
    def bitstring_list_handler(self, **kwargs):
        bitstrings = kwargs['bitstring_list']
        resulted_bitstrings = []
        for index in range(0, len(bitstrings)):
            signal_slot.connect(bitstrings[index], 'bitstring', self._bitmappings[index], 'bitstring')

            #Initialize an empty bitstring whose size equals to mapped bitstring length
            # Dirty Trick, fix this!!!!!!!!!!!!!!!!!******************************
            resulted_bitstring = BitString(size=self._bitmappings[index].output_len())
            signal_slot.connect(self._bitmappings[index], 'bitstring', resulted_bitstring, 'bitstring')
            bitstrings[index].emit('bitstring', bitstring=str(bitstrings[index]))
            resulted_bitstrings.append(resulted_bitstring)

        self.emit('bitstring_list', bitstring_list=resulted_bitstrings)
Exemple #2
0
            length = len(a_bitstring)
            for internal_pos in range(0, length):
                self._output_bitstring[pos] = a_bitstring[internal_pos]
                pos = pos + 1


if __name__ == "__main__":

    @SignalSupporter("bitstring")
    class Source(object):
        pass

    s = Source()
    bs = BitString(bitstring="1001")

    signal_slot.connect(s, "bitstring", bs, "bitstring")
    s.emit("bitstring", bitstring="10011")
    print bs

    bd = BitStringDivider([3, 4], [0, 2, 1], [7, 5, 6])
    bd.bitstring_handler(bitstring="10110010")
    bd.apply()
    for b in bd._bitstrings:
        print b

    bl = [
        BitString(bitstring="101"),
        BitString(bitstring="00110"),
        BitString(bitstring="1100"),
        BitString(bitstring="1111"),
    ]
Exemple #3
0
if __name__ == '__main__':
    from bit_permutation import BitPermutation

    # Begin test of simple bitstring mapping
    print 'Testing BitMapping'
    @SignalSupporter('bitstring', 'intvalue')
    class Foo(object):
        pass

    bm = BitMapping({'1001':'1100', '0001':'1111', '1101':'1000', '0111':'1011'})
    print 'Output len: %s' % bm.output_len()
    bp = BitPermutation([3, 0, 1, 2])
    f = Foo()

    signal_slot.connect(f, 'bitstring', bm, 'bitstring')
    signal_slot.connect(bm, 'bitstring', bp, 'bitstring')

    f.emit('bitstring', bitstring='0111')
    print bm._output_bitstring
    print bp._output_bitstring

    f.emit('bitstring', bitstring='1001')
    print bm._output_bitstring
    print bp._output_bitstring
    print 'End of BitMapping testing'
    # End of testing

    # Testing of BitMappingGroup
    print 'Testing BitMappingGroup'
    bss = [BitString(bitstring='1001'), BitString(bitstring='1101'), BitString(bitstring='001')]

    def permute(self, permutation_list=None):
        """
        Permute according to permutation list
        """
        if permutation_list is not None:
            return self._bitstring.permute(permutation_list)
        else:
            if self._permutation_list is not None:
                return self._bitstring.permute(self._permutation_list)
        raise ValueError("Permutation list is not given nor initialized.")

    def bitstring_handler(self, **kwargs):
        self._input_bitstring = BitString(bitstring=kwargs['bitstring'])
        self.apply()

    def apply(self):
        self._output_bitstring = self._input_bitstring.permute(self._permutation_list)

if __name__ == '__main__':
    @SignalSupporter('bitstring')
    class Source(object):
        pass

    s = Source()
    bp = BitPermutation([3, 0, 2, 1])
    signal_slot.connect(s, 'bitstring', bp, 'bitstring')
    s.emit('bitstring', bitstring='1010')
    print bp._output_bitstring