Example #1
0
        def get_net_info_cb(netinfo):
            """
            Returns a (Networname, 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 ex.NetworkTemporalyUnavailableError

            try:
                status = int(netinfo.group('status'))
                conn_type = (status == 0) and 'GPRS' or '3G'
            except IndexError:
                conn_type = 'GPRS'
                
            netname = netinfo.group('netname')
            
            if netname in ['Limited Service',
                           pack_ucs2_bytes('Limited Service')]:
                return netname, conn_type
            
            # 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
                if not process:
                    return netname, conn_type
                
                # we got a numeric id, lets convert it
                from vmc.common.persistent import net_manager
                network = net_manager.get_network_by_id(netname)
                if network:
                    return network.get_name(), conn_type
# ajb: make consistent display between network returned via id or name
                #    return network.get_full_name(), conn_type
                
                return _('Unknown Network'), conn_type
Example #2
0
 def get_smsc_cb(response):
     try:
         smsc = response[0].group('smsc')
         if not smsc.startswith('+'):
             if check_if_ucs2(smsc):
                 # the smsc is in UCS2 format
                 smsc = from_u(unpack_ucs2_bytes(smsc))
 
         return smsc
     except KeyError, e:
         raise ex.CMEErrorNotFound()
Example #3
0
        def translate_from_ucs2(arg):
#            arg[0] = '00470053004D'
#            arg[1] = '004900520041'
#            arg[2] = '0038003800350039002D0031'
#            arg[3] = '005500540046002D0038'
#            arg[4] = '0055004300530032'

            if not check_if_ucs2(arg[0]):
                return arg

            cvt = []              # assume all strings are UCS2 and convert
            for p in arg:
                cvt.append(unpack_ucs2_bytes(p))
            return cvt
Example #4
0
 def set_charset(self, charset):
     if check_if_ucs2(charset):
         self.charset = unpack_ucs2_bytes(charset)
     else:
         self.charset = charset
     return charset
 def set_charset(self, charset):
     if check_if_ucs2(charset):
         self.charset = unpack_ucs2_bytes(charset)
     else:
         self.charset = charset
     return charset
 def test_unpack_ucs2_bytes(self):
     self.assertEqual(unpack_ucs2_bytes('0068006F006C0061'), 'hola')
     resp = 'holas'
     self.assertEqual(unpack_ucs2_bytes('0068006F006C00610073'), resp)