diff --git a/src/calibre/devices/kindle/apnx.py b/src/calibre/devices/kindle/apnx.py
index 317a1287d1..89a673b25b 100644
--- a/src/calibre/devices/kindle/apnx.py
+++ b/src/calibre/devices/kindle/apnx.py
@@ -237,7 +237,7 @@ class APNXBuilder(object):
# not modifying the text. In this case the case
# doesn't matter just the absolute character and
# the position within the stream.
- data = bytearray(as_bytes(mr.mobi_html.lower()))
+ data = mr.mobi_html.lower()
slash, p, lt, gt = map(ord, '/p<>')
for c in data:
pos += 1
diff --git a/src/calibre/devices/prs505/driver.py b/src/calibre/devices/prs505/driver.py
index f816754722..0bd4d7b015 100644
--- a/src/calibre/devices/prs505/driver.py
+++ b/src/calibre/devices/prs505/driver.py
@@ -135,10 +135,10 @@ class PRS505(USBMS):
time.sleep(5)
os.makedirs(dname, mode=0o777)
with lopen(cachep, 'wb') as f:
- f.write(u'''
+ f.write(b'''
- '''.encode('utf8'))
+ ''')
fsync(f)
return True
except:
diff --git a/src/calibre/devices/prs505/sony_cache.py b/src/calibre/devices/prs505/sony_cache.py
index fb6f358137..cb4eca51d1 100644
--- a/src/calibre/devices/prs505/sony_cache.py
+++ b/src/calibre/devices/prs505/sony_cache.py
@@ -35,13 +35,13 @@ Periodical identifier sample from a PRS-650:
'''
# Utility functions {{{
-EMPTY_CARD_CACHE = '''\
+EMPTY_CARD_CACHE = b'''\
'''
-EMPTY_EXT_CACHE = '''\
+EMPTY_EXT_CACHE = b'''\
@@ -726,8 +726,8 @@ class XMLCache(object):
self.cleanup_whitespace(i)
raw = etree.tostring(self.roots[i], encoding='UTF-8',
xml_declaration=True)
- raw = raw.replace("",
- '')
+ raw = raw.replace(b"",
+ b'')
with lopen(path, 'wb') as f:
f.write(raw)
fsync(f)
@@ -738,8 +738,8 @@ class XMLCache(object):
xml_declaration=True)
except:
continue
- raw = raw.replace("",
- '')
+ raw = raw.replace(b"",
+ b'')
with lopen(path, 'wb') as f:
f.write(raw)
fsync(f)
diff --git a/src/calibre/ebooks/__init__.py b/src/calibre/ebooks/__init__.py
index 8e958202f8..8028840733 100644
--- a/src/calibre/ebooks/__init__.py
+++ b/src/calibre/ebooks/__init__.py
@@ -204,7 +204,7 @@ def check_ebook_format(stream, current_guess):
ans = current_guess
if current_guess.lower() in ('prc', 'mobi', 'azw', 'azw1', 'azw3'):
stream.seek(0)
- if stream.read(3) == 'TPZ':
+ if stream.read(3) == b'TPZ':
ans = 'tpz'
stream.seek(0)
return ans
diff --git a/src/calibre/ebooks/mobi/reader/mobi6.py b/src/calibre/ebooks/mobi/reader/mobi6.py
index bda6f97dc6..60e4f89aaf 100644
--- a/src/calibre/ebooks/mobi/reader/mobi6.py
+++ b/src/calibre/ebooks/mobi/reader/mobi6.py
@@ -346,7 +346,7 @@ class MobiReader(object):
def cleanup_html(self):
self.log.debug('Cleaning up HTML...')
self.processed_html = re.sub(r'
', '', self.processed_html)
- if self.book_header.ancient and '') + ''
self.processed_html = self.processed_html.replace('\r\n', '\n')
self.processed_html = self.processed_html.replace('> <', '>\n<')