jsommers / pytricia

A library for fast IP address lookup in Python.
GNU Lesser General Public License v3.0
216 stars 22 forks source link

Some methods generate undefined exceptions #8

Closed zorun closed 8 years ago

zorun commented 8 years ago

There seems to be some error cases where methods exit with a NULL pointer, but no exception is defined. This results in a SystemError exception, which is surprising to the user:

>>> pyt['foo.bar']
SystemError: error return without exception set
>>> pyt['2001:db8:/32'] # Notice the missing column at the end
SystemError: error return without exception set

In this case, a KeyError exception would be expected.

This seems related to the prefix parsing code, but there may be other places as well.

jsommers commented 8 years ago

Thanks for this. Yes, I agree that KeyError would be sensible in that case, and I'm sure there are other situations where exceptions are not being thrown as should be expected. I'll get to this when I can.

jsommers commented 8 years ago

The obvious occurrences are fixed. Please re-open if you find any additional occurrences --- thanks.

lithammer commented 5 years ago

This happens for the loopback version of IPv6 (i.e. ::1). Both when inserting and searching.

>>> import pytricia
>>> tree = pytricia.PyTricia(128)
>>> tree["::1"] = None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: error return without exception set
>>> tree["::1"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Invalid prefix.

It works fine with ::1/128 though.