zhikrullah / pyshp

Automatically exported from code.google.com/p/pyshp
MIT License
0 stars 0 forks source link

negative indexes are not well handled in "__restrictIndex" method #31

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. open (Reader) a shapefile (with N elements)
2. call the "shape" method with the value -N (which is valid !)

The expected value is the first (index 0) shape object but an exception is 
raised in __restricted index after the test at line 194 (version 1.1.4).

The code below fix the bug

def __restrictIndex(self, i):
    """Provides list-like handling of a record index with a clearer
    error message if the index is out of bounds."""
    if self.numRecords:
        if i < -self.numRecords or self.numRecords <= i:
            raise IndexError("Shape or Record index out of range.")
        if i < 0: i += self.numRecords
    return i

Original issue reported on code.google.com by pa.ler...@gmail.com on 9 Apr 2012 at 10:27

GoogleCodeExporter commented 8 years ago

Original comment by jlawh...@geospatialpython.com on 13 Apr 2012 at 3:54