Commit 197b1878 authored by Tim Graham's avatar Tim Graham
Browse files

Fixed #25225 -- Simplified code to remove GEOSIndexError

The test is a regression for refs #4740 to show that the original
fix of GEOSIndexError is no longer needed.
parent 20787b5c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ for more details: https://docs.djangoproject.com/en/dev/ref/contrib/gis/geos/
from .collections import (  # NOQA
    GeometryCollection, MultiLineString, MultiPoint, MultiPolygon,
)
from .error import GEOSException, GEOSIndexError  # NOQA
from .error import GEOSException  # NOQA
from .factory import fromfile, fromstr  # NOQA
from .geometry import GEOSGeometry, hex_regex, wkt_regex  # NOQA
from .io import WKBReader, WKBWriter, WKTReader, WKTWriter  # NOQA
+2 −2
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ from ctypes import byref, c_double, c_uint

from django.contrib.gis.geos import prototypes as capi
from django.contrib.gis.geos.base import GEOSBase
from django.contrib.gis.geos.error import GEOSException, GEOSIndexError
from django.contrib.gis.geos.error import GEOSException
from django.contrib.gis.geos.libgeos import CS_PTR
from django.contrib.gis.shortcuts import numpy
from django.utils.six.moves import range
@@ -74,7 +74,7 @@ class GEOSCoordSeq(GEOSBase):
        "Checks the given index."
        sz = self.size
        if (sz < 1) or (index < 0) or (index >= sz):
            raise GEOSIndexError('invalid GEOS Geometry index: %s' % str(index))
            raise IndexError('invalid GEOS Geometry index: %s' % str(index))

    def _checkdim(self, dim):
        "Checks the given dimension."
+0 −19
Original line number Diff line number Diff line
"""
 This module houses the GEOS exceptions, specifically, GEOSException and
 GEOSGeometryIndexError.
"""


class GEOSException(Exception):
    "The base GEOS exception, indicates a GEOS-related error."
    pass


class GEOSIndexError(GEOSException, KeyError):
    """
    This exception is raised when an invalid index is encountered, and has
    the 'silent_variable_feature' attribute set to true.  This ensures that
    django's templates proceed to use the next lookup type gracefully when
    an Exception is raised.  Fixes ticket #4740.
    """
    # "If, during the method lookup, a method raises an exception, the exception
    #  will be propagated, unless the exception has an attribute
    #  `silent_variable_failure` whose value is True." -- Django template docs.
    silent_variable_failure = True
+1 −4
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ from django.contrib.gis.geometry.regex import hex_regex, json_regex, wkt_regex
from django.contrib.gis.geos import prototypes as capi
from django.contrib.gis.geos.base import GEOSBase
from django.contrib.gis.geos.coordseq import GEOSCoordSeq
from django.contrib.gis.geos.error import GEOSException, GEOSIndexError
from django.contrib.gis.geos.error import GEOSException
from django.contrib.gis.geos.libgeos import GEOM_PTR
from django.contrib.gis.geos.mutable_list import ListMixin
from django.contrib.gis.geos.prepared import PreparedGeometry
@@ -26,9 +26,6 @@ from django.utils.encoding import force_bytes, force_text
class GEOSGeometry(GEOSBase, ListMixin):
    "A class that, generally, encapsulates a GEOS geometry."

    # Raise GEOSIndexError instead of plain IndexError
    # (see ticket #4740 and GEOSIndexError docstring)
    _IndexError = GEOSIndexError
    _GEOS_CLASSES = None

    ptr_type = GEOM_PTR
+4 −13
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
This module contains a base type which provides list-style mutations
without specific data storage methods.

See also http://www.aryehleib.com/MutableLists.html
See also http://static.aryehleib.com/oldsite/MutableLists.html

Author: Aryeh Leib Taurog.
"""
@@ -55,14 +55,10 @@ class ListMixin(object):

    type or tuple _allowed:
        A type or tuple of allowed item types [Optional]

    class _IndexError:
        The type of exception to be raise on invalid index [Optional]
    """

    _minlength = 0
    _maxlength = None
    _IndexError = IndexError

    # ### Python initialization and special list interface methods ###

@@ -113,11 +109,6 @@ class ListMixin(object):
            self._check_allowed((val,))
            self._set_single(index, val)

    def __iter__(self):
        "Iterate over the items in the list"
        for i in range(len(self)):
            yield self[i]

    # ### Special methods for arithmetic operations ###
    def __add__(self, other):
        'add another list-like object'
@@ -155,7 +146,7 @@ class ListMixin(object):
        for i in range(olen):
            try:
                c = self[i] == other[i]
            except self._IndexError:
            except IndexError:
                # self must be shorter
                return False
            if not c:
@@ -167,7 +158,7 @@ class ListMixin(object):
        for i in range(olen):
            try:
                c = self[i] < other[i]
            except self._IndexError:
            except IndexError:
                # self must be shorter
                return True
            if c:
@@ -254,7 +245,7 @@ class ListMixin(object):
            return index
        if correct and -length <= index < 0:
            return index + length
        raise self._IndexError('invalid index: %s' % str(index))
        raise IndexError('invalid index: %s' % str(index))

    def _check_allowed(self, items):
        if hasattr(self, '_allowed'):
Loading