[Python-checkins] r73136 - in python/branches/py3k: Lib/ipaddr.py Lib/test/test_ipaddr.py

gregory.p.smith python-checkins at python.org
Tue Jun 2 07:29:38 CEST 2009


Author: gregory.p.smith
Date: Tue Jun  2 07:29:37 2009
New Revision: 73136

Log:
Merged revisions 73135 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r73135 | gregory.p.smith | 2009-06-01 22:25:34 -0700 (Mon, 01 Jun 2009) | 3 lines
  
  Fixes issue6169: it was possible for two ipaddr network addresses to compare
  as both < and > than eachother.
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/ipaddr.py
   python/branches/py3k/Lib/test/test_ipaddr.py

Modified: python/branches/py3k/Lib/ipaddr.py
==============================================================================
--- python/branches/py3k/Lib/ipaddr.py	(original)
+++ python/branches/py3k/Lib/ipaddr.py	Tue Jun  2 07:29:37 2009
@@ -10,7 +10,7 @@
 
 """
 
-__version__ = '1.1.0'
+__version__ = '1.1.1'
 
 import struct
 
@@ -206,17 +206,25 @@
 
     def __lt__(self, other):
         try:
-            return (self.version < other.version
-                    or self.ip < other.ip
-                    or self.netmask < other.netmask)
+            if self.version != other.version:
+                return self.version < other.version
+            if self.ip != other.ip:
+                return self.ip < other.ip
+            if self.netmask != other.netmask:
+                return self.netmask < other.netmask
+            return False
         except AttributeError:
             return NotImplemented
 
     def __gt__(self, other):
         try:
-            return (self.version > other.version
-                    or self.ip > other.ip
-                    or self.netmask > other.netmask)
+            if self.version != other.version:
+                return self.version > other.version
+            if self.ip != other.ip:
+                return self.ip > other.ip
+            if self.netmask != other.netmask:
+                return self.netmask > other.netmask
+            return False
         except AttributeError:
             return NotImplemented
 

Modified: python/branches/py3k/Lib/test/test_ipaddr.py
==============================================================================
--- python/branches/py3k/Lib/test/test_ipaddr.py	(original)
+++ python/branches/py3k/Lib/test/test_ipaddr.py	Tue Jun  2 07:29:37 2009
@@ -1,18 +1,6 @@
 # Copyright 2007 Google Inc.
 #  Licensed to PSF under a Contributor Agreement.
 #
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
 # See also:  http://code.google.com/p/ipaddr-py/
 
 """Unittest for ipaddr module."""
@@ -393,6 +381,21 @@
         self.assertTrue(ipv6 > ipv4)
         self.assertTrue(ipv4 < ipv6)
 
+        # Regression test for issue6169 (ipaddr-py issue 19)
+        ip1 = ipaddr.IP('10.1.2.128/25')
+        self.assertFalse(ip1 < ip1)
+        self.assertFalse(ip1 > ip1)
+        ip2 = ipaddr.IP('10.1.3.0/24')
+        self.assertTrue(ip1 < ip2)
+        self.assertFalse(ip2 < ip1)
+        self.assertFalse(ip1 > ip2)
+        self.assertTrue(ip2 > ip1)
+        ip3 = ipaddr.IP('10.1.3.0/25')
+        self.assertTrue(ip2 < ip3)
+        self.assertFalse(ip3 < ip2)
+        self.assertFalse(ip2 > ip3)
+        self.assertTrue(ip3 > ip2)
+
     def test_embedded_ipv4(self):
         ipv4_string = '192.168.0.1'
         ipv4 = ipaddr.IPv4(ipv4_string)


More information about the Python-checkins mailing list