mirror of
https://github.com/apprenticeharper/DeDRM_tools
synced 2024-12-27 09:58:59 +01:00
Add encryption fixes from other scripts (SafeUnbuffered).
This commit is contained in:
parent
488924d443
commit
0d530c0c46
3 changed files with 52 additions and 6 deletions
Binary file not shown.
|
@ -3,6 +3,7 @@
|
|||
|
||||
# Version 3.1.5 September 2015
|
||||
# Removed requirement that a purchase has been made.
|
||||
# Also add in character encoding fixes
|
||||
#
|
||||
# Version 3.1.4 September 2015
|
||||
# Updated for version 3.17 of the Windows Desktop app.
|
||||
|
@ -218,6 +219,24 @@ def _load_crypto():
|
|||
|
||||
AES = _load_crypto()
|
||||
|
||||
# Wrap a stream so that output gets flushed immediately
|
||||
# and also make sure that any unicode strings get
|
||||
# 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,unicode):
|
||||
data = data.encode(self.encoding,"replace")
|
||||
self.stream.write(data)
|
||||
self.stream.flush()
|
||||
def __getattr__(self, attr):
|
||||
return getattr(self.stream, attr)
|
||||
|
||||
|
||||
class KoboLibrary(object):
|
||||
"""The Kobo library.
|
||||
|
||||
|
@ -463,8 +482,7 @@ class KoboFile(object):
|
|||
contents = contents[:-padding]
|
||||
return contents
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
def cli_main():
|
||||
lib = KoboLibrary()
|
||||
|
||||
for i, book in enumerate(lib.books):
|
||||
|
@ -515,4 +533,9 @@ if __name__ == '__main__':
|
|||
|
||||
zin.close()
|
||||
lib.close()
|
||||
exit(result)
|
||||
return result
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.stdout=SafeUnbuffered(sys.stdout)
|
||||
sys.stderr=SafeUnbuffered(sys.stderr)
|
||||
sys.exit(cli_main())
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
# Version 3.1.5 September 2015
|
||||
# Removed requirement that a purchase has been made.
|
||||
# Also add in character encoding fixes
|
||||
#
|
||||
# Version 3.1.4 September 2015
|
||||
# Updated for version 3.17 of the Windows Desktop app.
|
||||
|
@ -218,6 +219,24 @@ def _load_crypto():
|
|||
|
||||
AES = _load_crypto()
|
||||
|
||||
# Wrap a stream so that output gets flushed immediately
|
||||
# and also make sure that any unicode strings get
|
||||
# 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,unicode):
|
||||
data = data.encode(self.encoding,"replace")
|
||||
self.stream.write(data)
|
||||
self.stream.flush()
|
||||
def __getattr__(self, attr):
|
||||
return getattr(self.stream, attr)
|
||||
|
||||
|
||||
class KoboLibrary(object):
|
||||
"""The Kobo library.
|
||||
|
||||
|
@ -463,8 +482,7 @@ class KoboFile(object):
|
|||
contents = contents[:-padding]
|
||||
return contents
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
def cli_main():
|
||||
lib = KoboLibrary()
|
||||
|
||||
for i, book in enumerate(lib.books):
|
||||
|
@ -515,4 +533,9 @@ if __name__ == '__main__':
|
|||
|
||||
zin.close()
|
||||
lib.close()
|
||||
exit(result)
|
||||
return result
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.stdout=SafeUnbuffered(sys.stdout)
|
||||
sys.stderr=SafeUnbuffered(sys.stderr)
|
||||
sys.exit(cli_main())
|
||||
|
|
Loading…
Reference in a new issue