summaryrefslogtreecommitdiffstats
path: root/DeDRM_plugin/kfxdedrm.py
diff options
context:
space:
mode:
authorApprentice Harper <[email protected]>2020-09-27 11:54:49 +0100
committerApprentice Harper <[email protected]>2020-09-27 11:54:49 +0100
commitde50a02af92ef2bdd142dfb0bfb8e288ebf3bb67 (patch)
treed6544ffc055553a997020166694142f53a913e08 /DeDRM_plugin/kfxdedrm.py
parent6920f79a263516a566646f3075a3c94e99cf3c37 (diff)
More generic 3.0 changes, to be tested.
Diffstat (limited to 'DeDRM_plugin/kfxdedrm.py')
-rw-r--r--DeDRM_plugin/kfxdedrm.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/DeDRM_plugin/kfxdedrm.py b/DeDRM_plugin/kfxdedrm.py
index d3c0f7e..875c4a1 100644
--- a/DeDRM_plugin/kfxdedrm.py
+++ b/DeDRM_plugin/kfxdedrm.py
@@ -1,12 +1,9 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-from __future__ import with_statement
-from __future__ import print_function
-
# Engine to remove drm from Kindle KFX ebooks
-# 2.0 - Added Python 3 compatibility for calibre 5.0
+# 2.0 - Python 3 for calibre 5.0
import os
@@ -50,13 +47,13 @@ class KFXZipBook:
data += fh.read()
if self.voucher is None:
self.decrypt_voucher(totalpids)
- print(u'Decrypting KFX DRMION: {0}'.format(filename))
+ print("Decrypting KFX DRMION: {0}".format(filename))
outfile = StringIO()
ion.DrmIon(StringIO(data[8:-8]), lambda name: self.voucher).parse(outfile)
self.decrypted[filename] = outfile.getvalue()
if not self.decrypted:
- print(u'The .kfx-zip archive does not contain an encrypted DRMION file')
+ print("The .kfx-zip archive does not contain an encrypted DRMION file")
def decrypt_voucher(self, totalpids):
with zipfile.ZipFile(self.infile, 'r') as zf:
@@ -70,9 +67,9 @@ class KFXZipBook:
if 'ProtectedData' in data:
break # found DRM voucher
else:
- raise Exception(u'The .kfx-zip archive contains an encrypted DRMION file without a DRM voucher')
+ raise Exception("The .kfx-zip archive contains an encrypted DRMION file without a DRM voucher")
- print(u'Decrypting KFX DRM voucher: {0}'.format(info.filename))
+ print("Decrypting KFX DRM voucher: {0}".format(info.filename))
for pid in [''] + totalpids:
for dsn_len,secret_len in [(0,0), (16,0), (16,40), (32,40), (40,0), (40,40)]:
@@ -89,13 +86,13 @@ class KFXZipBook:
except:
pass
else:
- raise Exception(u'Failed to decrypt KFX DRM voucher with any key')
+ raise Exception("Failed to decrypt KFX DRM voucher with any key")
- print(u'KFX DRM voucher successfully decrypted')
+ print("KFX DRM voucher successfully decrypted")
license_type = voucher.getlicensetype()
if license_type != "Purchase":
- raise Exception((u'This book is licensed as {0}. '
+ raise Exception(("This book is licensed as {0}. "
'These tools are intended for use on purchased books.').format(license_type))
self.voucher = voucher