[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [flashproxy/master] Allow omitting the port in parse_addr_spec and format_addr.



commit 887b6eebd7505ef5d8d58d46b79f46c48ce7c0aa
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Thu Aug 30 15:17:13 2012 -0700

    Allow omitting the port in parse_addr_spec and format_addr.
---
 flashproxy-client   |   13 ++++++++-----
 flashproxy-reg-http |   13 ++++++++-----
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/flashproxy-client b/flashproxy-client
index 0dfe8c7..74c2a74 100755
--- a/flashproxy-client
+++ b/flashproxy-client
@@ -123,9 +123,9 @@ def parse_addr_spec(spec, defhost = None, defport = None):
         af = 0
     host = host or defhost
     port = port or defport
-    if not port:
-        raise ValueError("Bad address specification \"%s\"" % spec)
-    return host, int(port)
+    if port is not None:
+        port = int(port)
+    return host, port
 
 def format_addr(addr):
     host, port = addr
@@ -138,9 +138,12 @@ def format_addr(addr):
     except socket.gaierror, e:
         af = 0
     if af == socket.AF_INET6:
-        return u"[%s]:%d" % (host, port)
+        result = u"[%s]" % host
     else:
-        return u"%s:%d" % (host, port)
+        result = "%s" % host
+    if port is not None:
+        result += u":%d" % port
+    return result
 
 def safe_format_addr(addr):
     return safe_str(format_addr(addr))
diff --git a/flashproxy-reg-http b/flashproxy-reg-http
index 4cff231..6b0310f 100755
--- a/flashproxy-reg-http
+++ b/flashproxy-reg-http
@@ -61,9 +61,9 @@ def parse_addr_spec(spec, defhost = None, defport = None):
         af = 0
     host = host or defhost
     port = port or defport
-    if not port:
-        raise ValueError("Bad address specification \"%s\"" % spec)
-    return host, int(port)
+    if port is not None:
+        port = int(port)
+    return host, port
 
 def format_addr(addr):
     host, port = addr
@@ -76,9 +76,12 @@ def format_addr(addr):
     except socket.gaierror, e:
         af = 0
     if af == socket.AF_INET6:
-        return u"[%s]:%d" % (host, port)
+        result = u"[%s]" % host
     else:
-        return u"%s:%d" % (host, port)
+        result = "%s" % host
+    if port is not None:
+        result += u":%d" % port
+    return result
 
 options.facilitator_addr = (DEFAULT_FACILITATOR_HOST, DEFAULT_FACILITATOR_PORT)
 options.remote_addr = (DEFAULT_REMOTE_ADDRESS, DEFAULT_REMOTE_PORT)



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