From d2acc300264ed00b5fc6728e7948a208dab49bf7 2014-06-10 19:05:46 From: Thomas Kluyver Date: 2014-06-10 19:05:46 Subject: [PATCH] Move strip_ansi function to utils --- diff --git a/IPython/nbconvert/filters/ansi.py b/IPython/nbconvert/filters/ansi.py index ad8c7c1..0d6913d 100644 --- a/IPython/nbconvert/filters/ansi.py +++ b/IPython/nbconvert/filters/ansi.py @@ -14,6 +14,7 @@ import re from IPython.utils import coloransi +from IPython.utils.text import strip_ansi #----------------------------------------------------------------------------- # Classes and functions @@ -26,19 +27,6 @@ __all__ = [ 'ansi2latex' ] -def strip_ansi(source): - """ - Remove ansi from text - - Parameters - ---------- - source : str - Source to remove the ansi from - """ - - return re.sub(r'\033\[(\d|;)+?m', '', source) - - ansi_colormap = { '30': 'ansiblack', '31': 'ansired', diff --git a/IPython/testing/iptestcontroller.py b/IPython/testing/iptestcontroller.py index 0000a38..2982397 100644 --- a/IPython/testing/iptestcontroller.py +++ b/IPython/testing/iptestcontroller.py @@ -27,7 +27,7 @@ from IPython.utils.path import compress_user from IPython.utils.py3compat import bytes_to_str from IPython.utils.sysinfo import get_sys_info from IPython.utils.tempdir import TemporaryDirectory -from IPython.nbconvert.filters.ansi import strip_ansi +from IPython.utils.text import strip_ansi try: # Python >= 3.3 diff --git a/IPython/utils/text.py b/IPython/utils/text.py index b57895b..6cd9955 100644 --- a/IPython/utils/text.py +++ b/IPython/utils/text.py @@ -491,6 +491,17 @@ def strip_email_quotes(text): text = '\n'.join([ ln[strip:] for ln in lines]) return text +def strip_ansi(source): + """ + Remove ansi escape codes from text. + + Parameters + ---------- + source : str + Source to remove the ansi from + """ + return re.sub(r'\033\[(\d|;)+?m', '', source) + class EvalFormatter(Formatter): """A String Formatter that allows evaluation of simple expressions.