'If ``mode`` isn\'t provided, the most compact QR data type possible is
chosen.'

def __init__(self, data, mode=None, check_data=True):

    if check_data:
        data = to_bytestring(data)
    if (mode is None):
        self.mode = optimal_mode(data)
    else:
        self.mode = mode
        if (mode not in (MODE_NUMBER, MODE_ALPHA_NUM, MODE_8BIT_BYTE)):
            raise TypeError(('Invalid    mode    (%s)' % mode))
        if (check_data and (mode < optimal_mode(data))):
            raise ValueError('Provided    data    can    not    be    represented    in    mode    {0}'.format(mode))
    self.data = data
