qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astitc...@apache.org
Subject svn commit: r1157277 - /qpid/trunk/qpid/python/qpid/util.py
Date Fri, 12 Aug 2011 22:32:48 GMT
Author: astitcher
Date: Fri Aug 12 22:32:47 2011
New Revision: 1157277

URL: http://svn.apache.org/viewvc?rev=1157277&view=rev
Log:
QPID-3407: Change python connection url to allow ipv6 literal style addresses.
Eg. "amqp://[::1]:5762"

Modified:
    qpid/trunk/qpid/python/qpid/util.py

Modified: qpid/trunk/qpid/python/qpid/util.py
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/python/qpid/util.py?rev=1157277&r1=1157276&r2=1157277&view=diff
==============================================================================
--- qpid/trunk/qpid/python/qpid/util.py (original)
+++ qpid/trunk/qpid/python/qpid/util.py Fri Aug 12 22:32:47 2011
@@ -106,15 +106,23 @@ def fill(text, indent, heading = None):
 class URL:
 
   RE = re.compile(r"""
-        # [   <scheme>://  ] [    <user>   [   / <password>   ] @]   <host>
  [   :<port>   ]
-        ^ (?: ([^:/@]+)://)? (?: ([^:/@]+) (?: / ([^:/@]+)   )? @)? ([^@:/]+) (?: :([0-9]+))?$
-""", re.X)
+        # [   <scheme>://  ] [    <user>   [   / <password>   ] @]    (
<host4>     | \[    <host6>    \] )  [   :<port>   ]
+        ^ (?: ([^:/@]+)://)? (?: ([^:/@]+) (?: / ([^:/@]+)   )? @)? (?: ([^@:/\[]+) | \[
([a-f0-9:.]+) \] ) (?: :([0-9]+))?$
+""", re.X | re.I)
 
   AMQPS = "amqps"
   AMQP = "amqp"
 
-  def __init__(self, s):
-    if isinstance(s, URL):
+  def __init__(self, s=None, **kwargs):
+    if s is None:
+      self.scheme = kwargs.get('scheme', None)
+      self.user = kwargs.get('user', None)
+      self.password = kwargs.get('password', None)
+      self.host = kwargs.get('host', None)
+      self.port = kwargs.get('port', None)
+      if self.host is None:
+        raise ValueError('Host required for url')
+    elif isinstance(s, URL):
       self.scheme = s.scheme
       self.user = s.user
       self.password = s.password
@@ -124,7 +132,8 @@ class URL:
       match = URL.RE.match(s)
       if match is None:
         raise ValueError(s)
-      self.scheme, self.user, self.password, self.host, port = match.groups()
+      self.scheme, self.user, self.password, host4, host6, port = match.groups()
+      self.host = host4 or host6
       if port is None:
         self.port = None
       else:
@@ -142,11 +151,22 @@ class URL:
       if self.password:
         s += "/%s" % self.password
       s += "@"
-    s += self.host
+    s += self.host if ':' not in self.host else "[%s]" % self.host
     if self.port:
       s += ":%s" % self.port
     return s
 
+  def __eq__(self, url):
+    if isinstance(url, basestring):
+      url = URL(url)
+    return \
+      self.scheme==url.scheme and \
+      self.user==url.user and self.password==url.password and \
+      self.host==url.host and self.port==url.port
+
+  def __ne__(self, url):
+    return not self.__eq__(url)
+
 def default(value, default):
   if value is None:
     return default



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message