2020-09-27 16:54:49 +06:00
|
|
|
#!/usr/bin/env python3
|
2012-12-19 19:48:11 +06:00
|
|
|
# -*- coding: utf-8 -*-
|
2010-11-12 04:11:36 +06:00
|
|
|
|
2021-12-29 16:36:59 +06:00
|
|
|
#@@CALIBRE_COMPAT_CODE@@
|
2021-12-29 14:26:29 +06:00
|
|
|
|
|
|
|
from ignoblekeyGenPassHash import generate_key
|
2022-07-13 21:31:14 +06:00
|
|
|
import sys
|
2020-01-20 20:17:06 +06:00
|
|
|
|
2013-10-03 00:59:40 +06:00
|
|
|
__license__ = 'GPL v3'
|
|
|
|
|
|
|
|
def uStrCmp (s1, s2, caseless=False):
|
|
|
|
import unicodedata as ud
|
2022-07-13 21:31:14 +06:00
|
|
|
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)
|
|
|
|
|
2013-10-03 00:59:40 +06:00
|
|
|
if caseless:
|
|
|
|
return ud.normalize('NFC', str1.lower()) == ud.normalize('NFC', str2.lower())
|
2013-01-19 20:50:57 +06:00
|
|
|
else:
|
2013-10-03 00:59:40 +06:00
|
|
|
return ud.normalize('NFC', str1) == ud.normalize('NFC', str2)
|
2013-01-19 20:50:57 +06:00
|
|
|
|
2013-10-03 00:59:40 +06:00
|
|
|
def parseCustString(keystuff):
|
|
|
|
userkeys = []
|
|
|
|
ar = keystuff.split(':')
|
|
|
|
for i in ar:
|
2013-01-19 20:50:57 +06:00
|
|
|
try:
|
2013-10-03 00:59:40 +06:00
|
|
|
name, ccn = i.split(',')
|
|
|
|
# Generate Barnes & Noble EPUB user key from name and credit card number.
|
|
|
|
userkeys.append(generate_key(name, ccn))
|
2013-01-19 20:50:57 +06:00
|
|
|
except:
|
|
|
|
pass
|
2013-10-03 00:59:40 +06:00
|
|
|
return userkeys
|
2022-08-07 00:09:30 +06:00
|
|
|
|
|
|
|
|
|
|
|
# Wrap a stream so that output gets flushed immediately
|
|
|
|
# and also make sure that any unicode strings get safely
|
|
|
|
# encoded using "replace" before writing them.
|
|
|
|
class SafeUnbuffered:
|
|
|
|
def __init__(self, stream):
|
|
|
|
self.stream = stream
|
|
|
|
self.encoding = stream.encoding
|
|
|
|
if self.encoding == None:
|
|
|
|
self.encoding = "utf-8"
|
|
|
|
def write(self, data):
|
|
|
|
if isinstance(data,str) or isinstance(data,unicode):
|
|
|
|
# str for Python3, unicode for Python2
|
|
|
|
data = data.encode(self.encoding,"replace")
|
|
|
|
try:
|
|
|
|
buffer = getattr(self.stream, 'buffer', self.stream)
|
|
|
|
# self.stream.buffer for Python3, self.stream for Python2
|
|
|
|
buffer.write(data)
|
|
|
|
buffer.flush()
|
|
|
|
except:
|
|
|
|
# We can do nothing if a write fails
|
|
|
|
raise
|
|
|
|
def __getattr__(self, attr):
|
|
|
|
return getattr(self.stream, attr)
|
|
|
|
|