[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Normalized stem.util.term.format to return unicode
commit a4a59d0b309ebb07123c633aeae8cb3907ce1eb2
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Wed Jun 14 09:38:30 2017 -0700
Normalized stem.util.term.format to return unicode
An anonymous user reports that the following line in the 'to russia with love'
tutorial fails for python3...
print(term.format(query("https://www.atagar.com/echo.php"), term.Color.BLUE))
On relection I want stem.util.term.format() to accept both bytes and unicode,
so normalizing the input once we get it.
---
docs/change_log.rst | 1 +
stem/util/term.py | 8 +++++++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/docs/change_log.rst b/docs/change_log.rst
index 84f7493..50158ca 100644
--- a/docs/change_log.rst
+++ b/docs/change_log.rst
@@ -70,6 +70,7 @@ The following are only available within Stem's `git repository
* Added cwd argument to :func:`~stem.util.system.call`
* Added :class:`~stem.util.test_tools.TimedTestRunner` and :func:`~stem.util.test_tools.test_runtimes`
* Supporing pid arguments in :func:`~stem.util.system.is_running`
+ * Normalized :func:`~stem.util.term.format` to return unicode
* **Interpreter**
diff --git a/stem/util/term.py b/stem/util/term.py
index 895c4e9..68fa817 100644
--- a/stem/util/term.py
+++ b/stem/util/term.py
@@ -115,15 +115,21 @@ def format(msg, *attr):
* `termcolor <https://pypi.python.org/pypi/termcolor>`_
* `colorama <https://pypi.python.org/pypi/colorama>`_
+ .. versionchanged:: 1.6.0
+ Normalized return value to be unicode to better support python 2/3
+ compatibility.
+
:param str msg: string to be formatted
:param str attr: text attributes, this can be :data:`~stem.util.term.Color`,
:data:`~stem.util.term.BgColor`, or :data:`~stem.util.term.Attr` enums
and are case insensitive (so strings like 'red' are fine)
- :returns: **str** wrapped with ANSI escape encodings, starting with the given
+ :returns: **unicode** wrapped with ANSI escape encodings, starting with the given
attributes and ending with a reset
"""
+ msg = stem.util.str_tools._to_unicode(msg)
+
if DISABLE_COLOR_SUPPORT:
return msg
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits