def _normPyStr(self, valu): digs = digits(valu) if not digs: raise s_exc.BadTypeValu(valu=valu, name=self.name, mesg='requires a digit string') subs = {} try: info = s_l_phone.getPhoneInfo(int(digs)) except Exception as e: # pragma: no cover raise s_exc.BadTypeValu(valu=valu, name=self.name, mesg='Failed to get phone info') cc = info.get('cc') if cc is not None: subs['loc'] = cc # TODO prefix based validation? return digs, {'subs': subs}
def norm(self, valu, oldval=None): if isinstance(valu, str): valu = int(digits(valu)) subs = {} try: valu = int(valu) info = s_l_phone.getPhoneInfo(valu) cc = info.get('cc') if cc is not None: subs['cc'] = cc # TODO prefix based validation? return valu, subs except TypeError as e: self._raiseBadValu(valu)
def test_lookup_phonenum(self): self.eq(s_l_phone.getPhoneInfo(18075551212)['cc'], 'ca') self.eq(s_l_phone.getPhoneInfo(17035551212)['cc'], 'us')