PageRenderTime 122ms CodeModel.GetById 80ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 0ms

/django/contrib/gis/gdal/error.py

https://code.google.com/p/mango-py/
Python | 42 lines | 28 code | 0 blank | 14 comment | 0 complexity | 932a18559495b3f0fd5174245319cba7 MD5 | raw file
 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 ####
 7class GDALException(Exception): pass
 8class OGRException(Exception): pass
 9class SRSException(Exception): pass
10class OGRIndexError(OGRException, KeyError):
11    """
12    This exception is raised when an invalid index is encountered, and has
13    the 'silent_variable_feature' attribute set to true.  This ensures that
14    django's templates proceed to use the next lookup type gracefully when
15    an Exception is raised.  Fixes ticket #4740.
16    """
17    silent_variable_failure = True
18
19#### OGR error checking codes and routine ####
20
21# OGR Error Codes
22OGRERR_DICT = { 1 : (OGRException, 'Not enough data.'),
23                2 : (OGRException, 'Not enough memory.'),
24                3 : (OGRException, 'Unsupported geometry type.'),
25                4 : (OGRException, 'Unsupported operation.'),
26                5 : (OGRException, 'Corrupt data.'),
27                6 : (OGRException, 'OGR failure.'),
28                7 : (SRSException, 'Unsupported SRS.'),
29                8 : (OGRException, 'Invalid handle.'),
30                }
31OGRERR_NONE = 0
32
33def check_err(code):
34    "Checks the given OGRERR, and raises an exception where appropriate."
35    
36    if code == OGRERR_NONE:
37        return
38    elif code in OGRERR_DICT:
39        e, msg = OGRERR_DICT[code]
40        raise e(msg)
41    else:
42        raise OGRException('Unknown error code: "%s"' % code)