App Engine Python SDK version 1.7.4 (2)
[gae.git] / python / lib / django_1_4 / django / contrib / gis / geoip / libgeoip.py
blob613949f8096deea0173436c42f7ef48261e6ff02
1 import os
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/
14 if lib_path:
15 lib_name = None
16 else:
17 # TODO: Is this really the library name for Windows?
18 lib_name = 'GeoIP'
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.
27 if os.name == 'nt':
28 libc = CDLL('msvcrt')
29 else:
30 libc = CDLL(None)
31 free = libc.free