Пример #1
0
    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 not SMPPClientConfigKeyMap.has_key(cmd):
                return self.protocol.sendData('Unknown SMPPClientConfig key: %s' % cmd)
            if cmd == 'cid':
                return self.protocol.sendData('Connector id can not be modified !')
            
            # Buffer key for later (when receiving 'ok')
            SMPPClientConfigKey = SMPPClientConfigKeyMap[cmd]
            self.sessBuffer[SMPPClientConfigKey] = str2num(arg)
            
            return self.protocol.sendData()
Пример #2
0
    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')

            try:
                # Initiate a volatile SMPPClientConfig instance to run through it's constructor
                # validation steps, this will raise an exception whenever an error is detected
                configArgs = self.sessBuffer
                configArgs['id'] = self.sessionContext['cid']
                SMPPClientConfig(**configArgs)
            except Exception as e:
                return self.protocol.sendData('Error: %s' % str(e))

            return fCallback(self, self.sessBuffer)
        else:
            # Unknown key
            if cmd not in SMPPClientConfigKeyMap:
                return self.protocol.sendData(
                    'Unknown SMPPClientConfig key: %s' % cmd)
            if cmd == 'cid':
                return self.protocol.sendData(
                    'Connector id can not be modified !')

            try:
                # Buffer key for later (when receiving 'ok')
                SMPPClientConfigKey = SMPPClientConfigKeyMap[cmd]
                if isinstance(
                        arg, str
                ) and SMPPClientConfigKey not in SMPPClientConfigStringKeys:
                    self.sessBuffer[
                        SMPPClientConfigKey] = castInputToBuiltInType(
                            cmd, str2num(arg))
                else:
                    self.sessBuffer[
                        SMPPClientConfigKey] = castInputToBuiltInType(
                            cmd, arg)
            except Exception as e:
                return self.protocol.sendData('Error: %s' % str(e))

            return self.protocol.sendData()
Пример #3
0
    def parse_args_and_call_with_instance(self, *args, **kwargs):
        cmd = args[0]
        arg = args[1]

        # Empty line
        if cmd is None:
            return self.protocol.sendData()
        # Initiate JCliSMPPClientConfig with sessBuffer content
        if cmd == 'ok':
            if len(self.sessBuffer) == 0:
                return self.protocol.sendData(
                    'You must set at least connector id (cid) before saving !')

            connector = {}
            for key, value in self.sessBuffer.iteritems():
                connector[key] = value
            try:
                SMPPClientConfigInstance = JCliSMPPClientConfig(**connector)
                # Hand the instance to fCallback
                return fCallback(self, SMPPClientConfigInstance)
            except Exception as e:
                return self.protocol.sendData('Error: %s' % str(e))
        else:
            # Unknown key
            if cmd not in SMPPClientConfigKeyMap:
                return self.protocol.sendData(
                    'Unknown SMPPClientConfig key: %s' % cmd)

            try:
                # Buffer key for later SMPPClientConfig initiating
                SMPPClientConfigKey = SMPPClientConfigKeyMap[cmd]
                if isinstance(
                        arg, str
                ) and SMPPClientConfigKey not in SMPPClientConfigStringKeys:
                    self.sessBuffer[
                        SMPPClientConfigKey] = castInputToBuiltInType(
                            cmd, str2num(arg))
                else:
                    self.sessBuffer[
                        SMPPClientConfigKey] = castInputToBuiltInType(
                            cmd, arg)
            except Exception as e:
                return self.protocol.sendData('Error: %s' % str(e))

            return self.protocol.sendData()
Пример #4
0
            try:
                SMPPClientConfigInstance = JCliSMPPClientConfig(**connector)
                # Hand the instance to fCallback
                return fCallback(self, SMPPClientConfigInstance)
            except Exception, e:
                return self.protocol.sendData('Error: %s' % str(e))
        else:
            # Unknown key
            if not SMPPClientConfigKeyMap.has_key(cmd):
                return self.protocol.sendData('Unknown SMPPClientConfig key: %s' % cmd)

            try:
                # Buffer key for later SMPPClientConfig initiating
                SMPPClientConfigKey = SMPPClientConfigKeyMap[cmd]
                if isinstance(arg, str) and SMPPClientConfigKey not in SMPPClientConfigStringKeys:
                    self.sessBuffer[SMPPClientConfigKey] = castInputToBuiltInType(cmd, str2num(arg))
                else:
                    self.sessBuffer[SMPPClientConfigKey] = castInputToBuiltInType(cmd, arg)
            except Exception, e:
                return self.protocol.sendData('Error: %s' % str(e))

            return self.protocol.sendData()
    return parse_args_and_call_with_instance

