Repository: ipython/ipython

Issue:
unicode error when trying Audio('data/Bach Cello Suite #3.wav') 
Hello,

I'm under  ipython2.0dev/windows7 / python3

Trying the greatest and latest @ellisonbg notebook at 
https://github.com/ellisonbg/talk-pydata-nyc2013/blob/master/Close to Data.ipynb

I get an unicode error at the wave example.
Does anyone else has the same problem ? (I suspect a bug, as the file plays music if I click on it via the explorer)

```
from IPython.display import display, Audio, Latex
a = Audio('data/Bach Cello Suite #3.wav')
```

```
--------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-4-35380f5da86b> in <module>()
----> 1 a = Audio('data/Bach Cello Suite #3.wav')

c:\users\famille\documents\winpython\winpython-32bit-3.3.2.3ggplotip2\python-3.3.2\src\master\IPython\lib\display.py in __init__(self, data, filename, url, embed, rate, autoplay)
     80             self.embed = True
     81         self.autoplay = autoplay
---> 82         super(Audio, self).__init__(data=data, url=url, filename=filename)
     83 
     84         if self.data is not None and not isinstance(self.data, bytes):

c:\users\famille\documents\winpython\winpython-32bit-3.3.2.3ggplotip2\python-3.3.2\src\master\IPython\core\display.py in __init__(self, data, url, filename)
    304         self.filename = None if filename is None else unicode_type(filename)
    305 
--> 306         self.reload()
    307 
    308     def reload(self):

c:\users\famille\documents\winpython\winpython-32bit-3.3.2.3ggplotip2\python-3.3.2\src\master\IPython\lib\display.py in reload(self)
     89         import mimetypes
     90         if self.embed:
---> 91             super(Audio, self).reload()
     92 
     93         if self.filename is not None:

c:\users\famille\documents\winpython\winpython-32bit-3.3.2.3ggplotip2\python-3.3.2\src\master\IPython\core\display.py in reload(self)
    310         if self.filename is not None:
    311             with open(self.filename, self._read_flags) as f:
--> 312                 self.data = f.read()
    313         elif self.url is not None:
    314             try:

C:\Users\famille\Documents\winpython\WinPython-32bit-3.3.2.3ggplotip2\python-3.3.2\lib\encodings\cp1252.py in decode(self, input, final)
     21 class IncrementalDecoder(codecs.IncrementalDecoder):
     22     def decode(self, input, final=False):
---> 23         return codecs.charmap_decode(input,self.errors,decoding_table)[0]
     24 
     25 class StreamWriter(Codec,codecs.StreamWriter):

UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 75132: character maps to <undefined>
```



Discussion:

Resolving patch:
diff --git a/IPython/lib/display.py b/IPython/lib/display.py
--- a/IPython/lib/display.py
+++ b/IPython/lib/display.py
@@ -67,7 +67,8 @@ class Audio(DisplayObject):
     Audio(data=b'RAW_WAV_DATA..)
 
     """
-        
+    _read_flags = 'rb'
+
     def __init__(self, data=None, filename=None, url=None, embed=None, rate=None, autoplay=False):
         if filename is None and url is None and data is None:
             raise ValueError("No image data found. Expecting filename, url, or data.")
diff --git a/setupbase.py b/setupbase.py
--- a/setupbase.py
+++ b/setupbase.py
@@ -151,6 +151,7 @@ def find_package_data():
     package_data = {
         'IPython.config.profile' : ['README*', '*/*.py'],
         'IPython.core.tests' : ['*.png', '*.jpg'],
+        'IPython.lib.tests' : ['*.wav'],
         'IPython.testing' : ['*.txt'],
         'IPython.testing.plugin' : ['*.txt'],
         'IPython.html' : ['templates/*'] + static_data,


Test patch:
diff --git a/IPython/lib/tests/test.wav b/IPython/lib/tests/test.wav
new file mode 100644
Binary files /dev/null and b/IPython/lib/tests/test.wav differ
diff --git a/IPython/lib/tests/test_display.py b/IPython/lib/tests/test_display.py
--- a/IPython/lib/tests/test_display.py
+++ b/IPython/lib/tests/test_display.py
@@ -14,13 +14,14 @@
 #-----------------------------------------------------------------------------
 from __future__ import print_function
 from tempfile import NamedTemporaryFile, mkdtemp
-from os.path import split
+from os.path import split, join as pjoin, dirname
 
 # Third-party imports
 import nose.tools as nt
 
 # Our own imports
 from IPython.lib import display
+from IPython.testing.decorators import skipif_not_numpy
 
 #-----------------------------------------------------------------------------
 # Classes and functions
@@ -155,3 +156,7 @@ def test_error_on_file_to_FileLinks():
     tf1 = NamedTemporaryFile(dir=td)
     nt.assert_raises(ValueError,display.FileLinks,tf1.name)
 
+@skipif_not_numpy
+def test_audio_from_file():
+    path = pjoin(dirname(__file__), 'test.wav')
+    display.Audio(filename=path)
\ No newline at end of file