Skip to content

Commit d739bda

Browse files
Issue #18084: Use sys.byteorder in wave.py.
Original patch by Hideaki Takahashi.
1 parent 2e537f9 commit d739bda

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

Lib/wave.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,8 @@ class Error(Exception):
8282

8383
_array_fmts = None, 'b', 'h', None, 'l'
8484

85-
# Determine endian-ness
8685
import struct
87-
if struct.pack("h", 1) == b"\000\001":
88-
big_endian = 1
89-
else:
90-
big_endian = 0
91-
86+
import sys
9287
from chunk import Chunk
9388
from collections import namedtuple
9489

@@ -235,7 +230,7 @@ def readframes(self, nframes):
235230
self._data_seek_needed = 0
236231
if nframes == 0:
237232
return b''
238-
if self._sampwidth > 1 and big_endian:
233+
if self._sampwidth > 1 and sys.byteorder == 'big':
239234
# unfortunately the fromfile() method does not take
240235
# something that only looks like a file object, so
241236
# we have to reach into the innards of the chunk object
@@ -422,7 +417,7 @@ def writeframesraw(self, data):
422417
nframes = len(data) // (self._sampwidth * self._nchannels)
423418
if self._convert:
424419
data = self._convert(data)
425-
if self._sampwidth > 1 and big_endian:
420+
if self._sampwidth > 1 and sys.byteorder == 'big':
426421
import array
427422
data = array.array(_array_fmts[self._sampwidth], data)
428423
data.byteswap()

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,7 @@ Thenault Sylvain
12221222
Péter Szabó
12231223
Amir Szekely
12241224
Arfrever Frehtes Taifersar Arahesis
1225+
Hideaki Takahashi
12251226
Neil Tallim
12261227
Geoff Talvola
12271228
Musashi Tamura

0 commit comments

Comments
 (0)