def SMPPClientConfigUpdate(fCallback):
    '''Get connector configuration 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]
Пример #5
0
                return self.protocol.sendData('Error: %s' % str(e))
        else:
            # Unknown key
            if cmd not in SMPPClientConfigKeyMap:
                return self.protocol.sendData(
                    'Unknown SMPPClientConfig key: %s' % cmd)

            try:
                # Buffer key for later SMPPClientConfig initiating
                SMPPClientConfigKey = SMPPClientConfigKeyMap[cmd]
                if isinstance(
                        arg, str
                ) and SMPPClientConfigKey not in SMPPClientConfigStringKeys:
                    self.sessBuffer[
                        SMPPClientConfigKey] = castInputToBuiltInType(
                            cmd, str2num(arg))
                else:
                    self.sessBuffer[
                        SMPPClientConfigKey] = castInputToBuiltInType(
                            cmd, arg)
            except Exception, e:
                return self.protocol.sendData('Error: %s' % str(e))

            return self.protocol.sendData()

    return parse_args_and_call_with_instance


def SMPPClientConfigUpdate(fCallback):
    '''Get connector configuration and log update requests passing to fCallback
    The log will be handed to fCallback when 'ok' is received'''
Пример #6
0
    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()
Пример #7
0
            else:
                # Provisioning User instance
                # 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 User initiating
                    UserKey = UserKeyMap[cmd]
                    if UserKey not in UserConfigStringKeys:
                        self.sessBuffer[UserKey] = str2num(arg)
                    else:
                        self.sessBuffer[UserKey] = arg

            return self.protocol.sendData()

    return parse_args_and_call_with_instance


class UserExist(object):
    'Check if user uid exist before passing it to fCallback'

    def __init__(self, uid_key):
        self.uid_key = uid_key

    def __call__(self, fCallback):
Пример #8
0
    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 not UserKeyMap.has_key(cmd):
                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 type(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)
                key = _r.group(2)
                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)

                    # 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()
Пример #9
0
                except (jasminApiCredentialError, ValueError) as e:
                    return self.protocol.sendData('Error: %s' % str(e))
            else:
                # Provisioning User instance                
                # 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 User initiating
                    UserKey = UserKeyMap[cmd]
		    if UserKey not in UserConfigStringKeys:
                	self.sessBuffer[UserKey] = str2num(arg)
                    else:
                        self.sessBuffer[UserKey] = arg

            return self.protocol.sendData()
    return parse_args_and_call_with_instance

class UserExist:
    'Check if user uid exist before passing it to fCallback'
    def __init__(self, uid_key):
        self.uid_key = uid_key
    def __call__(self, fCallback):
        uid_key = self.uid_key
        def exist_user_and_call(self, *args, **kwargs):
            opts = args[1]
            uid = getattr(opts, uid_key)
Пример #10
0
    def parse_args_and_call_with_instance(self, *args, **kwargs):
        cmd = args[0]
        arg = args[1]

        # Empty line
        if cmd is None:
            return self.protocol.sendData()
        # Initiate jasmin.routing.jasminApi.User with sessBuffer content
        if cmd == 'ok':
            if ('uid' not in self.sessBuffer or
                        'group' not in self.sessBuffer or
                        'username' not in self.sessBuffer or
                        'password' not in self.sessBuffer):
                return self.protocol.sendData(
                    'You must set User id (uid), group (gid), username and password before saving !')

            # Set defaults when not defined
            if 'mt_credential' not in self.sessBuffer:
                self.sessBuffer[UserKeyMap['mt_messaging_cred']['keyMapValue']] = globals()[
                    UserKeyMap['mt_messaging_cred']['class']]()
            if 'smpps_credential' not in self.sessBuffer:
                self.sessBuffer[UserKeyMap['smpps_cred']['keyMapValue']] = globals()[
                    UserKeyMap['smpps_cred']['class']]()

            user = {}
            for key, value in self.sessBuffer.iteritems():
                user[key] = value
            try:
                UserInstance = User(**user)
                # Hand the instance to fCallback
                return fCallback(self, UserInstance)
            except Exception as e:
                return self.protocol.sendData('Error: %s' % str(e))
        else:
            # Unknown key
            if cmd not in UserKeyMap:
                return self.protocol.sendData('Unknown User key: %s' % cmd)

            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)

                    # Instanciate a new sub-User object
                    if subKeyMap['keyMapValue'] not in self.sessBuffer:
                        self.sessBuffer[subKeyMap['keyMapValue']] = globals()[subKeyMap['class']]()

                    # Set sub-User object value
                    getattr(self.sessBuffer[subKeyMap['keyMapValue']], 'set%s' % section)(
                        SectionKey, SectionValue)
                except (jasminApiCredentialError, ValueError) as e:
                    return self.protocol.sendData('Error: %s' % str(e))
            else:
                # Provisioning User instance
                # 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 User initiating
                    UserKey = UserKeyMap[cmd]
                    if UserKey not in UserConfigStringKeys:
                        self.sessBuffer[UserKey] = str2num(arg)
                    else:
                        self.sessBuffer[UserKey] = arg

            return self.protocol.sendData()
Пример #11
0
    def parse_args_and_call_with_instance(self, *args, **kwargs):
        cmd = args[0]
        arg = args[1]

        # Empty line
        if cmd is None:
            return self.protocol.sendData()
        # Initiate jasmin.routing.jasminApi.User with sessBuffer content
        if cmd == 'ok':
            if ('uid' not in self.sessBuffer or 'group' not in self.sessBuffer
                    or 'username' not in self.sessBuffer
                    or 'password' not in self.sessBuffer):
                return self.protocol.sendData(
                    'You must set User id (uid), group (gid), username and password before saving !'
                )

            # Set defaults when not defined
            if 'mt_credential' not in self.sessBuffer:
                self.sessBuffer[UserKeyMap['mt_messaging_cred']
                                ['keyMapValue']] = globals()[
                                    UserKeyMap['mt_messaging_cred']['class']]()
            if 'smpps_credential' not in self.sessBuffer:
                self.sessBuffer[UserKeyMap['smpps_cred']
                                ['keyMapValue']] = globals()[
                                    UserKeyMap['smpps_cred']['class']]()

            user = {}
            for key, value in self.sessBuffer.iteritems():
                user[key] = value
            try:
                UserInstance = User(**user)
                # Hand the instance to fCallback
                return fCallback(self, UserInstance)
            except Exception as e:
                return self.protocol.sendData('Error: %s' % str(e))
        else:
            # Unknown key
            if cmd not in UserKeyMap:
                return self.protocol.sendData('Unknown User key: %s' % cmd)

            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)

                    # Instanciate a new sub-User object
                    if subKeyMap['keyMapValue'] not in self.sessBuffer:
                        self.sessBuffer[subKeyMap['keyMapValue']] = globals()[
                            subKeyMap['class']]()

                    # Set sub-User object value
                    getattr(self.sessBuffer[subKeyMap['keyMapValue']],
                            'set%s' % section)(SectionKey, SectionValue)
                except (jasminApiCredentialError, ValueError) as e:
                    return self.protocol.sendData('Error: %s' % str(e))
            else:
                # Provisioning User instance
                # 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 User initiating
                    UserKey = UserKeyMap[cmd]
                    if UserKey not in UserConfigStringKeys:
                        self.sessBuffer[UserKey] = str2num(arg)
                    else:
                        self.sessBuffer[UserKey] = arg

            return self.protocol.sendData()
Пример #12
0
    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')

            try:
                # Initiate a volatile SMPPClientConfig instance to run through it's constructor
                # validation steps, this will raise an exception whenever an error is detected
                configArgs = self.sessBuffer
                configArgs['id'] = self.sessionContext['cid']
                SMPPClientConfig(**configArgs)
            except Exception as e:
                return self.protocol.sendData('Error: %s' % str(e))

            return fCallback(self, self.sessBuffer)
        else:
            # Unknown key
            if cmd not in SMPPClientConfigKeyMap:
                return self.protocol.sendData('Unknown SMPPClientConfig key: %s' % cmd)
            if cmd == 'cid':
                return self.protocol.sendData('Connector id can not be modified !')

            try:
                # Buffer key for later (when receiving 'ok')
                SMPPClientConfigKey = SMPPClientConfigKeyMap[cmd]
                if isinstance(arg, str) and SMPPClientConfigKey not in SMPPClientConfigStringKeys:
                    self.sessBuffer[SMPPClientConfigKey] = castInputToBuiltInType(cmd, str2num(arg))
                else:
                    self.sessBuffer[SMPPClientConfigKey] = castInputToBuiltInType(cmd, arg)
            except Exception as e:
                return self.protocol.sendData('Error: %s' % str(e))

            return self.protocol.sendData()
Пример #13
0
    def parse_args_and_call_with_instance(self, *args, **kwargs):
        cmd = args[0]
        arg = args[1]

        # Empty line
        if cmd is None:
            return self.protocol.sendData()
        # Initiate JCliSMPPClientConfig with sessBuffer content
        if cmd == 'ok':
            if len(self.sessBuffer) == 0:
                return self.protocol.sendData('You must set at least connector id (cid) before saving !')

            connector = {}
            for key, value in self.sessBuffer.iteritems():
                connector[key] = value
            try:
                SMPPClientConfigInstance = JCliSMPPClientConfig(**connector)
                # Hand the instance to fCallback
                return fCallback(self, SMPPClientConfigInstance)
            except Exception as e:
                return self.protocol.sendData('Error: %s' % str(e))
        else:
            # Unknown key
            if cmd not in SMPPClientConfigKeyMap:
                return self.protocol.sendData('Unknown SMPPClientConfig key: %s' % cmd)

            try:
                # Buffer key for later SMPPClientConfig initiating
                SMPPClientConfigKey = SMPPClientConfigKeyMap[cmd]
                if isinstance(arg, str) and SMPPClientConfigKey not in SMPPClientConfigStringKeys:
                    self.sessBuffer[SMPPClientConfigKey] = castInputToBuiltInType(cmd, str2num(arg))
                else:
                    self.sessBuffer[SMPPClientConfigKey] = castInputToBuiltInType(cmd, arg)
            except Exception as e:
                return self.protocol.sendData('Error: %s' % str(e))

            return self.protocol.sendData()
Пример #14
0
        else:
            # Unknown key
            if not SMPPClientConfigKeyMap.has_key(cmd):
                return self.protocol.sendData('Unknown SMPPClientConfig key: %s' % cmd)
            
            # Cast to boolean
            if cmd in ['con_loss_retry', 'con_fail_retry']:
                if arg.lower() in ['yes', 'y', '1']:
                    arg = True
                elif arg.lower() in ['no', 'n', '0']:
                    arg = False
            
            # Buffer key for later SMPPClientConfig initiating
            SMPPClientConfigKey = SMPPClientConfigKeyMap[cmd]
            if isinstance(arg, str):
                self.sessBuffer[SMPPClientConfigKey] = str2num(arg)
            else:
                self.sessBuffer[SMPPClientConfigKey] = arg
            
            return self.protocol.sendData()
    return parse_args_and_call_with_instance

def SMPPClientConfigUpdate(fCallback):
    '''Get connector configuration 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:
Пример #15
0
            try:
                SMPPClientConfigInstance = JCliSMPPClientConfig(**connector)
                # Hand the instance to fCallback
                return fCallback(self, SMPPClientConfigInstance)
            except Exception, e:
                return self.protocol.sendData('Error: %s' % str(e))
        else:
            # Unknown key
            if cmd not in SMPPClientConfigKeyMap:
                return self.protocol.sendData('Unknown SMPPClientConfig key: %s' % cmd)

            try:
                # Buffer key for later SMPPClientConfig initiating
                SMPPClientConfigKey = SMPPClientConfigKeyMap[cmd]
                if isinstance(arg, str) and SMPPClientConfigKey not in SMPPClientConfigStringKeys:
                    self.sessBuffer[SMPPClientConfigKey] = castInputToBuiltInType(cmd, str2num(arg))
                else:
                    self.sessBuffer[SMPPClientConfigKey] = castInputToBuiltInType(cmd, arg)
            except Exception, e:
                return self.protocol.sendData('Error: %s' % str(e))

            return self.protocol.sendData()
    return parse_args_and_call_with_instance

def SMPPClientConfigUpdate(fCallback):
    '''Get connector configuration 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]