diff options
author | Stephen D. Huston <shuston@apache.org> | 2011-10-21 01:19:00 +0000 |
---|---|---|
committer | Stephen D. Huston <shuston@apache.org> | 2011-10-21 01:19:00 +0000 |
commit | ebfd9ff053b04ab379acfc0fefedee5a31b6d8a5 (patch) | |
tree | dcfb94e75656c6c239fc3dcb754cd2015126424d /python/qpid/util.py | |
parent | 5eb354b338bb8d8fcd35b6ac3fb33f8103e757c3 (diff) | |
download | qpid-python-ebfd9ff053b04ab379acfc0fefedee5a31b6d8a5.tar.gz |
Undo bad merge from trunk - merged at wrong level.
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/QPID-2519@1187150 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/qpid/util.py')
-rw-r--r-- | python/qpid/util.py | 54 |
1 files changed, 13 insertions, 41 deletions
diff --git a/python/qpid/util.py b/python/qpid/util.py index 89677289e2..e62bebdf24 100644 --- a/python/qpid/util.py +++ b/python/qpid/util.py @@ -39,17 +39,12 @@ except ImportError: self.sock.close() def connect(host, port): - for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM): - af, socktype, proto, canonname, sa = res - sock = socket.socket(af, socktype, proto) - try: - sock.connect(sa) - break - except socket.error, msg: - sock.close - else: - # If we got here then we couldn't connect (yet) - raise + sock = socket.socket() + sock.connect((host, port)) + sock.setblocking(1) + # XXX: we could use this on read, but we'd have to put write in a + # loop as well + # sock.settimeout(1) return sock def listen(host, port, predicate = lambda: True, bound = lambda: None): @@ -106,23 +101,15 @@ def fill(text, indent, heading = None): class URL: RE = re.compile(r""" - # [ <scheme>:// ] [ <user> [ / <password> ] @] ( <host4> | \[ <host6> \] ) [ :<port> ] - ^ (?: ([^:/@]+)://)? (?: ([^:/@]+) (?: / ([^:/@]+) )? @)? (?: ([^@:/\[]+) | \[ ([a-f0-9:.]+) \] ) (?: :([0-9]+))?$ -""", re.X | re.I) + # [ <scheme>:// ] [ <user> [ / <password> ] @] <host> [ :<port> ] + ^ (?: ([^:/@]+)://)? (?: ([^:/@]+) (?: / ([^:/@]+) )? @)? ([^@:/]+) (?: :([0-9]+))?$ +""", re.X) AMQPS = "amqps" AMQP = "amqp" - 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): + def __init__(self, s): + if isinstance(s, URL): self.scheme = s.scheme self.user = s.user self.password = s.password @@ -132,8 +119,7 @@ class URL: match = URL.RE.match(s) if match is None: raise ValueError(s) - self.scheme, self.user, self.password, host4, host6, port = match.groups() - self.host = host4 or host6 + self.scheme, self.user, self.password, self.host, port = match.groups() if port is None: self.port = None else: @@ -151,25 +137,11 @@ class URL: if self.password: s += "/%s" % self.password s += "@" - if ':' not in self.host: - s += self.host - else: - s += "[%s]" % self.host + 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 |