mirror of
https://github.com/Leseratte10/acsm-calibre-plugin.git
synced 2024-12-23 01:34:36 +06:00
Update PDF code for Python2
This commit is contained in:
parent
6d72506fad
commit
05a302424c
@ -17,6 +17,7 @@ popd
|
|||||||
|
|
||||||
# Delete cache
|
# Delete cache
|
||||||
rm -r __pycache__
|
rm -r __pycache__
|
||||||
|
rm *.pyc
|
||||||
|
|
||||||
# Set module ID. This needs to be changed if any of the module ZIPs change.
|
# Set module ID. This needs to be changed if any of the module ZIPs change.
|
||||||
echo -n "2021-12-19-03" > module_id.txt
|
echo -n "2021-12-19-03" > module_id.txt
|
||||||
|
@ -392,6 +392,8 @@ def encrypt_with_device_key(data):
|
|||||||
for _ in range(remain):
|
for _ in range(remain):
|
||||||
data.append(remain)
|
data.append(remain)
|
||||||
|
|
||||||
|
data = bytes(data)
|
||||||
|
|
||||||
|
|
||||||
iv = Random.get_random_bytes(16)
|
iv = Random.get_random_bytes(16)
|
||||||
cip = AES.new(devkey_bytes, AES.MODE_CBC, iv)
|
cip = AES.new(devkey_bytes, AES.MODE_CBC, iv)
|
||||||
|
@ -1,25 +1,37 @@
|
|||||||
import os, zlib, base64, time
|
import sys, os, zlib, base64, time
|
||||||
|
|
||||||
class BackwardReader:
|
class BackwardReader:
|
||||||
|
|
||||||
def __init__(self, file):
|
def __init__(self, file):
|
||||||
self.file = file
|
self.file = file
|
||||||
|
|
||||||
|
|
||||||
def readlines(self):
|
def readlines(self):
|
||||||
BLKSIZE = 4096
|
BLKSIZE = 4096
|
||||||
# Move reader to the end of file
|
# Move reader to the end of file
|
||||||
self.file.seek(0, os.SEEK_END)
|
self.file.seek(0, os.SEEK_END)
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
buffer = bytearray()
|
buffer = bytearray()
|
||||||
|
else:
|
||||||
|
buffer = ""
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
pos_newline = buffer.rfind(bytes([0x0a]))
|
pos_newline = buffer.rfind(bytes([0x0a]))
|
||||||
|
else:
|
||||||
|
pos_newline = buffer.rfind("\n")
|
||||||
|
|
||||||
# Get the current position of the reader
|
# Get the current position of the reader
|
||||||
current_pos = self.file.tell()
|
current_pos = self.file.tell()
|
||||||
if pos_newline != -1:
|
if pos_newline != -1:
|
||||||
# Newline is found
|
# Newline is found
|
||||||
line = buffer[pos_newline+1:]
|
line = buffer[pos_newline+1:]
|
||||||
buffer = buffer[:pos_newline]
|
buffer = buffer[:pos_newline]
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
yield line.decode("latin-1")
|
yield line.decode("latin-1")
|
||||||
|
else:
|
||||||
|
yield line
|
||||||
|
|
||||||
elif current_pos:
|
elif current_pos:
|
||||||
# Need to fill the buffer
|
# Need to fill the buffer
|
||||||
to_read = min(BLKSIZE, current_pos)
|
to_read = min(BLKSIZE, current_pos)
|
||||||
@ -27,13 +39,17 @@ class BackwardReader:
|
|||||||
buffer = self.file.read(to_read) + buffer
|
buffer = self.file.read(to_read) + buffer
|
||||||
self.file.seek(current_pos-to_read, 0)
|
self.file.seek(current_pos-to_read, 0)
|
||||||
if current_pos is to_read:
|
if current_pos is to_read:
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
buffer = bytes([0x0a]) + buffer
|
buffer = bytes([0x0a]) + buffer
|
||||||
|
else:
|
||||||
|
buffer = "\n" + buffer
|
||||||
else:
|
else:
|
||||||
# Start of file
|
# Start of file
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def trim_encrypt_string(encrypt):
|
def trim_encrypt_string(encrypt):
|
||||||
|
|
||||||
string_list = list(encrypt)
|
string_list = list(encrypt)
|
||||||
|
Loading…
Reference in New Issue
Block a user