Skip to content

Commit 907f0b7

Browse files
committed
Use int.from_bytes instead of implementing the conversion ourselves.
int.from_bytes has been around since Python 3.2.
1 parent ea66786 commit 907f0b7

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

lib/matplotlib/dviread.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,10 @@ def _read(self):
392392

393393
def _arg(self, nbytes, signed=False):
394394
"""
395-
Read and return an integer argument *nbytes* long.
395+
Read and return a big-endian integer *nbytes* long.
396396
Signedness is determined by the *signed* keyword.
397397
"""
398-
buf = self.file.read(nbytes)
399-
value = buf[0]
400-
if signed and value >= 0x80:
401-
value = value - 0x100
402-
for b in buf[1:]:
403-
value = 0x100*value + b
404-
return value
398+
return int.from_bytes(self.file.read(nbytes), "big", signed=signed)
405399

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

0 commit comments

Comments
 (0)