py3: misc fixes

This commit is contained in:
Kovid Goyal 2019-04-10 20:56:52 +05:30
parent 1a602a7873
commit eced0f25b3
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 3 additions and 3 deletions

View File

@ -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('<?xml '):
raw = '<?xml version="1.0" encoding="%s"?>\n'%encoding.upper()+raw
if not raw.lstrip().startswith(b'<?xml '):
raw = ('<?xml version="1.0" encoding="%s"?>\n'%encoding.upper()).encode('ascii') + raw
return raw
def smart_update(self, mi, replace_metadata=False, apply_null=False):

View File

@ -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