]> xmof Git - DeDRM.git/commitdiff
Add encryption fixes from other scripts (SafeUnbuffered).
authorapprenticeharper <apprenticeharper@gmail.com>
Mon, 7 Sep 2015 07:11:18 +0000 (08:11 +0100)
committerapprenticeharper <apprenticeharper@gmail.com>
Mon, 7 Sep 2015 07:12:45 +0000 (08:12 +0100)
Obok_calibre_plugin/obok_plugin.zip
Obok_calibre_plugin/obok_plugin/obok/obok.py
Other_Tools/Kobo/obok.py

index 8c22732032e6d313a1ab224d2ee92e6017721f32..144ad0e8d130a67ba4498de81a8407afbd145599 100644 (file)
Binary files a/Obok_calibre_plugin/obok_plugin.zip and b/Obok_calibre_plugin/obok_plugin.zip differ
index 1e93c0e5e7a68fb0a86cab796a2202f6260ed599..d619a26ae53af02bb11ac39674e115c4b2cb08d4 100644 (file)
@@ -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())
index 1e93c0e5e7a68fb0a86cab796a2202f6260ed599..d619a26ae53af02bb11ac39674e115c4b2cb08d4 100644 (file)
@@ -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())