diff options
| author | Rafael H. Schloming <rhs@apache.org> | 2008-10-28 23:15:27 +0000 |
|---|---|---|
| committer | Rafael H. Schloming <rhs@apache.org> | 2008-10-28 23:15:27 +0000 |
| commit | 86ed9f4cc99564e80ba3cdd891a5608f4f35c55f (patch) | |
| tree | 9400ad35c20b6b5821274491816e6844cdd8eed0 /python/qpid/util.py | |
| parent | f2020671d5bcc87b956c3890ff7131742232dc4b (diff) | |
| download | qpid-python-86ed9f4cc99564e80ba3cdd891a5608f4f35c55f.tar.gz | |
ssl support for the python client
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@708718 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/qpid/util.py')
| -rw-r--r-- | python/qpid/util.py | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/python/qpid/util.py b/python/qpid/util.py index 1140cbe5ef..1ca616f1f5 100644 --- a/python/qpid/util.py +++ b/python/qpid/util.py @@ -17,7 +17,9 @@ # under the License. # -import os, socket, time, textwrap +import os, socket, time, textwrap, re + +ssl = socket.ssl def connect(host, port): sock = socket.socket() @@ -76,3 +78,40 @@ def fill(text, indent, heading = None): init = sub w = textwrap.TextWrapper(initial_indent = init, subsequent_indent = sub) return w.fill(" ".join(text.split())) + +class URL: + + RE = re.compile(r""" + # [ <scheme>:// ] [ <user> [ / <password> ] @] <host> [ :<port> ] + ^ (?: ([^:/@]+)://)? (?: ([^:/@]+) (?: / ([^:/@]+) )? @)? ([^@:/]+) (?: :([0-9]+))?$ +""", re.X) + + AMQPS = "amqps" + AMQP = "amqp" + + def __init__(self, s): + match = URL.RE.match(s) + if match is None: + raise ValueError(s) + self.scheme, self.user, self.password, self.host, port = match.groups() + if port is None: + self.port = None + else: + self.port = int(port) + + def __repr__(self): + return "URL(%r)" % str(self) + + def __str__(self): + s = "" + if self.scheme: + s += "%s://" % self.scheme + if self.user: + s += self.user + if self.password: + s += "/%s" % self.password + s += "@" + s += self.host + if self.port: + s += ":%s" % self.port + return s |
