def offsetcopy(s, newoffset):
    """Return a copy of a ByteStore with the newoffset.

    Not part of public interface.
    """
    assert 0 <= newoffset < 8
    if not s.bitlength:
        return copy.copy(s)
    else:
        if newoffset == s.offset % 8:
            return ByteStore(s.getbyteslice(s.byteoffset, s.byteoffset + s.bytelength), s.bitlength, newoffset)
        newdata = []
        d = s._rawarray
        assert newoffset != s.offset % 8
        if newoffset < s.offset % 8:
            # We need to shift everything left
            shiftleft = s.offset % 8 - newoffset
            # First deal with everything except for the final byte
            for x in range(s.byteoffset, s.byteoffset + s.bytelength - 1):
                newdata.append(((d[x] << shiftleft) & 0xff) +\
                               (d[x + 1] >> (8 - shiftleft)))
            bits_in_last_byte = (s.offset + s.bitlength) % 8
            if not bits_in_last_byte:
                bits_in_last_byte = 8
            if bits_in_last_byte > shiftleft:
                newdata.append((d[s.byteoffset + s.bytelength - 1] << shiftleft) & 0xff)
        else: # newoffset > s._offset % 8
            shiftright = newoffset - s.offset % 8
            newdata.append(s.getbyte(0) >> shiftright)
            for x in range(s.byteoffset + 1, s.byteoffset + s.bytelength):
                newdata.append(((d[x - 1] << (8 - shiftright)) & 0xff) +\
                               (d[x] >> shiftright))
            bits_in_last_byte = (s.offset + s.bitlength) % 8
            if not bits_in_last_byte:
                bits_in_last_byte = 8
            if bits_in_last_byte + shiftright > 8:
                newdata.append((d[s.byteoffset + s.bytelength - 1] << (8 - shiftright)) & 0xff)
        new_s = ByteStore(bytearray(newdata), s.bitlength, newoffset)
        assert new_s.offset == newoffset
        return new_s
def offsetcopy ( s , newoffset ) : assert 0 <= newoffset < 8 if not s . bitlength : return copy . copy ( s ) else : if newoffset == s . offset % 8 : return ByteStore ( s . getbyteslice ( s . byteoffset , s . byteoffset + s . bytelength ) , s . bitlength , newoffset ) newdata = [ ] d = s . _rawarray assert newoffset != s . offset % 8 if newoffset < s . offset % 8 : shiftleft = s . offset % 8 - newoffset for x in range ( s . byteoffset , s . byteoffset + s . bytelength - 1 ) : newdata . append ( ( ( d [ x ] << shiftleft ) & 0xff ) + ( d [ x + 1 ] >> ( 8 - shiftleft ) ) ) bits_in_last_byte = ( s . offset + s . bitlength ) % 8 if not bits_in_last_byte : bits_in_last_byte = 8 if bits_in_last_byte > shiftleft : newdata . append ( ( d [ s . byteoffset + s . bytelength - 1 ] << shiftleft ) & 0xff ) else : shiftright = newoffset - s . offset % 8 newdata . append ( s . getbyte ( 0 ) >> shiftright ) for x in range ( s . byteoffset + 1 , s . byteoffset + s . bytelength ) : newdata . append ( ( ( d [ x - 1 ] << ( 8 - shiftright ) ) & 0xff ) + ( d [ x ] >> shiftright ) ) bits_in_last_byte = ( s . offset + s . bitlength ) % 8 if not bits_in_last_byte : bits_in_last_byte = 8 if bits_in_last_byte + shiftright > 8 : newdata . append ( ( d [ s . byteoffset + s . bytelength - 1 ] << ( 8 - shiftright ) ) & 0xff ) new_s = ByteStore ( bytearray ( newdata ) , s . bitlength , newoffset ) assert new_s . offset == newoffset return new_s
Return a copy of a ByteStore with the newoffset.

    Not part of public interface.