mirror of
https://github.com/noDRM/DeDRM_tools.git
synced 2024-12-28 12:07:39 +06:00
Move SafeUnbuffered to own Python file
This commit is contained in:
parent
b404605878
commit
de23b5c221
@ -134,29 +134,8 @@ except:
|
|||||||
config_dir = ""
|
config_dir = ""
|
||||||
|
|
||||||
|
|
||||||
# Wrap a stream so that output gets flushed immediately
|
from utilities import SafeUnbuffered
|
||||||
# and also make sure that any unicode strings get safely
|
|
||||||
# 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,str) or isinstance(data,unicode):
|
|
||||||
# str for Python3, unicode for Python2
|
|
||||||
data = data.encode(self.encoding,"replace")
|
|
||||||
try:
|
|
||||||
buffer = getattr(self.stream, 'buffer', self.stream)
|
|
||||||
# self.stream.buffer for Python3, self.stream for Python2
|
|
||||||
buffer.write(data)
|
|
||||||
buffer.flush()
|
|
||||||
except:
|
|
||||||
# We can do nothing if a write fails
|
|
||||||
raise
|
|
||||||
def __getattr__(self, attr):
|
|
||||||
return getattr(self.stream, attr)
|
|
||||||
|
|
||||||
PLUGIN_NAME = __version.PLUGIN_NAME
|
PLUGIN_NAME = __version.PLUGIN_NAME
|
||||||
PLUGIN_VERSION = __version.PLUGIN_VERSION
|
PLUGIN_VERSION = __version.PLUGIN_VERSION
|
||||||
|
@ -5,29 +5,7 @@
|
|||||||
# For use with Topaz Scripts Version 2.6
|
# For use with Topaz Scripts Version 2.6
|
||||||
# Python 3, September 2020
|
# Python 3, September 2020
|
||||||
|
|
||||||
# Wrap a stream so that output gets flushed immediately
|
from utilities import SafeUnbuffered
|
||||||
# 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,str) or isinstance(data,unicode):
|
|
||||||
# str for Python3, unicode for Python2
|
|
||||||
data = data.encode(self.encoding,"replace")
|
|
||||||
try:
|
|
||||||
buffer = getattr(self.stream, 'buffer', self.stream)
|
|
||||||
# self.stream.buffer for Python3, self.stream for Python2
|
|
||||||
buffer.write(data)
|
|
||||||
buffer.flush()
|
|
||||||
except:
|
|
||||||
# We can do nothing if a write fails
|
|
||||||
raise
|
|
||||||
def __getattr__(self, attr):
|
|
||||||
return getattr(self.stream, attr)
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import csv
|
import csv
|
||||||
|
@ -79,29 +79,7 @@ except ImportError:
|
|||||||
|
|
||||||
#@@CALIBRE_COMPAT_CODE@@
|
#@@CALIBRE_COMPAT_CODE@@
|
||||||
|
|
||||||
# Wrap a stream so that output gets flushed immediately
|
from utilities import SafeUnbuffered
|
||||||
# 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,str) or isinstance(data,unicode):
|
|
||||||
# str for Python3, unicode for Python2
|
|
||||||
data = data.encode(self.encoding,"replace")
|
|
||||||
try:
|
|
||||||
buffer = getattr(self.stream, 'buffer', self.stream)
|
|
||||||
# self.stream.buffer for Python3, self.stream for Python2
|
|
||||||
buffer.write(data)
|
|
||||||
buffer.flush()
|
|
||||||
except:
|
|
||||||
# We can do nothing if a write fails
|
|
||||||
raise
|
|
||||||
def __getattr__(self, attr):
|
|
||||||
return getattr(self.stream, attr)
|
|
||||||
|
|
||||||
iswindows = sys.platform.startswith('win')
|
iswindows = sys.platform.startswith('win')
|
||||||
isosx = sys.platform.startswith('darwin')
|
isosx = sys.platform.startswith('darwin')
|
||||||
|
@ -4,29 +4,7 @@
|
|||||||
# Python 3 for calibre 5.0
|
# Python 3 for calibre 5.0
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
# Wrap a stream so that output gets flushed immediately
|
from utilities import SafeUnbuffered
|
||||||
# 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,str) or isinstance(data,unicode):
|
|
||||||
# str for Python3, unicode for Python2
|
|
||||||
data = data.encode(self.encoding,"replace")
|
|
||||||
try:
|
|
||||||
buffer = getattr(self.stream, 'buffer', self.stream)
|
|
||||||
# self.stream.buffer for Python3, self.stream for Python2
|
|
||||||
buffer.write(data)
|
|
||||||
buffer.flush()
|
|
||||||
except:
|
|
||||||
# We can do nothing if a write fails
|
|
||||||
raise
|
|
||||||
def __getattr__(self, attr):
|
|
||||||
return getattr(self.stream, attr)
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import csv
|
import csv
|
||||||
|
@ -50,35 +50,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from Crypto.Cipher import AES
|
from Crypto.Cipher import AES
|
||||||
|
|
||||||
# Wrap a stream so that output gets flushed immediately
|
from utilities import SafeUnbuffered
|
||||||
# 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,str) or isinstance(data,unicode):
|
|
||||||
# str for Python3, unicode for Python2
|
|
||||||
data = data.encode(self.encoding,"replace")
|
|
||||||
try:
|
|
||||||
buffer = getattr(self.stream, 'buffer', self.stream)
|
|
||||||
# self.stream.buffer for Python3, self.stream for Python2
|
|
||||||
buffer.write(data)
|
|
||||||
buffer.flush()
|
|
||||||
except:
|
|
||||||
# We can do nothing if a write fails
|
|
||||||
raise
|
|
||||||
def __getattr__(self, attr):
|
|
||||||
return getattr(self.stream, attr)
|
|
||||||
|
|
||||||
try:
|
|
||||||
from calibre.constants import iswindows, isosx
|
|
||||||
except:
|
|
||||||
iswindows = sys.platform.startswith('win')
|
|
||||||
isosx = sys.platform.startswith('darwin')
|
|
||||||
|
|
||||||
def unicode_argv():
|
def unicode_argv():
|
||||||
if iswindows:
|
if iswindows:
|
||||||
|
@ -27,35 +27,12 @@ import hashlib
|
|||||||
import getopt
|
import getopt
|
||||||
import re
|
import re
|
||||||
|
|
||||||
# Wrap a stream so that output gets flushed immediately
|
from utilities import SafeUnbuffered
|
||||||
# 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,str) or isinstance(data,unicode):
|
|
||||||
# str for Python3, unicode for Python2
|
|
||||||
data = data.encode(self.encoding,"replace")
|
|
||||||
try:
|
|
||||||
buffer = getattr(self.stream, 'buffer', self.stream)
|
|
||||||
# self.stream.buffer for Python3, self.stream for Python2
|
|
||||||
buffer.write(data)
|
|
||||||
buffer.flush()
|
|
||||||
except:
|
|
||||||
# We can do nothing if a write fails
|
|
||||||
raise
|
|
||||||
def __getattr__(self, attr):
|
|
||||||
return getattr(self.stream, attr)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from calibre.constants import iswindows, isosx
|
from calibre.constants import iswindows
|
||||||
except:
|
except:
|
||||||
iswindows = sys.platform.startswith('win')
|
iswindows = sys.platform.startswith('win')
|
||||||
isosx = sys.platform.startswith('darwin')
|
|
||||||
|
|
||||||
def unicode_argv():
|
def unicode_argv():
|
||||||
if iswindows:
|
if iswindows:
|
||||||
|
@ -70,35 +70,7 @@ def unpad(data, padding=16):
|
|||||||
|
|
||||||
return data[:-pad_len]
|
return data[:-pad_len]
|
||||||
|
|
||||||
# Wrap a stream so that output gets flushed immediately
|
from utilities import SafeUnbuffered
|
||||||
# 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,str) or isinstance(data,unicode):
|
|
||||||
# str for Python3, unicode for Python2
|
|
||||||
data = data.encode(self.encoding,"replace")
|
|
||||||
try:
|
|
||||||
buffer = getattr(self.stream, 'buffer', self.stream)
|
|
||||||
# self.stream.buffer for Python3, self.stream for Python2
|
|
||||||
buffer.write(data)
|
|
||||||
buffer.flush()
|
|
||||||
except:
|
|
||||||
# We can do nothing if a write fails
|
|
||||||
raise
|
|
||||||
def __getattr__(self, attr):
|
|
||||||
return getattr(self.stream, attr)
|
|
||||||
|
|
||||||
try:
|
|
||||||
from calibre.constants import iswindows, isosx
|
|
||||||
except:
|
|
||||||
iswindows = sys.platform.startswith('win')
|
|
||||||
isosx = sys.platform.startswith('darwin')
|
|
||||||
|
|
||||||
def unicode_argv():
|
def unicode_argv():
|
||||||
if iswindows:
|
if iswindows:
|
||||||
|
@ -93,29 +93,7 @@ def unpad(data, padding=16):
|
|||||||
return data[:-pad_len]
|
return data[:-pad_len]
|
||||||
|
|
||||||
|
|
||||||
# Wrap a stream so that output gets flushed immediately
|
from utilities import SafeUnbuffered
|
||||||
# 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,str) or isinstance(data,unicode):
|
|
||||||
# str for Python3, unicode for Python2
|
|
||||||
data = data.encode(self.encoding,"replace")
|
|
||||||
try:
|
|
||||||
buffer = getattr(self.stream, 'buffer', self.stream)
|
|
||||||
# self.stream.buffer for Python3, self.stream for Python2
|
|
||||||
buffer.write(data)
|
|
||||||
buffer.flush()
|
|
||||||
except:
|
|
||||||
# We can do nothing if a write fails
|
|
||||||
raise
|
|
||||||
def __getattr__(self, attr):
|
|
||||||
return getattr(self.stream, attr)
|
|
||||||
|
|
||||||
iswindows = sys.platform.startswith('win')
|
iswindows = sys.platform.startswith('win')
|
||||||
isosx = sys.platform.startswith('darwin')
|
isosx = sys.platform.startswith('darwin')
|
||||||
|
@ -88,32 +88,7 @@ import kgenpids
|
|||||||
import androidkindlekey
|
import androidkindlekey
|
||||||
import kfxdedrm
|
import kfxdedrm
|
||||||
|
|
||||||
# Wrap a stream so that output gets flushed immediately
|
from utilities import SafeUnbuffered
|
||||||
# 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,str) or isinstance(data,unicode):
|
|
||||||
# str for Python3, unicode for Python2
|
|
||||||
data = data.encode(self.encoding,"replace")
|
|
||||||
try:
|
|
||||||
buffer = getattr(self.stream, 'buffer', self.stream)
|
|
||||||
# self.stream.buffer for Python3, self.stream for Python2
|
|
||||||
buffer.write(data)
|
|
||||||
buffer.flush()
|
|
||||||
except:
|
|
||||||
# We can do nothing if a write fails
|
|
||||||
raise
|
|
||||||
def __getattr__(self, attr):
|
|
||||||
return getattr(self.stream, attr)
|
|
||||||
|
|
||||||
iswindows = sys.platform.startswith('win')
|
|
||||||
isosx = sys.platform.startswith('darwin')
|
|
||||||
|
|
||||||
def unicode_argv():
|
def unicode_argv():
|
||||||
if iswindows:
|
if iswindows:
|
||||||
|
@ -62,29 +62,7 @@ except NameError:
|
|||||||
|
|
||||||
# Routines common to Mac and PC
|
# Routines common to Mac and PC
|
||||||
|
|
||||||
# Wrap a stream so that output gets flushed immediately
|
from utilities import SafeUnbuffered
|
||||||
# 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,str) or isinstance(data,unicode):
|
|
||||||
# str for Python3, unicode for Python2
|
|
||||||
data = data.encode(self.encoding,"replace")
|
|
||||||
try:
|
|
||||||
buffer = getattr(self.stream, 'buffer', self.stream)
|
|
||||||
# self.stream.buffer for Python3, self.stream for Python2
|
|
||||||
buffer.write(data)
|
|
||||||
buffer.flush()
|
|
||||||
except:
|
|
||||||
# We can do nothing if a write fails
|
|
||||||
raise
|
|
||||||
def __getattr__(self, attr):
|
|
||||||
return getattr(self.stream, attr)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from calibre.constants import iswindows, isosx
|
from calibre.constants import iswindows, isosx
|
||||||
|
@ -16,32 +16,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import binascii
|
import binascii
|
||||||
|
|
||||||
# Wrap a stream so that output gets flushed immediately
|
from utilities import SafeUnbuffered
|
||||||
# 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,str) or isinstance(data,unicode):
|
|
||||||
# str for Python3, unicode for Python2
|
|
||||||
data = data.encode(self.encoding,"replace")
|
|
||||||
try:
|
|
||||||
buffer = getattr(self.stream, 'buffer', self.stream)
|
|
||||||
# self.stream.buffer for Python3, self.stream for Python2
|
|
||||||
buffer.write(data)
|
|
||||||
buffer.flush()
|
|
||||||
except:
|
|
||||||
# We can do nothing if a write fails
|
|
||||||
raise
|
|
||||||
def __getattr__(self, attr):
|
|
||||||
return getattr(self.stream, attr)
|
|
||||||
|
|
||||||
iswindows = sys.platform.startswith('win')
|
|
||||||
isosx = sys.platform.startswith('darwin')
|
|
||||||
|
|
||||||
def unicode_argv():
|
def unicode_argv():
|
||||||
if iswindows:
|
if iswindows:
|
||||||
|
@ -85,29 +85,7 @@ try:
|
|||||||
except:
|
except:
|
||||||
print("AlfCrypto not found. Using python PC1 implementation.")
|
print("AlfCrypto not found. Using python PC1 implementation.")
|
||||||
|
|
||||||
# Wrap a stream so that output gets flushed immediately
|
from utilities import SafeUnbuffered
|
||||||
# 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,str) or isinstance(data,unicode):
|
|
||||||
# str for Python3, unicode for Python2
|
|
||||||
data = data.encode(self.encoding,"replace")
|
|
||||||
try:
|
|
||||||
buffer = getattr(self.stream, 'buffer', self.stream)
|
|
||||||
# self.stream.buffer for Python3, self.stream for Python2
|
|
||||||
buffer.write(data)
|
|
||||||
buffer.flush()
|
|
||||||
except:
|
|
||||||
# We can do nothing if a write fails
|
|
||||||
raise
|
|
||||||
def __getattr__(self, attr):
|
|
||||||
return getattr(self.stream, attr)
|
|
||||||
|
|
||||||
iswindows = sys.platform.startswith('win')
|
iswindows = sys.platform.startswith('win')
|
||||||
isosx = sys.platform.startswith('darwin')
|
isosx = sys.platform.startswith('darwin')
|
||||||
|
@ -23,33 +23,9 @@ from struct import pack
|
|||||||
from struct import unpack
|
from struct import unpack
|
||||||
|
|
||||||
from alfcrypto import Topaz_Cipher
|
from alfcrypto import Topaz_Cipher
|
||||||
|
from utilities import SafeUnbuffered
|
||||||
|
|
||||||
# Wrap a stream so that output gets flushed immediately
|
from argv_utils import unicode_argv
|
||||||
# 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,str) or isinstance(data,unicode):
|
|
||||||
# str for Python3, unicode for Python2
|
|
||||||
data = data.encode(self.encoding,"replace")
|
|
||||||
try:
|
|
||||||
buffer = getattr(self.stream, 'buffer', self.stream)
|
|
||||||
# self.stream.buffer for Python3, self.stream for Python2
|
|
||||||
buffer.write(data)
|
|
||||||
buffer.flush()
|
|
||||||
except:
|
|
||||||
# We can do nothing if a write fails
|
|
||||||
raise
|
|
||||||
def __getattr__(self, attr):
|
|
||||||
return getattr(self.stream, attr)
|
|
||||||
|
|
||||||
iswindows = sys.platform.startswith('win')
|
|
||||||
isosx = sys.platform.startswith('darwin')
|
|
||||||
|
|
||||||
def unicode_argv():
|
def unicode_argv():
|
||||||
if iswindows:
|
if iswindows:
|
||||||
|
@ -45,3 +45,29 @@ def parseCustString(keystuff):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return userkeys
|
return userkeys
|
||||||
|
|
||||||
|
|
||||||
|
# Wrap a stream so that output gets flushed immediately
|
||||||
|
# and also make sure that any unicode strings get safely
|
||||||
|
# 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,str) or isinstance(data,unicode):
|
||||||
|
# str for Python3, unicode for Python2
|
||||||
|
data = data.encode(self.encoding,"replace")
|
||||||
|
try:
|
||||||
|
buffer = getattr(self.stream, 'buffer', self.stream)
|
||||||
|
# self.stream.buffer for Python3, self.stream for Python2
|
||||||
|
buffer.write(data)
|
||||||
|
buffer.flush()
|
||||||
|
except:
|
||||||
|
# We can do nothing if a write fails
|
||||||
|
raise
|
||||||
|
def __getattr__(self, attr):
|
||||||
|
return getattr(self.stream, attr)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user