PageRenderTime 33ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/django/contrib/gis/gdal/base.py

https://code.google.com/p/mango-py/
Python | 35 lines | 17 code | 6 blank | 12 comment | 5 complexity | fd696a7d2c3dc5bb3fb56de72b3d43fc MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from ctypes import c_void_p
  2. from types import NoneType
  3. from django.contrib.gis.gdal.error import GDALException
  4. class GDALBase(object):
  5. """
  6. Base object for GDAL objects that has a pointer access property
  7. that controls access to the underlying C pointer.
  8. """
  9. # Initially the pointer is NULL.
  10. _ptr = None
  11. # Default allowed pointer type.
  12. ptr_type = c_void_p
  13. # Pointer access property.
  14. def _get_ptr(self):
  15. # Raise an exception if the pointer isn't valid don't
  16. # want to be passing NULL pointers to routines --
  17. # that's very bad.
  18. if self._ptr: return self._ptr
  19. else: raise GDALException('GDAL %s pointer no longer valid.' % self.__class__.__name__)
  20. def _set_ptr(self, ptr):
  21. # Only allow the pointer to be set with pointers of the
  22. # compatible type or None (NULL).
  23. if isinstance(ptr, (int, long)):
  24. self._ptr = self.ptr_type(ptr)
  25. elif isinstance(ptr, (self.ptr_type, NoneType)):
  26. self._ptr = ptr
  27. else:
  28. raise TypeError('Incompatible pointer type')
  29. ptr = property(_get_ptr, _set_ptr)