Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 uses a different integer division operator and different default encoding #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions miette/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,24 @@ def read(self, size=None):
length = size - len(data_buffer)

if fc_f_compressed:
fc_fc /= 2
fc_fc //= 2
else:
length *= 2

self.word_document.seek(fc_fc)
part = self.word_document.read(length)
if not fc_f_compressed:
part = part.decode('utf-16')
else:
part = part.decode('cp1252') # Python 2.x uses ASCII as a default encoding, but Python 3.3+ uses UTF-8 default encoding. Therefore we need to specify the cp1252 file encoding explicitly.
data_buffer += str(part)
self._position += len(part)

if len(data_buffer) >= size:
break

return data_buffer[:size].encode('utf-8')
# return data_buffer[:size].encode('utf-8') # comment-out: the Python 3.3+ string is already in UTF-8 format
return data_buffer[:size]

def tell(self):
"""
Expand Down