diff options
author | Sean Reifschneider <jafo@tummy.com> | 2013-03-28 18:07:41 -0600 |
---|---|---|
committer | Sean Reifschneider <jafo@tummy.com> | 2013-03-28 18:07:41 -0600 |
commit | d997b2e8813172a083947ef08696cd25b7a2ea3a (patch) | |
tree | c85a7a9fcd2c4e7a1dcb39eeeb97d7b158fe628c | |
parent | ad1c231facc078f92ed83d1a174ecdecbae2b5d0 (diff) | |
download | python-memcached-d997b2e8813172a083947ef08696cd25b7a2ea3a.tar.gz |
Adding patch for IPv6 connection string.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | memcache.py | 14 |
2 files changed, 17 insertions, 0 deletions
@@ -1,3 +1,6 @@ + * Supports IPv6 connections using: "inet6:[fd00::32:19f7]:11000". + Patch by Romain Courteaud + * Switching over to github for this project: https://github.com/linsomniac diff --git a/memcache.py b/memcache.py index 34a547d..f729c8c 100644 --- a/memcache.py +++ b/memcache.py @@ -264,6 +264,8 @@ class Client(local): if not s.connect(): continue if s.family == socket.AF_INET: name = '%s:%s (%s)' % ( s.ip, s.port, s.weight ) + elif s.family == socket.AF_INET6: + name = '[%s]:%s (%s)' % ( s.ip, s.port, s.weight ) else: name = 'unix:%s (%s)' % ( s.address, s.weight ) if not stat_args: @@ -287,6 +289,8 @@ class Client(local): if not s.connect(): continue if s.family == socket.AF_INET: name = '%s:%s (%s)' % ( s.ip, s.port, s.weight ) + elif s.family == socket.AF_INET6: + name = '[%s]:%s (%s)' % ( s.ip, s.port, s.weight ) else: name = 'unix:%s (%s)' % ( s.address, s.weight ) serverData = {} @@ -1054,6 +1058,9 @@ class _Host(object): # parse the connection string m = re.match(r'^(?P<proto>unix):(?P<path>.*)$', host) if not m: + m = re.match(r'^(?P<proto>inet6):' + r'\[(?P<host>[^\[\]]+)\](:(?P<port>[0-9]+))?$', host) + if not m: m = re.match(r'^(?P<proto>inet):' r'(?P<host>[^:]+)(:(?P<port>[0-9]+))?$', host) if not m: m = re.match(r'^(?P<host>[^:]+)(:(?P<port>[0-9]+))?$', host) @@ -1064,6 +1071,11 @@ class _Host(object): if hostData.get('proto') == 'unix': self.family = socket.AF_UNIX self.address = hostData['path'] + elif hostData.get('proto') == 'inet6': + self.family = socket.AF_INET6 + self.ip = hostData['host'] + self.port = int(hostData.get('port') or 11211) + self.address = ( self.ip, self.port ) else: self.family = socket.AF_INET self.ip = hostData['host'] @@ -1187,6 +1199,8 @@ class _Host(object): if self.family == socket.AF_INET: return "inet:%s:%d%s" % (self.address[0], self.address[1], d) + elif self.family == socket.AF_INET6: + return "inet6:[%s]:%d%s" % (self.address[0], self.address[1], d) else: return "unix:%s%s" % (self.address, d) |