From e5ce62bfeaff2c77b603a2c090b85c576e8a7732 Mon Sep 17 00:00:00 2001 From: Bastian Bechtold Date: Wed, 10 Dec 2014 10:34:55 +0100 Subject: [PATCH 1/3] modified __repr__ for 2.6 compatibility --- pysoundfile.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pysoundfile.py b/pysoundfile.py index a69288a..68ac3a8 100644 --- a/pysoundfile.py +++ b/pysoundfile.py @@ -718,9 +718,9 @@ def __init__(self, file, mode='r', samplerate=None, channels=None, _file = None def __repr__(self): - return ('SoundFile("{}", mode="{}", samplerate={}, channels={}, ' - 'format="{}")').format(self.name, self.mode, self.samplerate, - self.channels, self.format) + return ('SoundFile("%s", mode="%s", samplerate=%i, channels=%i, ' + 'format="%s")' % (self.name, self.mode, self.samplerate, + self.channels, self.format)) def __del__(self): self.close() From ee60d3a60f153854d6aa8f015b7a5deb8a71d3da Mon Sep 17 00:00:00 2001 From: Bastian Bechtold Date: Wed, 17 Dec 2014 13:48:04 +0100 Subject: [PATCH 2/3] included subtype and endian in __repr__ --- pysoundfile.py | 5 +++-- tests/test_pysoundfile.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pysoundfile.py b/pysoundfile.py index 68ac3a8..abc638b 100644 --- a/pysoundfile.py +++ b/pysoundfile.py @@ -719,8 +719,9 @@ def __init__(self, file, mode='r', samplerate=None, channels=None, def __repr__(self): return ('SoundFile("%s", mode="%s", samplerate=%i, channels=%i, ' - 'format="%s")' % (self.name, self.mode, self.samplerate, - self.channels, self.format)) + 'format="%s", subtype="%s", endian="%s")' % + (self.name, self.mode, self.samplerate, self.channels, + self.format, self.subtype, self.endian)) def __del__(self): self.close() diff --git a/tests/test_pysoundfile.py b/tests/test_pysoundfile.py index 9bb0951..07c8bbd 100644 --- a/tests/test_pysoundfile.py +++ b/tests/test_pysoundfile.py @@ -449,7 +449,8 @@ def test__repr__(sf_stereo_r): if not isinstance(sf_stereo_r.name, int): assert repr(sf_stereo_r) == ('SoundFile("{}", mode="r", ' 'samplerate=44100, channels=2, ' - 'format="WAV")').format(filename_stereo) + 'format="WAV", subtype="FLOAT", ' + 'endian="FILE")').format(filename_stereo) def test_mode_should_be_in_write_mode(sf_stereo_w): assert sf_stereo_w.mode == 'w' From 5e9a075d9fac3cc8e82c59a3cead3723797afa47 Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Tue, 23 Dec 2014 22:45:39 +0100 Subject: [PATCH 3/3] Store file-like object as SoundFile.name ... instead of storing only the "name" attribute of the file-like object. __repr__() shows the repr() of the file name/file descriptor/file-like object and the repr() of the mode and format strings. --- pysoundfile.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pysoundfile.py b/pysoundfile.py index abc638b..c70b9a4 100644 --- a/pysoundfile.py +++ b/pysoundfile.py @@ -636,10 +636,10 @@ def __init__(self, file, mode='r', samplerate=None, channels=None, mode_int = _snd.SFM_WRITE old_fmt = format - self._name = getattr(file, 'name', file) + self._name = file if format is None: - format = str(self.name).rsplit('.', 1)[-1].upper() - if format not in _formats and 'r' not in modes: + format = str(getattr(file, 'name', file)).rsplit('.', 1)[-1] + if format.upper() not in _formats and 'r' not in modes: raise TypeError( "No format specified and unable to get format from " "file extension: %s" % repr(self.name)) @@ -718,8 +718,8 @@ def __init__(self, file, mode='r', samplerate=None, channels=None, _file = None def __repr__(self): - return ('SoundFile("%s", mode="%s", samplerate=%i, channels=%i, ' - 'format="%s", subtype="%s", endian="%s")' % + return ('SoundFile(%r, mode=%r, samplerate=%i, channels=%i, ' + 'format=%r, subtype=%r, endian=%r)' % (self.name, self.mode, self.samplerate, self.channels, self.format, self.subtype, self.endian))