mirror of
https://github.com/noDRM/DeDRM_tools
synced 2024-12-25 21:58:59 +01:00
Another Python2 Bugfix for Obok
This commit is contained in:
parent
1cc5d383cc
commit
b404605878
2 changed files with 21 additions and 6 deletions
|
@ -224,10 +224,17 @@ class SafeUnbuffered:
|
||||||
if self.encoding == None:
|
if self.encoding == None:
|
||||||
self.encoding = "utf-8"
|
self.encoding = "utf-8"
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
if isinstance(data,str):
|
if isinstance(data,str) or isinstance(data,unicode):
|
||||||
|
# str for Python3, unicode for Python2
|
||||||
data = data.encode(self.encoding,"replace")
|
data = data.encode(self.encoding,"replace")
|
||||||
self.stream.buffer.write(data)
|
try:
|
||||||
self.stream.buffer.flush()
|
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):
|
def __getattr__(self, attr):
|
||||||
return getattr(self.stream, attr)
|
return getattr(self.stream, attr)
|
||||||
|
|
||||||
|
|
|
@ -276,14 +276,22 @@ class SafeUnbuffered:
|
||||||
if self.encoding == None:
|
if self.encoding == None:
|
||||||
self.encoding = "utf-8"
|
self.encoding = "utf-8"
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
if isinstance(data,unicode):
|
if isinstance(data,str) or isinstance(data,unicode):
|
||||||
|
# str for Python3, unicode for Python2
|
||||||
data = data.encode(self.encoding,"replace")
|
data = data.encode(self.encoding,"replace")
|
||||||
self.stream.write(data)
|
try:
|
||||||
self.stream.flush()
|
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):
|
def __getattr__(self, attr):
|
||||||
return getattr(self.stream, attr)
|
return getattr(self.stream, attr)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class KoboLibrary(object):
|
class KoboLibrary(object):
|
||||||
"""The Kobo library.
|
"""The Kobo library.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue