2 from ctypes
import CDLL
3 from ctypes
.util
import find_library
4 from django
.conf
import settings
6 # Creating the settings dictionary with any settings, if needed.
7 GEOIP_SETTINGS
= dict((key
, getattr(settings
, key
))
8 for key
in ('GEOIP_PATH', 'GEOIP_LIBRARY_PATH', 'GEOIP_COUNTRY', 'GEOIP_CITY')
9 if hasattr(settings
, key
))
10 lib_path
= GEOIP_SETTINGS
.get('GEOIP_LIBRARY_PATH', None)
12 # The shared library for the GeoIP C API. May be downloaded
13 # from http://www.maxmind.com/download/geoip/api/c/
17 # TODO: Is this really the library name for Windows?
20 # Getting the path to the GeoIP library.
21 if lib_name
: lib_path
= find_library(lib_name
)
22 if lib_path
is None: raise GeoIPException('Could not find the GeoIP library (tried "%s"). '
23 'Try setting GEOIP_LIBRARY_PATH in your settings.' % lib_name
)
24 lgeoip
= CDLL(lib_path
)
26 # Getting the C `free` for the platform.