[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Renaming stem.util.connection.is_valid_ip_address()
commit 08c5f3d6020c860077125a976a336f076f9b9e7c
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Fri Mar 8 09:37:35 2013 -0800
Renaming stem.util.connection.is_valid_ip_address()
Changing is_valid_ip_address() to is_valid_ipv4_address() so it'll be in better
keeping with the modules conventions now that it also supports IPv6. We might
add is_valid_ip_address() later to check if it's an IPv4 *or* IPv6 address.
---
stem/control.py | 4 ++--
stem/descriptor/extrainfo_descriptor.py | 2 +-
stem/descriptor/networkstatus.py | 6 +++---
stem/descriptor/router_status_entry.py | 4 ++--
stem/descriptor/server_descriptor.py | 4 ++--
stem/exit_policy.py | 6 +++---
stem/util/conf.py | 2 +-
stem/util/connection.py | 8 ++++----
test/integ/control/controller.py | 2 +-
test/network.py | 2 +-
test/unit/util/connection.py | 8 ++++----
11 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/stem/control.py b/stem/control.py
index 85b1c8e..d64373b 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -635,7 +635,7 @@ class Controller(BaseController):
:raises: :class:`stem.SocketError` if we're unable to establish a connection
"""
- if not stem.util.connection.is_valid_ip_address(address):
+ if not stem.util.connection.is_valid_ipv4_address(address):
raise ValueError("Invalid IP address: %s" % address)
elif not stem.util.connection.is_valid_port(port):
raise ValueError("Invalid port: %s" % port)
@@ -928,7 +928,7 @@ class Controller(BaseController):
# validate that address/ports are valid, and convert ports to ints
for addr, port in proxy_addrs:
- if not stem.util.connection.is_valid_ip_address(addr):
+ if not stem.util.connection.is_valid_ipv4_address(addr):
raise stem.ProtocolError("Invalid address for a SOCKS listener: %s" % addr)
elif not stem.util.connection.is_valid_port(port):
raise stem.ProtocolError("Invalid port for a SOCKS listener: %s" % port)
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py
index 9b0ffa3..3d7bb3c 100644
--- a/stem/descriptor/extrainfo_descriptor.py
+++ b/stem/descriptor/extrainfo_descriptor.py
@@ -502,7 +502,7 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
else:
address, port_str = value_comp[1].split(':', 1)
- if not stem.util.connection.is_valid_ip_address(address) or \
+ if not stem.util.connection.is_valid_ipv4_address(address) or \
stem.util.connection.is_valid_ipv6_address(address):
raise ValueError("Transport line has a malformed address: %s" % line)
elif not stem.util.connection.is_valid_port(port_str):
diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py
index c3fac3e..e032f76 100644
--- a/stem/descriptor/networkstatus.py
+++ b/stem/descriptor/networkstatus.py
@@ -343,7 +343,7 @@ class NetworkStatusDocumentV2(NetworkStatusDocument):
if not dir_source_comp[0]:
# https://trac.torproject.org/7055
raise ValueError("Authority's hostname can't be blank: %s" % line)
- elif not stem.util.connection.is_valid_ip_address(dir_source_comp[1]):
+ elif not stem.util.connection.is_valid_ipv4_address(dir_source_comp[1]):
raise ValueError("Authority's address isn't a valid IPv4 address: %s" % dir_source_comp[1])
elif not stem.util.connection.is_valid_port(dir_source_comp[2], allow_zero = True):
raise ValueError("Authority's DirPort is invalid: %s" % dir_source_comp[2])
@@ -1112,7 +1112,7 @@ class DirectoryAuthority(stem.descriptor.Descriptor):
elif not dir_source_comp[2]:
# https://trac.torproject.org/7055
raise ValueError("Authority's hostname can't be blank: %s" % line)
- elif not stem.util.connection.is_valid_ip_address(dir_source_comp[3]):
+ elif not stem.util.connection.is_valid_ipv4_address(dir_source_comp[3]):
raise ValueError("Authority's address isn't a valid IPv4 address: %s" % dir_source_comp[3])
elif not stem.util.connection.is_valid_port(dir_source_comp[4], allow_zero = True):
raise ValueError("Authority's DirPort is invalid: %s" % dir_source_comp[4])
@@ -1273,7 +1273,7 @@ class KeyCertificate(stem.descriptor.Descriptor):
address, dirport = value.split(':', 1)
if validate:
- if not stem.util.connection.is_valid_ip_address(address):
+ if not stem.util.connection.is_valid_ipv4_address(address):
raise ValueError("Key certificate's address isn't a valid IPv4 address: %s" % line)
elif not stem.util.connection.is_valid_port(dirport):
raise ValueError("Key certificate's dirport is invalid: %s" % line)
diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index 5a020b0..ef810ec 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -487,7 +487,7 @@ def _parse_r_line(desc, value, validate, include_digest = True):
if validate:
if not stem.util.tor_tools.is_valid_nickname(r_comp[0]):
raise ValueError("%s nickname isn't valid: %s" % (desc._name(), r_comp[0]))
- elif not stem.util.connection.is_valid_ip_address(r_comp[5]):
+ elif not stem.util.connection.is_valid_ipv4_address(r_comp[5]):
raise ValueError("%s address isn't a valid IPv4 address: %s" % (desc._name(), r_comp[5]))
elif not stem.util.connection.is_valid_port(r_comp[6]):
raise ValueError("%s ORPort is invalid: %s" % (desc._name(), r_comp[6]))
@@ -530,7 +530,7 @@ def _parse_a_line(desc, value, validate):
if is_ipv6:
address = address[1:-1] # remove brackets
- if not ((not is_ipv6 and stem.util.connection.is_valid_ip_address(address)) or
+ if not ((not is_ipv6 and stem.util.connection.is_valid_ipv4_address(address)) or
(is_ipv6 and stem.util.connection.is_valid_ipv6_address(address))):
if not validate:
return
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index b1c1cef..298b480 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -357,7 +357,7 @@ class ServerDescriptor(stem.descriptor.Descriptor):
if validate:
if not stem.util.tor_tools.is_valid_nickname(router_comp[0]):
raise ValueError("Router line entry isn't a valid nickname: %s" % router_comp[0])
- elif not stem.util.connection.is_valid_ip_address(router_comp[1]):
+ elif not stem.util.connection.is_valid_ipv4_address(router_comp[1]):
raise ValueError("Router line entry isn't a valid IPv4 address: %s" % router_comp[1])
elif not stem.util.connection.is_valid_port(router_comp[2], allow_zero = True):
raise ValueError("Router line's ORPort is invalid: %s" % router_comp[2])
@@ -523,7 +523,7 @@ class ServerDescriptor(stem.descriptor.Descriptor):
if is_ipv6:
address = address[1:-1] # remove brackets
- if not ((not is_ipv6 and stem.util.connection.is_valid_ip_address(address)) or
+ if not ((not is_ipv6 and stem.util.connection.is_valid_ipv4_address(address)) or
(is_ipv6 and stem.util.connection.is_valid_ipv6_address(address))):
if not validate:
continue
diff --git a/stem/exit_policy.py b/stem/exit_policy.py
index 475d67e..bae7af1 100644
--- a/stem/exit_policy.py
+++ b/stem/exit_policy.py
@@ -546,7 +546,7 @@ class ExitPolicyRule(object):
if address is not None:
address_type = self.get_address_type()
- if stem.util.connection.is_valid_ip_address(address):
+ if stem.util.connection.is_valid_ipv4_address(address):
if address_type == AddressType.IPv6:
return False
elif stem.util.connection.is_valid_ipv6_address(address, allow_brackets = True):
@@ -705,7 +705,7 @@ class ExitPolicyRule(object):
if addrspec == "*":
self._address_type = _address_type_to_int(AddressType.WILDCARD)
self.address = self._masked_bits = None
- elif stem.util.connection.is_valid_ip_address(self.address):
+ elif stem.util.connection.is_valid_ipv4_address(self.address):
# ipv4spec ::= ip4 | ip4 "/" num_ip4_bits | ip4 "/" ip4mask
# ip4 ::= an IPv4 address in dotted-quad format
# ip4mask ::= an IPv4 mask in dotted-quad format
@@ -715,7 +715,7 @@ class ExitPolicyRule(object):
if addr_extra is None:
self._masked_bits = 32
- elif stem.util.connection.is_valid_ip_address(addr_extra):
+ elif stem.util.connection.is_valid_ipv4_address(addr_extra):
# provided with an ip4mask
try:
self._masked_bits = stem.util.connection.get_masked_bits(addr_extra)
diff --git a/stem/util/conf.py b/stem/util/conf.py
index 292e3d5..795cd82 100644
--- a/stem/util/conf.py
+++ b/stem/util/conf.py
@@ -57,7 +57,7 @@ To do this use the :func:`~stem.util.conf.config_dict` function. For example...
# require at least a one second timeout
return max(1, value)
elif key == "endpoint":
- if not connection.is_valid_ip_address(value):
+ if not connection.is_valid_ipv4_address(value):
raise ValueError("'%s' isn't a valid IPv4 address" % value)
elif key == "port":
if not connection.is_valid_port(value):
diff --git a/stem/util/connection.py b/stem/util/connection.py
index 90961fc..52a3954 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -9,7 +9,7 @@ but for now just moving the parts we need.
::
- is_valid_ip_address - checks if a string is a valid IPv4 address
+ is_valid_ipv4_address - checks if a string is a valid IPv4 address
is_valid_ipv6_address - checks if a string is a valid IPv6 address
is_valid_port - checks if something is a valid representation for a port
expand_ipv6_address - provides an IPv6 address with its collapsed portions expanded
@@ -34,7 +34,7 @@ FULL_IPv4_MASK = "255.255.255.255"
FULL_IPv6_MASK = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"
-def is_valid_ip_address(address):
+def is_valid_ipv4_address(address):
"""
Checks if a string is a valid IPv4 address.
@@ -202,7 +202,7 @@ def get_masked_bits(mask):
:raises: **ValueError** if the mask is invalid or can't be converted
"""
- if not is_valid_ip_address(mask):
+ if not is_valid_ipv4_address(mask):
raise ValueError("'%s' is an invalid subnet mask" % mask)
# converts octets to binary representation
@@ -264,7 +264,7 @@ def get_address_binary(address):
:raises: **ValueError** if address is neither an IPv4 nor IPv6 address
"""
- if is_valid_ip_address(address):
+ if is_valid_ipv4_address(address):
return "".join([get_binary(int(octet), 8) for octet in address.split(".")])
elif is_valid_ipv6_address(address):
address = expand_ipv6_address(address)
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index b93b802..f35932f 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -797,7 +797,7 @@ class TestController(unittest.TestCase):
# The response data for our request for request should be an IP address + '\n'
ip_addr = response[response.find("\r\n\r\n"):].strip()
- self.assertTrue(stem.util.connection.is_valid_ip_address(ip_addr))
+ self.assertTrue(stem.util.connection.is_valid_ipv4_address(ip_addr))
def test_get_microdescriptor(self):
"""
diff --git a/test/network.py b/test/network.py
index c8f0e97..2d4d9ba 100644
--- a/test/network.py
+++ b/test/network.py
@@ -202,7 +202,7 @@ class Socks(_socket_socket):
if response != SOCKS5_NOAUTH_RESPONSE:
raise SocksError(0x01)
- if stem.util.connection.is_valid_ip_address(address[0]):
+ if stem.util.connection.is_valid_ipv4_address(address[0]):
header = self._ints_to_bytes(SOCKS5_CONN_BY_IPV4)
header = header + socket.inet_aton(address[0])
else:
diff --git a/test/unit/util/connection.py b/test/unit/util/connection.py
index 756852b..c7db6d3 100644
--- a/test/unit/util/connection.py
+++ b/test/unit/util/connection.py
@@ -8,9 +8,9 @@ import stem.util.connection
class TestConnection(unittest.TestCase):
- def test_is_valid_ip_address(self):
+ def test_is_valid_ipv4_address(self):
"""
- Checks the is_valid_ip_address function.
+ Checks the is_valid_ipv4_address function.
"""
valid_addresses = (
@@ -30,10 +30,10 @@ class TestConnection(unittest.TestCase):
)
for address in valid_addresses:
- self.assertTrue(stem.util.connection.is_valid_ip_address(address))
+ self.assertTrue(stem.util.connection.is_valid_ipv4_address(address))
for address in invalid_addresses:
- self.assertFalse(stem.util.connection.is_valid_ip_address(address))
+ self.assertFalse(stem.util.connection.is_valid_ipv4_address(address))
def test_is_valid_ipv6_address(self):
"""
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits