@@ -26,9 +26,38 @@ def testNoPortGiven(self):
2626 self .assertEqual (server .host , os .environ ['MEMCACHED_HOST' ])
2727 self .assertEqual (server .port , 11211 )
2828
29+ def testIPv6 (self ):
30+ server = bmemcached .protocol .Protocol ('[::1]' )
31+ self .assertEqual (server .host , '::1' )
32+ self .assertEqual (server .port , 11211 )
33+ server = bmemcached .protocol .Protocol ('::1' )
34+ self .assertEqual (server .host , '::1' )
35+ self .assertEqual (server .port , 11211 )
36+ server = bmemcached .protocol .Protocol ('[2001:db8::2]' )
37+ self .assertEqual (server .host , '2001:db8::2' )
38+ self .assertEqual (server .port , 11211 )
39+ server = bmemcached .protocol .Protocol ('2001:db8::2' )
40+ self .assertEqual (server .host , '2001:db8::2' )
41+ self .assertEqual (server .port , 11211 )
42+ # Since `2001:db8::2:8080` is a valid IPv6 address,
43+ # it is ambiguous whether to split it into `2001:db8::2` and `8080`
44+ # or treat it as `2001:db8::2:8080`.
45+ # Therefore, it will be treated as `2001:db8::2:8080`.
46+ server = bmemcached .protocol .Protocol ('2001:db8::2:8080' )
47+ self .assertEqual (server .host , '2001:db8::2:8080' )
48+ self .assertEqual (server .port , 11211 )
49+ server = bmemcached .protocol .Protocol ('[::1]:5000' )
50+ self .assertEqual (server .host , '::1' )
51+ self .assertEqual (server .port , 5000 )
52+ server = bmemcached .protocol .Protocol ('[2001:db8::2]:5000' )
53+ self .assertEqual (server .host , '2001:db8::2' )
54+ self .assertEqual (server .port , 5000 )
55+
2956 def testInvalidPort (self ):
3057 with self .assertRaises (ValueError ):
3158 bmemcached .protocol .Protocol ('{}:blah' .format (os .environ ['MEMCACHED_HOST' ]))
59+ with self .assertRaises (ValueError ):
60+ bmemcached .protocol .Protocol ('[::1]:blah' )
3261
3362 def testNonStandardPort (self ):
3463 server = bmemcached .protocol .Protocol ('{}:5000' .format (os .environ ['MEMCACHED_HOST' ]))
0 commit comments