Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use int.from_bytes instead of implementing the conversion ourselves. #27288

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

Merged
merged 1 commit into from
Nov 8, 2023
Merged
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
10 changes: 2 additions & 8 deletions lib/matplotlib/dviread.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,10 @@ def _read(self):

def _arg(self, nbytes, signed=False):
"""
Read and return an integer argument *nbytes* long.
Read and return a big-endian integer *nbytes* long.
Signedness is determined by the *signed* keyword.
"""
buf = self.file.read(nbytes)
value = buf[0]
if signed and value >= 0x80:
value = value - 0x100
for b in buf[1:]:
value = 0x100*value + b
return value
return int.from_bytes(self.file.read(nbytes), "big", signed=signed)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the file pointer be wrapped in a with statement, or does it get cleaned up in the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its lifetime is managed by the Dvi object.


@_dispatch(min=0, max=127, state=_dvistate.inpage)
def _set_char_immediate(self, char):
Expand Down