importosfromctypesimportCDLLfromctypes.utilimportfind_libraryfromdjango.confimportsettings# Creating the settings dictionary with any settings, if needed.GEOIP_SETTINGS={key:getattr(settings,key)forkeyin('GEOIP_PATH','GEOIP_LIBRARY_PATH','GEOIP_COUNTRY','GEOIP_CITY')ifhasattr(settings,key)}lib_path=GEOIP_SETTINGS.get('GEOIP_LIBRARY_PATH')# The shared library for the GeoIP C API. May be downloaded# from http://www.maxmind.com/download/geoip/api/c/iflib_path:lib_name=Noneelse:# TODO: Is this really the library name for Windows?lib_name='GeoIP'# Getting the path to the GeoIP library.iflib_name:lib_path=find_library(lib_name)iflib_pathisNone:raiseRuntimeError('Could not find the GeoIP library (tried "%s"). ''Try setting GEOIP_LIBRARY_PATH in your settings.'%lib_name)lgeoip=CDLL(lib_path)# Getting the C `free` for the platform.ifos.name=='nt':libc=CDLL('msvcrt')else:libc=CDLL(None)free=libc.free