Beispiel #1
0
def test_nanpa():

    ni = NanpaDB.getNumberInfo('+15412233333')
    assert (ni['state'] == 'OR')
    assert (ni['lata'] == '670')
    ni = NanpaDB.getNumberInfo('5039433333')
    assert (ni['state'] == 'OR')
    assert (ni['lata'] == '672')
Beispiel #2
0
def test_nanpa():

    ni = NanpaDB.getNumberInfo('+15412233333')
    assert(ni['state'] == 'OR')
    assert(ni['lata'] == '670')
    ni = NanpaDB.getNumberInfo('5039433333')
    assert(ni['state'] == 'OR')
    assert(ni['lata'] == '672')
Beispiel #3
0
    def finalize(self):

        #print 'finalizing) c_from=%s c_to=%s tag=%s' % (self.c_from, self.c_to, self.tag)

        customer = netcall.getCustomerObject(self.c_from)

        if not customer:
            log.warning("no customer object found for c_from %s.  callid=%s",
                        self.c_from, self.callid)
            log.warning(
                " --> FIX THIS so opensips always records c_from regardless")
            return
            #sys.exit(-1)

        if self.c_to:  # c_to may be null if this all routes were tried and we're returning 480 to client
            terminator = netcall.getTerminatorObject(self.c_to)

        ## compute final times
        if self.t_confirm and self.t_start:
            self.s_setup = int((self.t_confirm - self.t_start).total_seconds())

        if self.t_confirm and self.t_end:
            self.s_connected = int(
                (self.t_end - self.t_confirm).total_seconds())

        if self.t_start and self.t_end:
            self.s_total = int((self.t_end - self.t_start).total_seconds())

        # set anum to btn if needed
        btn_used = False
        self.anum2 = self.anum
        if (not PhoneNumber.isUSdomesticNumber(self.anum)
                and not PhoneNumber.isInterationalNumber(self.anum)):

            btn_used = True
            log.debug("will use btn for anum %s", self.anum)

            if customer.btn:
                self.anum2 = customer.btn
            else:
                self.anum2 = '?BTN?'

        ## compute jurisdiction info

        # warn if b_lrn isn't set: the routing and LRN logic should always
        # set some value for b_lrn (but occassionally LRN dip fails or doesn't return a mapping)
        if not self.b_lrn:
            self.b_lrn = self.bnum
            log.warning('b_lrn not set. using bnum instead')

        # TODO: clarify what happens when BTN was substituted ...
        # call origination type - domestic or international?
        ed = PhoneNumber.num2codes(self.anum2)
        if ed:
            self.a_country = ed[2]
        # note: isUSdomesticNumber is lax compared to num2codes ... TODO implement logic to decide when to use
        # lax or strict parsing rules -- like in a Carrier subclass, since different carriers may have different
        # policies or can assume certain countries/defaults when numbers are ambiguous
        if PhoneNumber.isUSdomesticNumber(self.anum2): self.a_jtype = 'D'
        elif PhoneNumber.isInterationalNumber(self.anum2): self.a_jtype = 'I'
        else: self.a_jtype = 'U'
        if self.a_jtype == 'D' and self.a_country != 'US':
            log.warning(
                'PhoneNumber num2codes & isUSdomesticNumber returning inconsistent result! lax parsing case? anum2=%s',
                self.anum2)

        # call destination type - domestic or international? (note: parsing bnum here less reliable than looking at lcr route used?)
        ed = PhoneNumber.num2codes(self.b_lrn)
        if ed:
            self.b_country = ed[2]
        if PhoneNumber.isUSdomesticNumber(self.b_lrn): self.b_jtype = 'D'
        elif PhoneNumber.isInterationalNumber(self.b_lrn): self.b_jtype = 'I'
        else: self.b_jtype = 'U'
        if self.b_jtype == 'D' and self.b_country != 'US':
            log.warning(
                'PhoneNumber num2codes & isUSdomesticNumber returning inconsistent result! lax parsing case? b_lrn=%s',
                self.b_lrn)

        if self.b_jtype == 'D':
            ni = NanpaDB.getNumberInfo(self.b_lrn)
            if ni:
                self.b_state = ni['state']
                self.b_lata = ni['lata']
                self.b_ocn = ni['ocn']

        if self.a_jtype == 'D':
            ni = NanpaDB.getNumberInfo(self.anum)
            if ni:
                self.a_state = ni['state']
                self.a_lata = ni['lata']
                self.a_ocn = ni['ocn']

        # our business rule: international or different US states, consider interstate, otherwise (unknown jurisdictions) consider it to be intrastate
        self.xstate = 'unknown'
        if btn_used:
            self.xstate = 'unknown'
        elif self.a_jtype == 'U' or self.b_jtype == 'U':
            self.xstate == 'unknown'  # labeled as unknown, but will be billed as intra
        elif self.a_jtype == 'I' and self.b_jtype == 'D':
            self.xstate = 'inter'
        elif self.a_state and self.b_state and self.a_state == self.b_state:
            self.xstate = 'intra'

        # given the customer object, have it compute the call_price for this call.
        self.s_connected_r = customer.calculateRoundedBillingSeconds(
            self.s_connected, cdr=self)
        (self.call_price, self.ptgroup) = customer.computeCallPrice(cdr=self)
