Add some Python2 compat code I forgot to add earlier

This commit is contained in:
NoDRM
2022-07-13 17:31:14 +02:00
parent c12d214b59
commit fed8bb716b
2 changed files with 19 additions and 12 deletions

View File

@@ -4,6 +4,7 @@
#@@CALIBRE_COMPAT_CODE@@
from ignoblekeyGenPassHash import generate_key
import sys
__license__ = 'GPL v3'
@@ -21,8 +22,13 @@ DETAILED_MESSAGE = \
def uStrCmp (s1, s2, caseless=False):
import unicodedata as ud
str1 = s1 if isinstance(s1, str) else str(s1)
str2 = s2 if isinstance(s2, str) else str(s2)
if sys.version_info[0] == 2:
str1 = s1 if isinstance(s1, unicode) else unicode(s1)
str2 = s2 if isinstance(s2, unicode) else unicode(s2)
else:
str1 = s1 if isinstance(s1, str) else str(s1)
str2 = s2 if isinstance(s2, str) else str(s2)
if caseless:
return ud.normalize('NFC', str1.lower()) == ud.normalize('NFC', str2.lower())
else: