Exemple #1
0
    def _regexp_to_contact(self, match):
        """
        I process a contact match and return a `Contact` object out of it
        """
        if int(match.group('raw')) == 0:
            # some buggy firmware appends this
            name = match.group('name').rstrip('\xff')
        else:
            encoding = match.group('name')[:2]
            hexbytes = match.group('name')[2:]
            if encoding != '82':
                # E220 pads  '534E4E3AFFFFFFFFFFFFFFFFFF'
                # K2540 pads '534E4E3AFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
                #            'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
                significant = hexbytes.find('FF')
                if significant != -1:
                    hexbytes = hexbytes[:significant + 2]

            if encoding == '80':   # example '80058300440586FF'
                name = unpack_ucs2_bytes_in_ts31101_80(hexbytes)
            elif encoding == '81':  # example '810602A46563746F72FF'
                name = unpack_ucs2_bytes_in_ts31101_81(hexbytes)
            elif encoding == '82':  # example '820505302D82D32D31'
                name = unpack_ucs2_bytes_in_ts31101_82(hexbytes)
            else:
                name = "Unsupported encoding"

        number = match.group('number')
        index = int(match.group('id'))

        return Contact(name, number, index=index)
Exemple #2
0
    def test_unpack_ucs2_bytes_in_ts31101_81(self):
        # From our original Huawei contacts code
        self.assertEqual(
            unpack_ucs2_bytes_in_ts31101_81('0602A46563746F72FF'), u'Ĥector')

        # From Android code
        self.assertEqual(
            unpack_ucs2_bytes_in_ts31101_81('0A01566FEC6365204DE0696CFFFFFF'),
                                            u'Vo\u00ECce M\u00E0il')
        # From TS102221
        # Byte 4 indicates GSM Default Alphabet character '53', i.e. 'S'.
        # Byte 5 indicates a UCS2 character offset to the base pointer of '15',
        #           expressed in binary as follows 001 0101, which, when added
        #           to the base pointer value results in a sixteen bit value of
        #           0000 1001 1001 0101, i.e. '0995', which is the Bengali
        #           letter KA.
        # Byte 6 / 7 were not defined in TS102221 example, so just repeated 5
        # Byte 8 contains the value 'FF', but as the string length is 5, this
        #           is a valid character in the string, where the bit pattern
        #           111 1111 is added to the base pointer, yielding a sixteen
        #           bit value of 0000 1001 1111 1111 for the UCS2 character
        #           (i.e. '09FF').
        self.assertEqual(
            unpack_ucs2_bytes_in_ts31101_81('051353959595FFFF'), u'Sককক\u09FF')