Beispiel #4
0
    def finalize(self):

        #print 'finalizing) c_from=%s c_to=%s tag=%s' % (self.c_from, self.c_to, self.tag)

        customer = netcall.getCustomerObject(self.c_from)

        if not customer:
            log.warning("no customer object found for c_from %s.  callid=%s", self.c_from, self.callid)
            log.warning(" --> FIX THIS so opensips always records c_from regardless")
            return
            #sys.exit(-1)

        if self.c_to: # c_to may be null if this all routes were tried and we're returning 480 to client
            terminator = netcall.getTerminatorObject(self.c_to)

        ## compute final times
        if self.t_confirm and self.t_start:
            self.s_setup = int((self.t_confirm - self.t_start).total_seconds())

        if self.t_confirm and self.t_end:
            self.s_connected = int((self.t_end - self.t_confirm).total_seconds())

        if self.t_start and self.t_end:
            self.s_total = int((self.t_end - self.t_start).total_seconds())


        # set anum to btn if needed
        btn_used = False
        self.anum2 = self.anum
        if (not PhoneNumber.isUSdomesticNumber(self.anum) and 
            not PhoneNumber.isInterationalNumber(self.anum)):

            btn_used = True
            log.debug("will use btn for anum %s", self.anum)

            if customer.btn:
                self.anum2 = customer.btn
            else:
                self.anum2 = '?BTN?'



        ## compute jurisdiction info

        # warn if b_lrn isn't set: the routing and LRN logic should always
        # set some value for b_lrn (but occassionally LRN dip fails or doesn't return a mapping)
        if not self.b_lrn:
            self.b_lrn = self.bnum
            log.warning('b_lrn not set. using bnum instead')


        # TODO: clarify what happens when BTN was substituted ...
        # call origination type - domestic or international?
        ed = PhoneNumber.num2codes(self.anum2)
        if ed:
            self.a_country = ed[2]
        # note: isUSdomesticNumber is lax compared to num2codes ... TODO implement logic to decide when to use
        # lax or strict parsing rules -- like in a Carrier subclass, since different carriers may have different
        # policies or can assume certain countries/defaults when numbers are ambiguous
        if PhoneNumber.isUSdomesticNumber(self.anum2): self.a_jtype = 'D'
        elif PhoneNumber.isInterationalNumber(self.anum2): self.a_jtype = 'I'
        else: self.a_jtype = 'U'
        if self.a_jtype == 'D' and self.a_country != 'US':
            log.warning('PhoneNumber num2codes & isUSdomesticNumber returning inconsistent result! lax parsing case? anum2=%s', self.anum2)

        # call destination type - domestic or international? (note: parsing bnum here less reliable than looking at lcr route used?)
        ed = PhoneNumber.num2codes(self.b_lrn)
        if ed:
            self.b_country = ed[2]
        if PhoneNumber.isUSdomesticNumber(self.b_lrn): self.b_jtype = 'D'
        elif PhoneNumber.isInterationalNumber(self.b_lrn): self.b_jtype = 'I'
        else: self.b_jtype = 'U'
        if self.b_jtype == 'D' and self.b_country != 'US':
            log.warning('PhoneNumber num2codes & isUSdomesticNumber returning inconsistent result! lax parsing case? b_lrn=%s', self.b_lrn)


        if self.b_jtype == 'D':
            ni = NanpaDB.getNumberInfo(self.b_lrn)
            if ni:
                self.b_state = ni['state']
                self.b_lata  = ni['lata']
                self.b_ocn   = ni['ocn']

        if self.a_jtype == 'D':
            ni = NanpaDB.getNumberInfo(self.anum)
            if ni:
                self.a_state = ni['state']
                self.a_lata  = ni['lata']
                self.a_ocn   = ni['ocn']


        # our business rule: international or different US states, consider interstate, otherwise (unknown jurisdictions) consider it to be intrastate
        self.xstate = 'unknown'
        if btn_used:
            self.xstate = 'unknown'
        elif self.a_jtype == 'U' or self.b_jtype == 'U':
            self.xstate == 'unknown'   # labeled as unknown, but will be billed as intra 
        elif self.a_jtype == 'I' and self.b_jtype == 'D':
            self.xstate = 'inter'
        elif self.a_state and self.b_state and self.a_state==self.b_state:
            self.xstate = 'intra'


        # given the customer object, have it compute the call_price for this call.
        self.s_connected_r = customer.calculateRoundedBillingSeconds(self.s_connected, cdr=self)
        (self.call_price, self.ptgroup) = customer.computeCallPrice(cdr=self)