Esempio n. 1
0
def operator_code_to_full_name(code):
    import mobile_codes
    import re

    h = HTMLParser.HTMLParser()

    a = re.compile("^\d{5,}")
    if not code or not a.match(code):
        return code
    mcc = code[:3]
    mnc = code[3:]
    try:
        op = mobile_codes.mcc_mnc(mcc, mnc)
        cn = mobile_codes.mcc(mcc)
        try:
            return u"{0} ({1}) - {2}".format(h.unescape(op.operator), mnc,
                                             cn[0].name)
        except AttributeError:
            return u"{0} ({1}) - {2}".format(h.unescape(op.operator), mnc,
                                             cn[0])
    except KeyError:
        try:
            cn = mobile_codes.mcc(mcc)
        except KeyError:
            return u"Unknown ({0}/{1})".format(mcc, mnc)
        try:
            return u"{0} unknown ({1}/{2})".format(cn.name, mcc, mnc)
        except AttributeError:
            return u"Unknown ({0}/{1})".format(mcc, mnc)
Esempio n. 2
0
def operator_code_to_full_name(code):
    import mobile_codes
    import re

    h = HTMLParser.HTMLParser()

    a = re.compile("^\d{5,}")
    if not code or not a.match(code):
        return code
    mcc = code[:3]
    mnc = code[3:]
    try:
        op = mobile_codes.mcc_mnc(mcc, mnc)
        cn = mobile_codes.mcc(mcc)
        try:
            return u"{0} ({1}) - {2}".format(h.unescape(op.operator), mnc, cn[0].name)
        except AttributeError:
            return u"{0} ({1}) - {2}".format(h.unescape(op.operator), mnc, cn[0])
    except KeyError:
        try:
            cn = mobile_codes.mcc(mcc)
        except KeyError:
            return u"Unknown ({0}/{1})".format(mcc, mnc)
        try:
            return u"{0} unknown ({1}/{2})".format(cn.name, mcc, mnc)
        except AttributeError:
            return u"Unknown ({0}/{1})".format(mcc, mnc)
Esempio n. 3
0
 def test_mcc_mnc(self):
     operator = mobile_codes.mcc_mnc(u'722', '070')
     self.assertEqual(operator.mcc, u'722')
     self.assertEqual(operator.mnc, u'070')
Esempio n. 4
0
 def lookup_mcc_mnc(mcc, mnc):
     return mcc_mnc(mcc, mnc)
Esempio n. 5
0
 def test_mcc_mnc_fail(self):
     with pytest.raises(KeyError):
         mobile_codes.mcc_mnc("000", "001")
Esempio n. 6
0
 def test_mcc_mnc(self):
     operator = mobile_codes.mcc_mnc("722", "070")
     assert operator.mcc == "722"
     assert operator.mnc == "070"
Esempio n. 7
0
 def test_mcc_mnc(self):
     operator = mobile_codes.mcc_mnc(u'722', '070')
     self.assertEqual(operator.mcc, u'722')
     self.assertEqual(operator.mnc, u'070')