Kaydet (Commit) d739bda6 authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka

Issue #18084: Use sys.byteorder in wave.py.

Original patch by Hideaki Takahashi.
üst 2e537f9e
...@@ -82,13 +82,8 @@ WAVE_FORMAT_PCM = 0x0001 ...@@ -82,13 +82,8 @@ WAVE_FORMAT_PCM = 0x0001
_array_fmts = None, 'b', 'h', None, 'l' _array_fmts = None, 'b', 'h', None, 'l'
# Determine endian-ness
import struct import struct
if struct.pack("h", 1) == b"\000\001": import sys
big_endian = 1
else:
big_endian = 0
from chunk import Chunk from chunk import Chunk
from collections import namedtuple from collections import namedtuple
...@@ -235,7 +230,7 @@ class Wave_read: ...@@ -235,7 +230,7 @@ class Wave_read:
self._data_seek_needed = 0 self._data_seek_needed = 0
if nframes == 0: if nframes == 0:
return b'' return b''
if self._sampwidth > 1 and big_endian: if self._sampwidth > 1 and sys.byteorder == 'big':
# unfortunately the fromfile() method does not take # unfortunately the fromfile() method does not take
# something that only looks like a file object, so # something that only looks like a file object, so
# we have to reach into the innards of the chunk object # we have to reach into the innards of the chunk object
...@@ -422,7 +417,7 @@ class Wave_write: ...@@ -422,7 +417,7 @@ class Wave_write:
nframes = len(data) // (self._sampwidth * self._nchannels) nframes = len(data) // (self._sampwidth * self._nchannels)
if self._convert: if self._convert:
data = self._convert(data) data = self._convert(data)
if self._sampwidth > 1 and big_endian: if self._sampwidth > 1 and sys.byteorder == 'big':
import array import array
data = array.array(_array_fmts[self._sampwidth], data) data = array.array(_array_fmts[self._sampwidth], data)
data.byteswap() data.byteswap()
......
...@@ -1222,6 +1222,7 @@ Thenault Sylvain ...@@ -1222,6 +1222,7 @@ Thenault Sylvain
Péter Szabó Péter Szabó
Amir Szekely Amir Szekely
Arfrever Frehtes Taifersar Arahesis Arfrever Frehtes Taifersar Arahesis
Hideaki Takahashi
Neil Tallim Neil Tallim
Geoff Talvola Geoff Talvola
Musashi Tamura Musashi Tamura
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment