Merge pull request #1255 from cclauss/patch-2

GitHub Action test on both Python 2 and Python 3
This commit is contained in:
Apprentice Harper 2020-09-30 11:45:50 +01:00 committed by GitHub
commit 21d4811bfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 21 deletions

View File

@ -7,7 +7,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
os: [macos-latest] os: [macos-latest]
python-version: [2.7] # , 3.8] python-version: [2.7, 3.8]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }} - name: Set up Python ${{ matrix.python-version }}

View File

@ -516,7 +516,7 @@ def decryptBook(infile, outpath, make_pmlz, user_key):
# remove temporary directory # remove temporary directory
shutil.rmtree(outdir, True) shutil.rmtree(outdir, True)
print("Output is {0}".format(pmlzname)) print("Output is {0}".format(pmlzname))
else else:
print("Output is in {0}".format(outdir)) print("Output is in {0}".format(outdir))
print("done") print("done")
except ValueError as e: except ValueError as e:

View File

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab # vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab
# Python 3 for calibre 5.0 # Python 3 for calibre 5.0
from __future__ import print_function
class Unbuffered: class Unbuffered:
def __init__(self, stream): def __init__(self, stream):
@ -92,7 +93,7 @@ def getMetaArray(metaFile):
tag = readString(fo) tag = readString(fo)
value = readString(fo) value = readString(fo)
result[tag] = value result[tag] = value
# print tag, value # print(tag, value)
fo.close() fo.close()
return result return result

View File

@ -19,6 +19,7 @@
""" """
Decrypts Barnes & Noble encrypted PDF files. Decrypts Barnes & Noble encrypted PDF files.
""" """
from __future__ import print_function
__license__ = 'GPL v3' __license__ = 'GPL v3'
__version__ = "0.1" __version__ = "0.1"
@ -428,7 +429,7 @@ class PSBaseParser(object):
if not pos: if not pos:
pos = self.bufpos+self.charpos pos = self.bufpos+self.charpos
self.fp.seek(pos) self.fp.seek(pos)
##print >>sys.stderr, 'poll(%d): %r' % (pos, self.fp.read(n)) # print('poll(%d): %r' % (pos, self.fp.read(n)), file=sys.stderr)
self.fp.seek(pos0) self.fp.seek(pos0)
return return
@ -753,7 +754,7 @@ class PSStackParser(PSBaseParser):
''' '''
while not self.results: while not self.results:
(pos, token) = self.nexttoken() (pos, token) = self.nexttoken()
##print (pos,token), (self.curtype, self.curstack) # print((pos, token), (self.curtype, self.curstack))
if (isinstance(token, int) or if (isinstance(token, int) or
isinstance(token, Decimal) or isinstance(token, Decimal) or
isinstance(token, bool) or isinstance(token, bool) or
@ -778,7 +779,7 @@ class PSStackParser(PSBaseParser):
try: try:
(pos, objs) = self.end_type('d') (pos, objs) = self.end_type('d')
if len(objs) % 2 != 0: if len(objs) % 2 != 0:
print "Incomplete dictionary construct" print("Incomplete dictionary construct")
objs.append("") # this isn't necessary. objs.append("") # this isn't necessary.
# temporary fix. is this due to rental books? # temporary fix. is this due to rental books?
# raise PSSyntaxError( # raise PSSyntaxError(
@ -1003,7 +1004,7 @@ class PDFStream(PDFObject):
if 'Filter' not in self.dic: if 'Filter' not in self.dic:
self.data = data self.data = data
self.rawdata = None self.rawdata = None
##print self.dict ##print(self.dict)
return return
filters = self.dic['Filter'] filters = self.dic['Filter']
if not isinstance(filters, list): if not isinstance(filters, list):
@ -1447,15 +1448,15 @@ class PDFDocument(object):
V = ord(bookkey[0]) V = ord(bookkey[0])
bookkey = bookkey[1:] bookkey = bookkey[1:]
else: else:
print "ebx_V is %d and ebx_type is %d" % (ebx_V, ebx_type) print("ebx_V is %d and ebx_type is %d" % (ebx_V, ebx_type))
print "length is %d and len(bookkey) is %d" % (length, len(bookkey)) print("length is %d and len(bookkey) is %d" % (length, len(bookkey)))
print "bookkey[0] is %d" % ord(bookkey[0]) print("bookkey[0] is %d" % ord(bookkey[0]))
raise IGNOBLEError('error decrypting book session key - mismatched length') raise IGNOBLEError('error decrypting book session key - mismatched length')
else: else:
# proper length unknown try with whatever you have # proper length unknown try with whatever you have
print "ebx_V is %d and ebx_type is %d" % (ebx_V, ebx_type) print("ebx_V is %d and ebx_type is %d" % (ebx_V, ebx_type))
print "length is %d and len(bookkey) is %d" % (length, len(bookkey)) print("length is %d and len(bookkey) is %d" % (length, len(bookkey)))
print "bookkey[0] is %d" % ord(bookkey[0]) print("bookkey[0] is %d" % ord(bookkey[0]))
if ebx_V == 3: if ebx_V == 3:
V = 3 V = 3
else: else:
@ -1500,7 +1501,7 @@ class PDFDocument(object):
plaintext = AES.new(key,AES.MODE_CBC,ivector).decrypt(data) plaintext = AES.new(key,AES.MODE_CBC,ivector).decrypt(data)
# remove pkcs#5 aes padding # remove pkcs#5 aes padding
cutter = -1 * ord(plaintext[-1]) cutter = -1 * ord(plaintext[-1])
#print cutter #print(cutter)
plaintext = plaintext[:cutter] plaintext = plaintext[:cutter]
return plaintext return plaintext
@ -1511,7 +1512,7 @@ class PDFDocument(object):
plaintext = AES.new(key,AES.MODE_CBC,ivector).decrypt(data) plaintext = AES.new(key,AES.MODE_CBC,ivector).decrypt(data)
# remove pkcs#5 aes padding # remove pkcs#5 aes padding
cutter = -1 * ord(plaintext[-1]) cutter = -1 * ord(plaintext[-1])
#print cutter #print(cutter)
plaintext = plaintext[:cutter] plaintext = plaintext[:cutter]
return plaintext return plaintext
@ -2010,15 +2011,15 @@ def decryptBook(userkey, inpath, outpath):
#try: #try:
serializer = PDFSerializer(inf, userkey) serializer = PDFSerializer(inf, userkey)
#except: #except:
# print "Error serializing pdf {0}. Probably wrong key.".format(os.path.basename(inpath)) # print("Error serializing pdf {0}. Probably wrong key.".format(os.path.basename(inpath)))
# return 2 # return 2
# hope this will fix the 'bad file descriptor' problem # hope this will fix the 'bad file descriptor' problem
with open(outpath, 'wb') as outf: with open(outpath, 'wb') as outf:
# help construct to make sure the method runs to the end # help construct to make sure the method runs to the end
try: try:
serializer.dump(outf) serializer.dump(outf)
except Exception, e: except Exception as e:
print "error writing pdf: {0}".format(e.args[0]) print("error writing pdf: {0}".format(e.args[0]))
return 2 return 2
return 0 return 0
@ -2029,13 +2030,13 @@ def cli_main():
argv=unicode_argv() argv=unicode_argv()
progname = os.path.basename(argv[0]) progname = os.path.basename(argv[0])
if len(argv) != 4: if len(argv) != 4:
print "usage: {0} <keyfile.b64> <inbook.pdf> <outbook.pdf>".format(progname) print("usage: {0} <keyfile.b64> <inbook.pdf> <outbook.pdf>".format(progname))
return 1 return 1
keypath, inpath, outpath = argv[1:] keypath, inpath, outpath = argv[1:]
userkey = open(keypath,'rb').read() userkey = open(keypath,'rb').read()
result = decryptBook(userkey, inpath, outpath) result = decryptBook(userkey, inpath, outpath)
if result == 0: if result == 0:
print "Successfully decrypted {0:s} as {1:s}".format(os.path.basename(inpath),os.path.basename(outpath)) print("Successfully decrypted {0:s} as {1:s}".format(os.path.basename(inpath),os.path.basename(outpath)))
return result return result
@ -2137,7 +2138,7 @@ def gui_main():
self.status['text'] = "Decrypting..." self.status['text'] = "Decrypting..."
try: try:
decrypt_status = decryptBook(userkey, inpath, outpath) decrypt_status = decryptBook(userkey, inpath, outpath)
except Exception, e: except Exception as e:
self.status['text'] = "Error; {0}".format(e.args[0]) self.status['text'] = "Error; {0}".format(e.args[0])
return return
if decrypt_status == 0: if decrypt_status == 0: