Esempio n. 1
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()
Esempio n. 2
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
Esempio n. 3
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)
Esempio n. 4
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
Esempio n. 5
0
 def test_unpack_ucs2_bytes(self):
     self.assertEqual(unpack_ucs2_bytes('0068006F006C0061'), 'hola')
     resp = 'holas'
     self.assertEqual(unpack_ucs2_bytes('0068006F006C00610073'), resp)