The logic of sms_counter.main.SMSCounter#_detect_encoding was fixed for compatibility with origin library https://github.com/danxexe/sms-counter

This commit is contained in:
Alexander Uralov 2018-12-25 18:15:00 +03:00
parent 06484ea664
commit 54f3daaa68
1 changed files with 8 additions and 10 deletions

View File

@ -1,8 +1,8 @@
# -*- coding: utf8 -*- # -*- coding: utf8 -*-
''' """
Created on Jul 10, 2016 Created on Jul 10, 2016
@author: Dayo @author: Dayo
''' """
from math import ceil from math import ceil
@ -45,17 +45,15 @@ class SMSCounter(object):
def _detect_encoding(cls, plaintext): def _detect_encoding(cls, plaintext):
rf = cls._text_to_unicode_pointcode_list(plaintext) rf = cls._text_to_unicode_pointcode_list(plaintext)
utf16chars = set(rf).difference(set(cls._get_gsm_7bit_map())) non_gsm_7bit_chars = set(rf) - set(cls._get_gsm_7bit_map())
if not non_gsm_7bit_chars:
return cls.GSM_7BIT
if len(utf16chars): non_gsm_7bit_ex_chars = non_gsm_7bit_chars - set(cls._get_added_gsm_7bit_ex_map())
return cls.UTF16 if not non_gsm_7bit_ex_chars:
exchars = set(rf).intersection(set(cls._get_added_gsm_7bit_ex_map()))
if len(exchars):
return cls.GSM_7BIT_EX return cls.GSM_7BIT_EX
return cls.GSM_7BIT return cls.UTF16
@classmethod @classmethod
def count(cls, plaintext): def count(cls, plaintext):