diff options
| author | robot-contrib <[email protected]> | 2022-05-18 00:43:36 +0300 |
|---|---|---|
| committer | robot-contrib <[email protected]> | 2022-05-18 00:43:36 +0300 |
| commit | 9e5f436a8b2a27bcc7802e443ea3ef3e41a82a75 (patch) | |
| tree | 78b522cab9f76336e62064d4d8ff7c897659b20e /contrib/python/ipython/py3/IPython/lib/display.py | |
| parent | 8113a823ffca6451bb5ff8f0334560885a939a24 (diff) | |
Update contrib/python/ipython/py3 to 8.3.0
ref:e84342d4d30476f9148137f37fd0c6405fd36f55
Diffstat (limited to 'contrib/python/ipython/py3/IPython/lib/display.py')
| -rw-r--r-- | contrib/python/ipython/py3/IPython/lib/display.py | 102 |
1 files changed, 55 insertions, 47 deletions
diff --git a/contrib/python/ipython/py3/IPython/lib/display.py b/contrib/python/ipython/py3/IPython/lib/display.py index 7b94acf6395..5ff2983dbf4 100644 --- a/contrib/python/ipython/py3/IPython/lib/display.py +++ b/contrib/python/ipython/py3/IPython/lib/display.py @@ -65,34 +65,47 @@ class Audio(DisplayObject): Examples -------- - :: - # Generate a sound - import numpy as np - framerate = 44100 - t = np.linspace(0,5,framerate*5) - data = np.sin(2*np.pi*220*t) + np.sin(2*np.pi*224*t) - Audio(data,rate=framerate) + >>> import pytest + >>> np = pytest.importorskip("numpy") + + Generate a sound + + >>> import numpy as np + >>> framerate = 44100 + >>> t = np.linspace(0,5,framerate*5) + >>> data = np.sin(2*np.pi*220*t) + np.sin(2*np.pi*224*t) + >>> Audio(data, rate=framerate) + <IPython.lib.display.Audio object> + + Can also do stereo or more channels + + >>> dataleft = np.sin(2*np.pi*220*t) + >>> dataright = np.sin(2*np.pi*224*t) + >>> Audio([dataleft, dataright], rate=framerate) + <IPython.lib.display.Audio object> + + From URL: - # Can also do stereo or more channels - dataleft = np.sin(2*np.pi*220*t) - dataright = np.sin(2*np.pi*224*t) - Audio([dataleft, dataright],rate=framerate) + >>> Audio("http://www.nch.com.au/acm/8k16bitpcm.wav") # doctest: +SKIP + >>> Audio(url="http://www.w3schools.com/html/horse.ogg") # doctest: +SKIP - Audio("http://www.nch.com.au/acm/8k16bitpcm.wav") # From URL - Audio(url="http://www.w3schools.com/html/horse.ogg") + From a File: - Audio('/path/to/sound.wav') # From file - Audio(filename='/path/to/sound.ogg') + >>> Audio('IPython/lib/tests/test.wav') # doctest: +SKIP + >>> Audio(filename='IPython/lib/tests/test.wav') # doctest: +SKIP - Audio(b'RAW_WAV_DATA..) # From bytes - Audio(data=b'RAW_WAV_DATA..) + From Bytes: + + >>> Audio(b'RAW_WAV_DATA..') # doctest: +SKIP + >>> Audio(data=b'RAW_WAV_DATA..') # doctest: +SKIP See Also -------- - - See also the ``Audio`` widgets form the ``ipywidget`` package for more flexibility and options. - + ipywidgets.Audio + + Audio widget with more more flexibility and options. + """ _read_flags = 'rb' @@ -183,9 +196,9 @@ class Audio(DisplayObject): try: max_abs_value = float(max([abs(x) for x in data])) - except TypeError: + except TypeError as e: raise TypeError('Only lists of mono audio are ' - 'supported if numpy is not installed') + 'supported if numpy is not installed') from e normalization_factor = Audio._get_normalization_factor(max_abs_value, normalize) scaled = array.array('h', [int(x / normalization_factor * 32767) for x in data]) @@ -272,10 +285,7 @@ class IFrame(object): def _repr_html_(self): """return the embed iframe""" if self.params: - try: - from urllib.parse import urlencode # Py 3 - except ImportError: - from urllib import urlencode + from urllib.parse import urlencode params = "?" + urlencode(self.params) else: params = "" @@ -500,27 +510,25 @@ class FileLinks(FileLink): self.recursive = recursive - def _get_display_formatter(self, - dirname_output_format, - fname_output_format, - fp_format, - fp_cleaner=None): - """ generate built-in formatter function - - this is used to define both the notebook and terminal built-in - formatters as they only differ by some wrapper text for each entry - - dirname_output_format: string to use for formatting directory - names, dirname will be substituted for a single "%s" which - must appear in this string - fname_output_format: string to use for formatting file names, - if a single "%s" appears in the string, fname will be substituted - if two "%s" appear in the string, the path to fname will be - substituted for the first and fname will be substituted for the - second - fp_format: string to use for formatting filepaths, must contain - exactly two "%s" and the dirname will be substituted for the first - and fname will be substituted for the second + def _get_display_formatter( + self, dirname_output_format, fname_output_format, fp_format, fp_cleaner=None + ): + """generate built-in formatter function + + this is used to define both the notebook and terminal built-in + formatters as they only differ by some wrapper text for each entry + + dirname_output_format: string to use for formatting directory + names, dirname will be substituted for a single "%s" which + must appear in this string + fname_output_format: string to use for formatting file names, + if a single "%s" appears in the string, fname will be substituted + if two "%s" appear in the string, the path to fname will be + substituted for the first and fname will be substituted for the + second + fp_format: string to use for formatting filepaths, must contain + exactly two "%s" and the dirname will be substituted for the first + and fname will be substituted for the second """ def f(dirname, fnames, included_suffixes=None): result = [] |
