# Path: mcm/librouteros/exceptions.py
# class ConnError( LibError ):
#     '''
#     Connection related errors.
#     '''


from socket import SHUT_RDWR, error as SOCKET_ERROR, timeout as SOCKET_TIMEOUT
from struct import pack, unpack
from mcm.librouteros.exceptions import ConnError

    bytes_length = len( bytes )

    if bytes_length < 2:
        offset = b'\x00\x00\x00'
        XOR = 0
    elif bytes_length < 3:
        offset = b'\x00\x00'
        XOR = 0x8000
    elif bytes_length < 4:
        offset = b'\x00'
        XOR = 0xC00000
    elif bytes_length < 5:
        offset = b''
        XOR = 0xE0000000
    else:
        raise ConnError( 'unable to decode length of {}'.format(bytes) )

    combined_bytes = offset + bytes
    decoded = unpack( '!I', combined_bytes )[0]
    decoded ^= XOR

    return decoded


def decsnt( sentence ):

    try:
        return tuple( word.decode( 'ASCII', 'strict' ) for word in sentence )
    except UnicodeDecodeError as error:

# Path: mcm/librouteros/exceptions.py
# class ConnError( LibError ):
#     '''
#     Connection related errors.
#     '''


# Path: mcm/librouteros/connections.py
from socket import SHUT_RDWR, error as SOCKET_ERROR, timeout as SOCKET_TIMEOUT
from struct import pack, unpack
from mcm.librouteros.exceptions import ConnError


    bytes_length = len( bytes )

    if bytes_length < 2:
        offset = b'\x00\x00\x00'
        XOR = 0
    elif bytes_length < 3:
        offset = b'\x00\x00'
        XOR = 0x8000
    elif bytes_length < 4:
        offset = b'\x00'
        XOR = 0xC00000
    elif bytes_length < 5:
        offset = b''
        XOR = 0xE0000000
    else:
        raise ConnError( 'unable to decode length of {}'.format(bytes) )

    combined_bytes = offset + bytes
    decoded = unpack( '!I', combined_bytes )[0]
    decoded ^= XOR

    return decoded


def decsnt( sentence ):

    try:
        return tuple( word.decode( 'ASCII', 'strict' ) for word in sentence )
    except UnicodeDecodeError as error:

        raise ConnError('Could not decode {!r}. Non ASCII characters'.format(error.object))