commit a31af967594047963a4344e9c9143c184c3d341f Author: Damian Johnson atagar@torproject.org Date: Sat Nov 4 11:54:41 2017 -0700
Bytes/unicode normalization for tor_tools didn't work for python3
We added unit tests to check that tor_tools functions like is_valid_fingerprint() worked for both bytes and unicode, but these tests actually only passes for python 2.x. With python3 they only accepted unicode. Normalizing the inputs. --- stem/util/tor_tools.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/stem/util/tor_tools.py b/stem/util/tor_tools.py index 424797b1..afb2e12e 100644 --- a/stem/util/tor_tools.py +++ b/stem/util/tor_tools.py @@ -21,6 +21,8 @@ Miscellaneous utility functions for working with tor.
import re
+import stem.util.str_tools + # The control-spec defines the following as... # # Fingerprint = "$" 40*HEXDIG @@ -54,6 +56,9 @@ def is_valid_fingerprint(entry, check_prefix = False): :returns: **True** if the string could be a relay fingerprint, **False** otherwise """
+ if isinstance(entry, bytes): + entry = stem.util.str_tools._to_unicode(entry) + try: if check_prefix: if not entry or entry[0] != '$': @@ -75,6 +80,9 @@ def is_valid_nickname(entry): :returns: **True** if the string could be a nickname, **False** otherwise """
+ if isinstance(entry, bytes): + entry = stem.util.str_tools._to_unicode(entry) + try: return bool(NICKNAME_PATTERN.match(entry)) except TypeError: @@ -88,6 +96,9 @@ def is_valid_circuit_id(entry): :returns: **True** if the string could be a circuit id, **False** otherwise """
+ if isinstance(entry, bytes): + entry = stem.util.str_tools._to_unicode(entry) + try: return bool(CIRC_ID_PATTERN.match(entry)) except TypeError: @@ -124,6 +135,9 @@ def is_valid_hidden_service_address(entry): :returns: **True** if the string could be a hidden service address, **False** otherwise """
+ if isinstance(entry, bytes): + entry = stem.util.str_tools._to_unicode(entry) + try: return bool(HS_ADDRESS_PATTERN.match(entry)) except TypeError:
tor-commits@lists.torproject.org