[tor-commits] [bridgedb/develop] Remove bridgedb.Bridges.is_valid_ip().
isis at torproject.org
isis at torproject.org
Thu Feb 19 02:21:15 UTC 2015
commit e1ad705670de064d22ababc78f4f38393a8dbf97
Author: Isis Lovecruft <isis at torproject.org>
Date: Tue Feb 10 07:34:08 2015 +0000
Remove bridgedb.Bridges.is_valid_ip().
---
lib/bridgedb/Bridges.py | 34 ----------------------------------
lib/bridgedb/HTTPServer.py | 5 +++--
2 files changed, 3 insertions(+), 36 deletions(-)
diff --git a/lib/bridgedb/Bridges.py b/lib/bridgedb/Bridges.py
index a5d142f..9e7c292 100644
--- a/lib/bridgedb/Bridges.py
+++ b/lib/bridgedb/Bridges.py
@@ -42,40 +42,6 @@ DIGEST_LEN = 20
PORTSPEC_LEN = 16
-def is_valid_ip(ip):
- """Return True if ip is the string encoding of a valid IPv4 address,
- and False otherwise.
-
- XXX this should probably be deprecated in favour of
- :func:`bridgedb.parse.addr.isValid`.
-
- >>> from bridgedb import Bridges
- >>> Bridges.is_valid_ip('1.2.3.4')
- True
- >>> Bridges.is_valid_ip('1.2.3.255')
- True
- >>> Bridges.is_valid_ip('1.2.3.256')
- False
- >>> Bridges.is_valid_ip('1')
- False
- >>> Bridges.is_valid_ip('1.2.3')
- False
- >>> Bridges.is_valid_ip('xyzzy')
- False
-
- :param str ip: A string representing an IPv4 or IPv6 address.
- """
- logging.warn(PendingDeprecationWarning(
- "Bridges.is_valid_ip() is replaced with parse.isIPAddress()"))
- # ipaddr does not treat "1.2" as a synonym for "0.0.1.2"
- try:
- ipaddr.IPAddress(ip)
- except ValueError:
- # not a valid IPv4 or IPv6 address
- return False
- return True
-
-
def getDescriptorDigests(desc):
"""Return the SHA-1 hash hexdigests of all descriptor descs
diff --git a/lib/bridgedb/HTTPServer.py b/lib/bridgedb/HTTPServer.py
index b073542..389d5a4 100644
--- a/lib/bridgedb/HTTPServer.py
+++ b/lib/bridgedb/HTTPServer.py
@@ -49,6 +49,7 @@ from bridgedb.Filters import filterBridgesByIP6
from bridgedb.Filters import filterBridgesByTransport
from bridgedb.Filters import filterBridgesByNotBlockedIn
from bridgedb.parse import headers
+from bridgedb.parse.addr import isIPAddress
from bridgedb.qrcodes import generateQR
from bridgedb.safelog import logSafely
@@ -158,7 +159,7 @@ class CaptchaProtectedResource(resource.Resource):
h = request.getHeader("X-Forwarded-For")
if h:
ip = h.split(",")[-1].strip()
- if not bridgedb.Bridges.is_valid_ip(ip):
+ if not isIPAddress(ip):
logging.warn("Got weird X-Forwarded-For value %r" % h)
ip = None
else:
@@ -684,7 +685,7 @@ class WebResourceBridges(resource.Resource):
h = request.getHeader("X-Forwarded-For")
if h:
ip = h.split(",")[-1].strip()
- if not bridgedb.Bridges.is_valid_ip(ip):
+ if not isIPAddress(ip):
logging.warn("Got weird forwarded-for value %r",h)
ip = None
else:
More information about the tor-commits
mailing list