More Python2 fixes

This commit is contained in:
NoDRM 2023-08-03 20:45:06 +02:00
parent d388ae72fd
commit 53996cf49c
14 changed files with 44 additions and 41 deletions

View File

@ -15,6 +15,6 @@ if "calibre" in sys.modules and sys.version_info[0] == 2:
sys.path.insert(0, os.path.join(config_dir, "plugins", "DeDRM.zip"))
# Explicitly set the package identifier so we are allowed to import stuff ...
#__package__ = "DeDRM_plugin"
__package__ = "calibre_plugins.dedrm"
#@@CALIBRE_COMPAT_CODE_END@@

View File

@ -46,8 +46,8 @@ from base64 import b64decode
from utilities import SafeUnbuffered
from argv_utils import unicode_argv
from .utilities import SafeUnbuffered
from .argv_utils import unicode_argv
try:

View File

@ -29,7 +29,7 @@ from calibre.constants import iswindows, isosx
from __init__ import PLUGIN_NAME, PLUGIN_VERSION
from __version import RESOURCE_NAME as help_file_name
from utilities import uStrCmp
from .utilities import uStrCmp
import prefs
import androidkindlekey

View File

@ -53,12 +53,12 @@ import sys, struct, os, traceback
import zlib
import zipfile
import xml.etree.ElementTree as etree
from argv_utils import unicode_argv
from .argv_utils import unicode_argv
NSMAP = {'adept': 'http://ns.adobe.com/adept',
'enc': 'http://www.w3.org/2001/04/xmlenc#'}
from utilities import SafeUnbuffered
from .utilities import SafeUnbuffered
_FILENAME_LEN_OFFSET = 26

View File

@ -79,11 +79,8 @@ except ImportError:
#@@CALIBRE_COMPAT_CODE@@
try:
from utilities import SafeUnbuffered
from argv_utils import unicode_argv
except:
from . import utilities, argv_utils
from .utilities import SafeUnbuffered
from .argv_utils import unicode_argv
iswindows = sys.platform.startswith('win')
isosx = sys.platform.startswith('darwin')

View File

@ -50,9 +50,9 @@ try:
except ImportError:
from Crypto.Cipher import AES
from utilities import SafeUnbuffered
from .utilities import SafeUnbuffered
from argv_utils import unicode_argv
from .argv_utils import unicode_argv
class IGNOBLEError(Exception):
pass

View File

@ -27,14 +27,14 @@ import hashlib
import getopt
import re
from utilities import SafeUnbuffered
from .utilities import SafeUnbuffered
try:
from calibre.constants import iswindows
except:
iswindows = sys.platform.startswith('win')
from argv_utils import unicode_argv
from .argv_utils import unicode_argv
class DrmException(Exception):
pass

View File

@ -70,9 +70,8 @@ def unpad(data, padding=16):
return data[:-pad_len]
from utilities import SafeUnbuffered
from argv_utils import unicode_argv
from .utilities import SafeUnbuffered
from .argv_utils import unicode_argv
class ADEPTError(Exception):

View File

@ -93,12 +93,12 @@ def unpad(data, padding=16):
return data[:-pad_len]
from utilities import SafeUnbuffered
from .utilities import SafeUnbuffered
iswindows = sys.platform.startswith('win')
isosx = sys.platform.startswith('darwin')
from argv_utils import unicode_argv
from .argv_utils import unicode_argv
class ADEPTError(Exception):
pass

View File

@ -88,9 +88,9 @@ import kgenpids
import androidkindlekey
import kfxdedrm
from utilities import SafeUnbuffered
from .utilities import SafeUnbuffered
from argv_utils import unicode_argv
from .argv_utils import unicode_argv
# cleanup unicode filenames

View File

@ -62,11 +62,8 @@ except NameError:
# Routines common to Mac and PC
try:
from utilities import SafeUnbuffered
from argv_utils import unicode_argv
except:
from . import utilities, argv_utils
from .utilities import SafeUnbuffered
from .argv_utils import unicode_argv
try:

View File

@ -16,17 +16,17 @@
import sys
import binascii
from utilities import SafeUnbuffered
from .utilities import SafeUnbuffered
from argv_utils import unicode_argv
from .argv_utils import unicode_argv
letters = 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789'
letters = b'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789'
def crc32(s):
return (~binascii.crc32(s,-1))&0xFFFFFFFF
def checksumPid(s):
crc = crc32(s.encode('ascii'))
crc = crc32(s)
crc = crc ^ (crc >> 16)
res = s
l = len(letters)

View File

@ -80,11 +80,14 @@ import sys
import os
import struct
import binascii
from alfcrypto import Pukall_Cipher
from utilities import SafeUnbuffered
from argv_utils import unicode_argv
#@@CALIBRE_COMPAT_CODE@@
from .alfcrypto import Pukall_Cipher
from .utilities import SafeUnbuffered
from .argv_utils import unicode_argv
class DrmException(Exception):
@ -103,10 +106,17 @@ def PC1(key, src, decryption=True):
except:
raise
# accepts unicode returns unicode
letters = b'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789'
def crc32(s):
return (~binascii.crc32(s,-1))&0xFFFFFFFF
def checksumPid(s):
letters = 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789'
crc = (~binascii.crc32(s.encode('utf-8'),-1))&0xFFFFFFFF
s = s.encode()
crc = crc32(s)
crc = crc ^ (crc >> 16)
res = s
l = len(letters)
@ -115,7 +125,7 @@ def checksumPid(s):
pos = (b // l) ^ (b % l)
res += bytes(bytearray([letters[pos%l]]))
crc >>= 8
return res
return res.decode()
# expects bytearray
def getSizeOfTrailingDataEntries(ptr, size, flags):

View File

@ -24,10 +24,10 @@ import traceback
from struct import pack
from struct import unpack
from alfcrypto import Topaz_Cipher
from utilities import SafeUnbuffered
from .alfcrypto import Topaz_Cipher
from .utilities import SafeUnbuffered
from argv_utils import unicode_argv
from .argv_utils import unicode_argv
#global switch