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()
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
def process_contact_match(match): """I process a contact match and return a C{Contact} object out of it""" from vmc.common.persistent import Contact _name = match.group('name') if check_if_ucs2(_name): name = from_ucs2(_name) else: name = _name.decode('utf8','ignore').rstrip('\x1f') number = from_ucs2(match.group('number')) index = int(match.group('id')) return Contact(name, number, index=index)
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
def set_charset(self, charset): if check_if_ucs2(charset): self.charset = unpack_ucs2_bytes(charset) else: self.charset = charset return charset
def test_check_if_ucs2(self): self.assertEqual(check_if_ucs2('00'), False) self.assertEqual(check_if_ucs2('mañico'), False) self.assertEqual(check_if_ucs2('0056006F006400610066006F006E0065'), True) self.assertEqual(check_if_ucs2('1234'), False)