[tor-commits] [stem/master] Make stem.util.connection.is_valid_port accept a list
atagar at torproject.org
atagar at torproject.org
Thu Jul 19 16:01:03 UTC 2012
commit b51d8da9bd2a6d4377019b37bbad768ad8ba17ca
Author: Sathyanarayanan Gunasekaran <gsathya.ceg at gmail.com>
Date: Tue Jun 26 08:48:23 2012 +0530
Make stem.util.connection.is_valid_port accept a list
Iterate through the list and check if each item is a valid
port or not.
---
stem/util/connection.py | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/stem/util/connection.py b/stem/util/connection.py
index 03dced9..13f2d47 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -65,13 +65,18 @@ def is_valid_port(entry, allow_zero = False):
"""
Checks if a string or int is a valid port number.
- :param str,int entry: string or integer to be checked
+ :param list, str, int entry: string, integer or list to be checked
:param bool allow_zero: accept port number of zero (reserved by defintion)
:returns: True if input is an integer and within the valid port range, False otherwise
"""
- if isinstance(entry, str):
+ if isinstance(entry, list):
+ for port in entry:
+ if not is_valid_port(port):
+ return False
+
+ elif isinstance(entry, str):
if not entry.isdigit():
return False
elif entry[0] == "0" and len(entry) > 1:
More information about the tor-commits
mailing list