def UserUpdate(fCallback):
    '''Get User and log update requests passing to fCallback
    The log will be handed to fCallback when 'ok' is received'''
    def log_update_requests_and_call(self, *args, **kwargs):
        cmd = args[0]
        arg = args[1]

        # Empty line
        if cmd is None:
            return self.protocol.sendData()
        # Pass sessBuffer as updateLog to fCallback
        if cmd == 'ok':
            if len(self.sessBuffer) == 0:
                return self.protocol.sendData('Nothing to save')

            return fCallback(self, self.sessBuffer)
        else:
            # Unknown key
            if cmd not in UserKeyMap:
                return self.protocol.sendData('Unknown User key: %s' % cmd)
            if cmd == 'uid':
                return self.protocol.sendData('User id can not be modified !')
            if cmd == 'username':
                return self.protocol.sendData('User username can not be modified !')

            if isinstance(UserKeyMap[cmd], dict):
                # Provisioning a sub-User instance (MtMessagingCredential ...)
                subKeyMap = UserKeyMap[cmd]

                # Syntax validation
                _r = re.match(r'^(\S+) (\S+) (\S+.*$)', arg)
                if not _r:
                    return self.protocol.sendData('Error: expected syntax: %s section key value' % cmd)

                section = _r.group(1).lower()
                key = _r.group(2).lower()
                value = _r.group(3)

                # Validate section
                possible_values = subKeyMap.keys()
                possible_values.remove('class')
                possible_values.remove('keyMapValue')
                valid_section = False
                for pv in possible_values:
                    if section == pv.lower():
                        section = pv
                        valid_section = True
                        break
                if not valid_section:
                    return self.protocol.sendData('Error: invalid section name: %s, possible values: %s' % (
                        section, ', '.join(possible_values)))

                # Validate key
                if key not in subKeyMap[section].keys():
                    return self.protocol.sendData('Error: invalid key: %s, possible keys: %s' % (
                        key, ', '.join(subKeyMap[section].keys())))
                SectionKey = subKeyMap[section][key]

                try:
                    # Input value are received in string type, castToBuiltCorrectCredType will fix the
                    # type depending on class, section and SectionKey
                    SectionValue = castToBuiltCorrectCredType(
                        subKeyMap['class'], section, SectionKey, value, update=True)

                    # Instanciate a new sub-User dict to receive update-log to be applied
                    # once 'ok' is received
                    sessBufferKey = '_%s' % subKeyMap['keyMapValue']
                    if sessBufferKey not in self.sessBuffer:
                        self.sessBuffer[sessBufferKey] = {section: {}}
                    if section not in self.sessBuffer[sessBufferKey]:
                        self.sessBuffer[sessBufferKey][section] = {}

                    # Set sub-User object value
                    self.sessBuffer[sessBufferKey][section][SectionKey] = SectionValue
                except (jasminApiCredentialError, ValueError) as e:
                    return self.protocol.sendData('Error: %s' % str(e))
            else:
                # IF we got the gid, instanciate a Group if gid exists or return an error
                if cmd == 'gid':
                    group = self.pb['router'].getGroup(arg)
                    if group is None:
                        return self.protocol.sendData(
                            'Unknown Group gid:%s, you must first create the Group' % arg)

                    self.sessBuffer['group'] = group
                else:
                    # Buffer key for later (when receiving 'ok')
                    UserKey = UserKeyMap[cmd]
                    if UserKey not in UserConfigStringKeys:
                        self.sessBuffer[UserKey] = str2num(arg)
                    else:
                        self.sessBuffer[UserKey] = arg

            return self.protocol.sendData()
    return log_update_requests_and_call
dataset/ETHPy150Open jookies/jasmin/jasmin/protocols/cli/usersm.py/UserUpdate/original