commit fd2df35dc9cdc27c24423f7905f60cc222e27a6d
Author: David Fifield <da...@bamsoftware.com>
Date:   Tue Sep 11 08:56:38 2012 -0700

    Make parse_addr_spec pass new tests.
---
 facilitator/fac.py  |   23 ++++++++++-------------
 flashproxy-client   |   23 ++++++++++-------------
 flashproxy-reg-http |   23 ++++++++++-------------
 3 files changed, 30 insertions(+), 39 deletions(-)

diff --git a/facilitator/fac.py b/facilitator/fac.py
index 2382d2b..494b378 100644
--- a/facilitator/fac.py
+++ b/facilitator/fac.py
@@ -29,32 +29,29 @@ def parse_addr_spec(spec, defhost = None, defport = None, 
resolve = False):
     IPv6 addresses must be enclosed in square brackets."""
     host = None
     port = None
+    af = 0
     m = None
     # IPv6 syntax.
     if not m:
-        m = re.match(ur'^\[(.+)\]:(\d+)$', spec)
+        m = re.match(ur'^\[(.+)\]:(\d*)$', spec)
         if m:
             host, port = m.groups()
             af = socket.AF_INET6
     if not m:
-        m = re.match(ur'^\[(.+)\]:?$', spec)
+        m = re.match(ur'^\[(.+)\]$', spec)
         if m:
             host, = m.groups()
             af = socket.AF_INET6
-    # IPv4 syntax.
+    # IPv4/hostname/port-only syntax.
     if not m:
-        m = re.match(ur'^(.+):(\d+)$', spec)
-        if m:
-            host, port = m.groups()
+        try:
+            host, port = spec.split(":", 1)
+        except ValueError:
+            host = spec
+        if re.match(ur'^[\d.]+$', host):
             af = socket.AF_INET
-    if not m:
-        m = re.match(ur'^:?(\d+)$', spec)
-        if m:
-            port, = m.groups()
+        else:
             af = 0
-    if not m:
-        host = spec
-        af = 0
     host = host or defhost
     port = port or defport
     if host is None or port is None:
diff --git a/flashproxy-client b/flashproxy-client
index f5c9a8b..6f7477e 100755
--- a/flashproxy-client
+++ b/flashproxy-client
@@ -95,32 +95,29 @@ def log(msg):
 def parse_addr_spec(spec, defhost = None, defport = None):
     host = None
     port = None
+    af = 0
     m = None
     # IPv6 syntax.
     if not m:
-        m = re.match(ur'^\[(.+)\]:(\d+)$', spec)
+        m = re.match(ur'^\[(.+)\]:(\d*)$', spec)
         if m:
             host, port = m.groups()
             af = socket.AF_INET6
     if not m:
-        m = re.match(ur'^\[(.+)\]:?$', spec)
+        m = re.match(ur'^\[(.+)\]$', spec)
         if m:
             host, = m.groups()
             af = socket.AF_INET6
-    # IPv4 syntax.
+    # IPv4/hostname/port-only syntax.
     if not m:
-        m = re.match(ur'^(.+):(\d+)$', spec)
-        if m:
-            host, port = m.groups()
+        try:
+            host, port = spec.split(":", 1)
+        except ValueError:
+            host = spec
+        if re.match(ur'^[\d.]+$', host):
             af = socket.AF_INET
-    if not m:
-        m = re.match(ur'^:?(\d+)$', spec)
-        if m:
-            port, = m.groups()
+        else:
             af = 0
-    if not m:
-        host = spec
-        af = 0
     host = host or defhost
     port = port or defport
     if port is not None:
diff --git a/flashproxy-reg-http b/flashproxy-reg-http
index e17abdf..4372c1f 100755
--- a/flashproxy-reg-http
+++ b/flashproxy-reg-http
@@ -34,32 +34,29 @@ remote address registered is "%(remote_addr)s".
 def parse_addr_spec(spec, defhost = None, defport = None):
     host = None
     port = None
+    af = 0
     m = None
     # IPv6 syntax.
     if not m:
-        m = re.match(ur'^\[(.+)\]:(\d+)$', spec)
+        m = re.match(ur'^\[(.+)\]:(\d*)$', spec)
         if m:
             host, port = m.groups()
             af = socket.AF_INET6
     if not m:
-        m = re.match(ur'^\[(.+)\]:?$', spec)
+        m = re.match(ur'^\[(.+)\]$', spec)
         if m:
             host, = m.groups()
             af = socket.AF_INET6
-    # IPv4 syntax.
+    # IPv4/hostname/port-only syntax.
     if not m:
-        m = re.match(ur'^(.+):(\d+)$', spec)
-        if m:
-            host, port = m.groups()
+        try:
+            host, port = spec.split(":", 1)
+        except ValueError:
+            host = spec
+        if re.match(ur'^[\d.]+$', host):
             af = socket.AF_INET
-    if not m:
-        m = re.match(ur'^:?(\d+)$', spec)
-        if m:
-            port, = m.groups()
+        else:
             af = 0
-    if not m:
-        host = spec
-        af = 0
     host = host or defhost
     port = port or defport
     if port is not None:

_______________________________________________
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to