示例#1
0
文件: ericsson.py 项目: achiang/wader
        def get_charsets_cb(charsets):
            ret = []
            for charset in charsets:
                if check_if_ucs2(charset):
                    charset = from_ucs2(charset)
                ret.append(charset)

            return ret
示例#2
0
 def test_check_if_ucs2_limit_extended_latin_b(self):
     self.assertEqual(check_if_ucs2(CTL_0, limit=LATIN_EX_B), True)
     self.assertEqual(check_if_ucs2(CTL_1, limit=LATIN_EX_B), True)
     self.assertEqual(check_if_ucs2(LTN_A, limit=LATIN_EX_B), True)
     self.assertEqual(check_if_ucs2(LTN_B, limit=LATIN_EX_B), True)
     self.assertEqual(check_if_ucs2('6C34', limit=LATIN_EX_B), False)
     self.assertEqual(
         check_if_ucs2(LTN_B + LTN_B + LTN_B, limit=LATIN_EX_B), True)
     self.assertEqual(
         check_if_ucs2('6C34' + LTN_B + LTN_B, limit=LATIN_EX_B), False)
     self.assertEqual(
         check_if_ucs2(LTN_B + '6C34' + LTN_B, limit=LATIN_EX_B), False)
     self.assertEqual(
         check_if_ucs2(LTN_B + LTN_B + '6C34', limit=LATIN_EX_B), False)
示例#3
0
 def test_check_if_ucs2_limit_control_1(self):
     self.assertEqual(check_if_ucs2(CTL_0, limit=CONTROL_1), True)
     self.assertEqual(check_if_ucs2(CTL_1, limit=CONTROL_1), True)
     self.assertEqual(check_if_ucs2(LTN_A, limit=CONTROL_1), False)
     self.assertEqual(check_if_ucs2(LTN_B, limit=CONTROL_1), False)
     self.assertEqual(check_if_ucs2('6C34', limit=CONTROL_1), False)
     self.assertEqual(
         check_if_ucs2(CTL_1 + CTL_1 + CTL_1, limit=CONTROL_1), True)
     self.assertEqual(
         check_if_ucs2('6C34' + CTL_1 + CTL_1, limit=CONTROL_1), False)
     self.assertEqual(
         check_if_ucs2(CTL_1 + '6C34' + CTL_1, limit=CONTROL_1), False)
     self.assertEqual(
         check_if_ucs2(CTL_1 + CTL_1 + '6C34', limit=CONTROL_1), False)
示例#4
0
        def get_smsc_cb(response):
            try:
                smsc = response[0].group('smsc')
                if not smsc.startswith('+'):
                    if check_if_ucs2(smsc):
                        smsc = from_u(unpack_ucs2_bytes(smsc))

                return smsc
            except KeyError:
                raise E.NotFound()
示例#5
0
 def test_check_if_ucs2(self):
     self.assertEqual(check_if_ucs2(CTL_0), True)
     self.assertEqual(check_if_ucs2(CTL_1), True)
     self.assertEqual(check_if_ucs2(LTN_A), True)
     self.assertEqual(check_if_ucs2(LTN_B), True)
     self.assertEqual(check_if_ucs2('6C34'), True)
     self.assertEqual(
         check_if_ucs2('0056006F006400610066006F006E0065'), True)
     self.assertEqual(check_if_ucs2('003'), False)
示例#6
0
        def get_net_info_cb(netinfo):
            """
            Returns a (Networkname, ConnType) tuple

            It returns None if there's no info
            """
            if not netinfo:
                return None

            netinfo = netinfo[0]

            if netinfo.group('error'):
                # this means that we've received a response like
                # +COPS: 0 which means that we don't have network temporaly
                # we should raise an exception here
                raise E.NoNetwork()

            # TS 27007 got updated as of 10.4
            _map = {
                '0': MM_GSM_ACCESS_TECH_GPRS,  # strictly GSM
                '1': MM_GSM_ACCESS_TECH_GSM_COMPAT,
                '2': MM_GSM_ACCESS_TECH_UMTS,  # strictly UTRAN
                '3': MM_GSM_ACCESS_TECH_EDGE,
                '4': MM_GSM_ACCESS_TECH_HSDPA,
                '5': MM_GSM_ACCESS_TECH_HSUPA,
                '6': MM_GSM_ACCESS_TECH_HSPA,
                '7': MM_GSM_ACCESS_TECH_LTE,
            }
            conn_type = _map.get(netinfo.group('status'))

            netname = netinfo.group('netname')
            if netname in ['Limited Service',
                    pack_ucs2_bytes('Limited Service')]:
                raise ex.LimitedServiceNetworkError

            # netname can be in UCS2, as a string, or as a network id (int)
            if check_if_ucs2(netname):
                return unpack_ucs2_bytes(netname), conn_type
            else:
                # now can be either a string or a network id (int)
                try:
                    netname = int(netname)
                except ValueError:
                    # we got a string ID
                    return netname, conn_type

                # if we have arrived here, that means that the network id
                # is a five, six or seven digit integer
                return str(netname), conn_type
示例#7
0
        def convert_response(response):
            index = response[0].group('index')
            if index == '1':
                self.device.set_property(USD_INTFACE, 'State', 'user-response')
            else:
                self.device.set_property(USD_INTFACE, 'State', 'idle')

            resp = response[0].group('resp')
            if resp is None:
                return ""   # returning the Empty string is valid

            if not check_if_ucs2(resp, limit=LATIN_EX_B):
                if 'UCS2' in self.device.sim.charset and \
                        not loose_charset_check:
                    raise E.MalformedUssdPduError(resp)
                else:
                    return resp
            else:
                try:
                    return unpack_ucs2_bytes(resp)
                except (TypeError, UnicodeDecodeError):
                    raise E.MalformedUssdPduError(resp)
示例#8
0
        def get_net_info_cb(netinfo):
            """
            Returns a (Networkname, ConnType) tuple

            It returns None if there's no info
            """
            if not netinfo:
                return None

            netinfo = netinfo[0]

            if netinfo.group('error'):
                # this means that we've received a response like
                # +COPS: 0 which means that we don't have network temporaly
                # we should raise an exception here
                raise E.NoNetwork()

            conn_type = 'GPRS'
            netname = netinfo.group('netname')

            if netname in ['Limited Service',
                           pack_ucs2_bytes('Limited Service')]:
                raise LimitedServiceNetworkError()

            # netname can be in UCS2, as a string, or as a network id (int)
            if check_if_ucs2(netname):
                return unpack_ucs2_bytes(netname), conn_type
            else:
                # now can be either a string or a network id (int)
                try:
                    netname = int(netname)
                except ValueError:
                    # we got a string ID
                    return netname, conn_type

                # if we have arrived here, that means that the network id
                # is a five digit integer
                return str(netname), conn_type