haypo/python-ipy — pull request #25 by djmitche (2014-08-25 21:46:57+00:00)
Title: Fix IPSet.__contains__ bug

This bug originally depended on dictionary ordering, which probably let it slip through the cracks for a long time. 6871815 makes the behavior consistent (and is, anyway, an optimization), but the bug exists without it. On my Python-2.7.8 system, I can reproduce the bug with
```
ipset = IPy.IPSet([IPy.IP('10.0.0.0/9'), IPy.IP('12.0.0.0/6'), IPy.IP('16.0.0.0/4'), IPy.IP('32.0.0.0/3'), IPy.IP('64.0.0.0/2'), IPy.IP('128.0.0.0/1')])
```

The bug is that `__contains__` examines 128.0.0.0/1 first, and since it's the only /1, that list of prefixes in the prefix table has length 1, and 128.0.0.0/1 sorts after the query IP, so `bisect.bisect` returns 0, correctly indicating that the query IP doesn't match any /1. However, it's too early at that point to conclude that the query IP doesn't match any other more specific prefix.