PageRenderTime 34ms CodeModel.GetById 16ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause
  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 GDALException(Exception): pass
  8. class OGRException(Exception): pass
  9. class SRSException(Exception): pass
  10. class 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. #### OGR error checking codes and routine ####
  19. # OGR Error Codes
  20. OGRERR_DICT = { 1 : (OGRException, 'Not enough data.'),
  21. 2 : (OGRException, 'Not enough memory.'),
  22. 3 : (OGRException, 'Unsupported geometry type.'),
  23. 4 : (OGRException, 'Unsupported operation.'),
  24. 5 : (OGRException, 'Corrupt data.'),
  25. 6 : (OGRException, 'OGR failure.'),
  26. 7 : (SRSException, 'Unsupported SRS.'),
  27. 8 : (OGRException, 'Invalid handle.'),
  28. }
  29. OGRERR_NONE = 0
  30. def check_err(code):
  31. "Checks the given OGRERR, and raises an exception where appropriate."
  32. if code == OGRERR_NONE:
  33. return
  34. elif code in OGRERR_DICT:
  35. e, msg = OGRERR_DICT[code]
  36. raise e(msg)
  37. else:
  38. raise OGRException('Unknown error code: "%s"' % code)