app/django/contrib/gis/gdal/error.py
changeset 323 ff1a9aa48cfd
equal deleted inserted replaced
322:6641e941ef1e 323:ff1a9aa48cfd
       
     1 """
       
     2  This module houses the OGR & SRS Exception objects, and the
       
     3  check_err() routine which checks the status code returned by
       
     4  OGR methods.
       
     5 """
       
     6 #### OGR & SRS Exceptions ####
       
     7 class OGRException(Exception): pass
       
     8 class SRSException(Exception): pass
       
     9 class OGRIndexError(OGRException, KeyError):
       
    10     """
       
    11     This exception is raised when an invalid index is encountered, and has
       
    12     the 'silent_variable_feature' attribute set to true.  This ensures that
       
    13     django's templates proceed to use the next lookup type gracefully when
       
    14     an Exception is raised.  Fixes ticket #4740.
       
    15     """
       
    16     silent_variable_failure = True
       
    17 
       
    18 #### OGR error checking codes and routine ####
       
    19 
       
    20 # OGR Error Codes
       
    21 OGRERR_DICT = { 1 : (OGRException, 'Not enough data.'),
       
    22                 2 : (OGRException, 'Not enough memory.'),
       
    23                 3 : (OGRException, 'Unsupported geometry type.'),
       
    24                 4 : (OGRException, 'Unsupported operation.'),
       
    25                 5 : (OGRException, 'Corrupt data.'),
       
    26                 6 : (OGRException, 'OGR failure.'),
       
    27                 7 : (SRSException, 'Unsupported SRS.'),
       
    28                 8 : (OGRException, 'Invalid handle.'),
       
    29                 }
       
    30 OGRERR_NONE = 0
       
    31 
       
    32 def check_err(code):
       
    33     "Checks the given OGRERR, and raises an exception where appropriate."
       
    34     
       
    35     if code == OGRERR_NONE:
       
    36         return
       
    37     elif code in OGRERR_DICT:
       
    38         e, msg = OGRERR_DICT[code]
       
    39         raise e, msg
       
    40     else:
       
    41         raise OGRException('Unknown error code: "%s"' % code)