def prepare_record(params, record, shared_folder_uid=''):
    ''' Prepares the record to be sent to the Keeper server
    :return: record encrypted and ready to be included into record_update json
    '''
    if not record.record_uid:
        record.record_uid = generate_record_uid()

    if params.debug: print('record UID: ' + record.record_uid)

    if params.record_cache in record.record_uid:
        raise Exception('Record UID already exists.')

    # generate friendly datestamp
    modified_time = int(round(time.time()))
    modified_time_milli = modified_time * 1000
    datestamp = datetime.datetime.fromtimestamp(
        modified_time).strftime('%Y-%m-%d %H:%M:%S')

    # initialize data and extra
    data = {}
    extra = {}
    udata = []

    data['title'] = record.title
    data['folder'] = record.folder
    data['secret1'] = record.login
    data['secret2'] = record.password
    data['link'] = record.login_url
    data['notes'] = record.notes
    data['custom'] = record.custom_fields

    # Convert the data and extra dictionary to string object
    # with double quotes instead of single quotes
    data_serialized = json.dumps(data)
    extra_serialized = json.dumps(extra)

    if params.debug: print('Dictionary: ' + str(data))
    if params.debug: print('Serialized: : ' + str(data_serialized))

    # generate a record key
    unencrypted_key = os.urandom(32)
    iv = os.urandom(16)
    cipher = AES.new(params.data_key, AES.MODE_CBC, iv)
    type1key = iv + cipher.encrypt(pad_binary(unencrypted_key))
    encoded_type1key = (base64.urlsafe_b64encode(
                           type1key).decode()).rstrip('==')

    if params.debug: print('generated key=' + str(type1key))
    if params.debug: print('encoded=' + str(encoded_type1key))

    # encrypt data with record key
    iv = os.urandom(16)
    cipher = AES.new(unencrypted_key, AES.MODE_CBC, iv)
    encrypted_data = iv + cipher.encrypt(pad(data_serialized))

    # encrypt extra with record key
    iv = os.urandom(16)
    cipher = AES.new(unencrypted_key, AES.MODE_CBC, iv)
    encrypted_extra = iv + cipher.encrypt(pad(extra_serialized))

    if params.debug: print('encrypted_data: ' + str(encrypted_data))
    if params.debug: print('encrypted_extra: ' + str(encrypted_extra))

    # note: decode() converts bytestream (b') to string
    encoded_data = base64.urlsafe_b64encode(encrypted_data).decode()
    encoded_extra = base64.urlsafe_b64encode(encrypted_extra).decode()

    if params.debug: print('encoded_data: ' + str(encoded_data))
    if params.debug: print('encoded_extra: ' + str(encoded_extra))

    # build a record object
    new_record = {}
    new_record['record_uid'] = record.record_uid
    new_record['version'] = 2
    new_record['data'] = encoded_data
    new_record['extra'] = encoded_extra
    new_record['udata'] = udata
    new_record['client_modified_time'] = modified_time_milli
    new_record['revision'] = 0
    new_record['record_key'] = encoded_type1key
    if shared_folder_uid:
        new_record['shared_folder_uid'] = shared_folder_uid

    if params.debug: print('new_record: ' + str(new_record))

    return new_record
dataset/ETHPy150Open Keeper-Security/Commander/keepercommander/api.py/prepare_record/swapped operands of `in`