Stem Docs

Tor Utilities

Tor Utilities

Miscellaneous utility functions for working with tor.

New in version 1.2.0.

Module Overview:

is_valid_fingerprint - checks if a string is a valid tor relay fingerprint
is_valid_nickname - checks if a string is a valid tor relay nickname
is_valid_circuit_id - checks if a string is a valid tor circuit id
is_valid_stream_id - checks if a string is a valid tor stream id
is_valid_connection_id - checks if a string is a valid tor connection id
is_valid_hidden_service_address - checks if a string is a valid hidden service address
is_hex_digits - checks if a string is only made up of hex digits
stem.util.tor_tools.is_valid_fingerprint(entry, check_prefix=False)[source]

Checks if a string is a properly formatted relay fingerprint. This checks for a '$' prefix if check_prefix is true, otherwise this only validates the hex digits.

Parameters:
  • entry (str) -- string to be checked
  • check_prefix (bool) -- checks for a '$' prefix
Returns:

True if the string could be a relay fingerprint, False otherwise

stem.util.tor_tools.is_valid_nickname(entry)[source]

Checks if a string is a valid format for being a nickname.

Parameters:entry (str) -- string to be checked
Returns:True if the string could be a nickname, False otherwise
stem.util.tor_tools.is_valid_circuit_id(entry)[source]

Checks if a string is a valid format for being a circuit identifier.

Returns:True if the string could be a circuit id, False otherwise
stem.util.tor_tools.is_valid_stream_id(entry)[source]

Checks if a string is a valid format for being a stream identifier. Currently, this is just an alias to is_valid_circuit_id().

Returns:True if the string could be a stream id, False otherwise
stem.util.tor_tools.is_valid_connection_id(entry)

Checks if a string is a valid format for being a connection identifier. Currently, this is just an alias to is_valid_circuit_id().

Returns:True if the string could be a connection id, False otherwise
stem.util.tor_tools.is_valid_hidden_service_address(entry)

Checks if a string is a valid format for being a hidden service address (not including the '.onion' suffix).

Returns:True if the string could be a hidden service address, False otherwise
stem.util.tor_tools.is_hex_digits(entry, count)[source]

Checks if a string is the given number of hex digits. Digits represented by letters are case insensitive.

Parameters:
  • entry (str) -- string to be checked
  • count (int) -- number of hex digits to be checked for
Returns:

True if the given number of hex digits, False otherwise