示例#1
0
文件: huawei.py 项目: crass/wader
    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)
示例#2
0
 def test_unpack_ucs2_bytes_in_ts31101_82(self):
     # From TS102221
     self.assertEqual(
         unpack_ucs2_bytes_in_ts31101_82('0505302D82D32D31'),u'-Բփ-1')