当前位置: 首页>>代码示例>>Python>>正文


Python Context.local方法代码示例

本文整理汇总了Python中context.Context.local方法的典型用法代码示例。如果您正苦于以下问题:Python Context.local方法的具体用法?Python Context.local怎么用?Python Context.local使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在context.Context的用法示例。


在下文中一共展示了Context.local方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import local [as 别名]

#.........这里部分代码省略.........
            except NumberingException as e:
                log.error(e)
                # TODO: play message of calling number is not authorized to call
                self.session.hangup()

            try:
                if (self._n.is_number_roaming(self.destination_number)):
                    processed = 1
                    log.info(
                        'Destination number %s is roaming'
                        % self.destination_number)
                    self.context.roaming('called')
            except NumberingException as e:
                log.error(e)
                # TODO: play message of destination number
                # unauthorized to receive call
                self.session.hangup()

            # check if destination number is an international call.
            # prefix with + or 00
            if (
                self.destination_number[0] == '+' or (
                    re.search(r'^00', self.destination_number) is not None)
            ) and processed == 0:
                log.debug('Called number is an international call or national')
                processed = 1
                log.debug(
                    'Called number is an external number '
                    'send call to OUTBOUND context')
                self.auth_context('outbound')

        if processed == 0:
            try:
                log.info('Check if called number is local')
                dest = self.destination_number
                is_local_number = self._n.is_number_local(dest)
                is_right_len = lambda num: len(num) == 11

                if is_local_number and is_right_len(dest):
                    log.info('Called number is a local number')
                    processed = 1
                    # check if calling number is another site

                    callin = self.calling_number
                    is_internal_number = self._n.is_number_internal(callin)
                    if is_internal_number and is_right_len(callin):

                        # check if dest number is authorized to receive call
                        # if self.subscriber.is_authorized(
                        # self.calling_number,0):
                        log.info('INTERNAL call from another site')
                        if self.subscriber.is_authorized(dest, 0):
                            log.info(
                                'Internal call send number to LOCAL context')
                            self.context.local()
                        else:
                            log.info(
                                'Destination subscriber is '
                                'unauthorized to receive calls')
                            # self.play_announcement(
                            # '002_saldo_insuficiente.gsm')
                            self.session.hangup()
                    else:
                        if self.subscriber.is_authorized(dest, 0):
                            log.info('Send call to LOCAL context')
                            self.auth_context('local')
开发者ID:ciaby,项目名称:rccn,代码行数:70,代码来源:dialplan.py

示例2: __init__

# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import local [as 别名]
class Dialplan:
    """
    Logic to assign the call to the right context
    """
    NOT_CREDIT_ENOUGH = '002_saldo_insuficiente.gsm'
    NOT_AUTH = '013_no_autorizado.gsm'
    NOT_REGISTERED = '015_no_access.gsm'
    WRONG_NUMBER = '007_el_numero_no_es_corecto.gsm'
    ERROR = '016_oops.gsm'

    def __init__(self, session):
        """ init """
        self.session = session
        self.destination_number = self.session.getVariable(
            'destination_number')
        self.calling_number = self.session.getVariable('caller_id_number')
        self.calling_host = self.session.getVariable("sip_network_ip")

        self.subscriber = Subscriber()
        self.numbering = Numbering()
        self._n = self.numbering
        self.billing = Billing()
        self.configuration = Configuration()
        self.local_caller_check = False

        modules = [self.subscriber, self.numbering,
                   self.billing, self.configuration]

        self.context = Context(session, modules)

    def parse_chans(self, data):
        chans = []
        lines = data.split('\n')
        for line in lines:
            if line != '' and line.find(' total.') == -1:
                values = line.split('|')
                if values[0] == 'uuid':
                    keys = values
                    continue
                chan = {}
                for i, val in enumerate(values):
                    try:
                        chan[keys[i]] = val
                    except Exception as ex:
                        log.debug(ex)
                chans.append(chan)
        return chans

    def check_chans(self, match, max, redirect=''):
        i = 0
        while self.session.ready() and i < 4:
            _count = 0
            self.session.execute("set", "_temp=${show channels as delim |}")
            # Below avoids recursive data returned due to _temp=[channels] being the
            # current application_data in this channel.
            self.session.execute("set", "_tmp=1")
            _chans = self.parse_chans(self.session.getVariable('_temp'))
            for chan in _chans:
                if chan['dest'] == match:
                    _count += 1
            log.info("Channel Usage(%s) for [%s]", _count, match)
            if _count < max:
                return True
            log.info("Channel Capacity for(%s) is exceeded.", match)
            if redirect == '':
                self.play_announcement("RESOURCE_UNAVAIL")
                self.session.hangup()
                return False
            #self.session.execute('playback', '018_ocupadas.gsm')
            self.session.execute('playback', '017_marca.gsm')
            self.session.execute('say', 'es number iterated %s' % redirect)
            i += 1
        self.session.hangup()
        return False

    def play_announcement(self, status):
        """
        Play an announcement.
        """
        ann = self.context.get_audio_file(status)
        self.session.execute('playback', '%s' % ann)

    def auth_context(self, mycontext):
        """
        Authenticate subscriber before route call to context

        :param mycontext: The context to route the call to
        """
        log.debug('Check if subscriber %s is registered and authorized',
                  self.calling_number)
        try:
            if self.subscriber.is_authorized(self.calling_number, 0):
                self.context.destination_number = self.destination_number
                log.debug('Subscriber is registered and authorized to call')
                exectx = getattr(self.context, mycontext)
                exectx()
            else:
                self.session.setVariable('context', mycontext.upper())
                log.info('Subscriber is not registered or authorized to call')
                self.play_announcement("OUTGOING_CALL_BARRED")
#.........这里部分代码省略.........
开发者ID:Rhizomatica,项目名称:rccn,代码行数:103,代码来源:dialplan.py


注:本文中的context.Context.local方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。