From eced0f25b3ebd340e2325377192bd36f237fe1a9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 10 Apr 2019 20:56:52 +0530 Subject: [PATCH] py3: misc fixes --- src/calibre/ebooks/metadata/opf2.py | 4 ++-- src/calibre/utils/zipfile.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/metadata/opf2.py b/src/calibre/ebooks/metadata/opf2.py index e0cbbd304a..3bbe43c6bc 100644 --- a/src/calibre/ebooks/metadata/opf2.py +++ b/src/calibre/ebooks/metadata/opf2.py @@ -1322,8 +1322,8 @@ class OPF(object): # {{{ if pretty_print_opf: _pretty_print(self.root) raw = etree.tostring(self.root, encoding=encoding, pretty_print=True) - if not raw.lstrip().startswith('\n'%encoding.upper()+raw + if not raw.lstrip().startswith(b'\n'%encoding.upper()).encode('ascii') + raw return raw def smart_update(self, mi, replace_metadata=False, apply_null=False): diff --git a/src/calibre/utils/zipfile.py b/src/calibre/utils/zipfile.py index 808812625c..0a9ac3f7da 100644 --- a/src/calibre/utils/zipfile.py +++ b/src/calibre/utils/zipfile.py @@ -321,7 +321,7 @@ class ZipInfo (object): # Terminate the file name at the first null byte. Null bytes in file # names are used as tricks by viruses in archives. - null_byte = filename.find(chr(0)) + null_byte = filename.find(b'\0' if isinstance(filename, bytes) else u'\0') if null_byte >= 0: filename = filename[0:null_byte] # This is used to ensure paths in generated ZIP files always use