def replace_number(self, fnumber): temp_adress = self.book[self.key][0] r = dict(self.book) del r[self.key] self.book = r Adress_list2 = temp_adress Phonenumber2 = PhoneNumber(fnumber) self.new_contact_info = [Adress_list2, Phonenumber2] self.book[self.key] = self.new_contact_info
def calculateRoundedBillingSeconds(self, s_connected, cdr=None): r1 = self.billing_spec_r1 r2 = self.billing_spec_r2 if cdr and cdr.bnum: nd = PhoneNumber.num2codes(cdr.bnum) if nd and nd[2] == 'MX': r1 = 1 r2 = 1 return self._calculateRoundedBillingSeconds(s_connected, r1, r2)
def calculateRoundedBillingSeconds(self, s_connected, cdr=None): r1 = self.billing_spec_r1 r2 = self.billing_spec_r2 if cdr and cdr.bnum: nd = PhoneNumber.num2codes(cdr.bnum) if nd and nd[2]=='MX': r1 = 1 r2 = 1 return self._calculateRoundedBillingSeconds(s_connected, r1, r2)
def test_number_init_fail_wrong_country_code(self): with self.assertRaises(ValueError): PN.NorwegianPhoneNumber("004512345678")
def setUp(self): self.number = PN.NorwegianPhoneNumber("004712345678")
def setUp(self): self.number_no_region = PN.SwedishPhoneNumber("004612345678") self.number_with_region = PN.SwedishPhoneNumber("004612312345678")
def setUp(self): self.number = PN.DanishPhoneNumber("004512345678")
try: if len(sys.argv) < 3: raise TypeError("Not enough input arguments") elif len(sys.argv) > 3: raise TypeError("Too many input arguments") except TypeError as err: print err in_file = sys.argv[1] out_file = sys.argv[2] line_number = 0 raw_number = "" # Unnormalized phone_number = { "45": PN.DanishPhoneNumber(), "46": PN.SwedishPhoneNumber(), "47": PN.NorwegianPhoneNumber() } input_file = open(in_file, "r") output_file = open(out_file, "w") # With statement is exited early when using exceptions while True: raw_number = input_file.readline() # End of input_file if not raw_number: input_file.close() output_file.close() break
def add_new_contact(self, street, postcode, city, fnumber): Adress_list = Adress(street, postcode, city) Phonenumber = PhoneNumber(fnumber) self.contact_info = [Adress_list, Phonenumber] self.book[self.key] = self.contact_info
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)
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)