<s> """<STR_LIT>""" <EOL> import os <EOL> import re <EOL> import sys <EOL> from ctypes import c_char_p , Structure , CDLL , CFUNCTYPE , POINTER <EOL> from ctypes . util import find_library <EOL> from django . contrib . gis . geos . error import GEOSException <EOL> try : <EOL> from django . conf import settings <EOL> lib_path = settings . GEOS_LIBRARY_PATH <EOL> except ( AttributeError , EnvironmentError , ImportError ) : <EOL> lib_path = None <EOL> if lib_path : <EOL> lib_names = None <EOL> elif os . name == '<STR_LIT>' : <EOL> lib_names = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> elif os . name == '<STR_LIT>' : <EOL> lib_names = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> else : <EOL> raise ImportError ( '<STR_LIT>' % os . name ) <EOL> if lib_names : <EOL> for lib_name in lib_names : <EOL> lib_path = find_library ( lib_name ) <EOL> if not lib_path is None : break <EOL> if lib_path is None : <EOL> raise ImportError ( '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> '<STR_LIT>' . join ( lib_names ) ) <EOL> lgeos = CDLL ( lib_path ) <EOL> NOTICEFUNC = CFUNCTYPE ( None , c_char_p , c_char_p ) <EOL> def notice_h ( fmt , lst , output_h = sys . stdout ) : <EOL> try : <EOL> warn_msg = fmt % lst <EOL> except : <EOL> warn_msg = fmt <EOL> output_h . write ( '<STR_LIT>' % warn_msg ) <EOL> notice_h = NOTICEFUNC ( notice_h ) <EOL> ERRORFUNC = CFUNCTYPE ( None , c_char_p , c_char_p ) <EOL> def error_h ( fmt , lst , output_h = sys . stderr ) : <EOL> try : <EOL> err_msg = fmt % lst <EOL> except : <EOL> err_msg = fmt <EOL> output_h . write ( '<STR_LIT>' % err_msg ) <EOL> error_h = ERRORFUNC ( error_h ) <EOL> class GEOSGeom_t ( Structure ) : pass <EOL> class GEOSPrepGeom_t ( Structure ) : pass <EOL> class GEOSCoordSeq_t ( Structure ) : pass <EOL> class GEOSContextHandle_t ( Structure ) : pass <EOL> GEOM_PTR = POINTER ( GEOSGeom_t ) <EOL> PREPGEOM_PTR = POINTER ( GEOSPrepGeom_t ) <EOL> CS_PTR = POINTER ( GEOSCoordSeq_t ) <EOL> CONTEXT_PTR = POINTER ( GEOSContextHandle_t ) <EOL> def get_pointer_arr ( n ) : <EOL> "<STR_LIT>" <EOL> GeomArr = GEOM_PTR * n <EOL> return GeomArr ( ) <EOL> geos_version = lgeos . GEOSversion <EOL> geos_version . argtypes = None <EOL> geos_version . restype = c_char_p <EOL> version_regex = re . compile ( r'<STR_LIT>' ) <EOL> def geos_version_info ( ) : <EOL> """<STR_LIT>""" <EOL> ver = geos_version ( ) <EOL> m = version_regex . match ( ver ) <EOL> if not m : raise GEOSException ( '<STR_LIT>' % ver ) <EOL> return dict ( ( key , m . group ( key ) ) for key in ( '<STR_LIT:version>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> _verinfo = geos_version_info ( ) <EOL> GEOS_MAJOR_VERSION = int ( _verinfo [ '<STR_LIT>' ] ) <EOL> GEOS_MINOR_VERSION = int ( _verinfo [ '<STR_LIT>' ] ) <EOL> GEOS_SUBMINOR_VERSION = int ( _verinfo [ '<STR_LIT>' ] ) <EOL> del _verinfo <EOL> GEOS_VERSION = ( GEOS_MAJOR_VERSION , GEOS_MINOR_VERSION , GEOS_SUBMINOR_VERSION ) <EOL> GEOS_PREPARE = GEOS_VERSION >= ( <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> if GEOS_PREPARE : <EOL> lgeos . initGEOS_r . restype = CONTEXT_PTR <EOL> lgeos . finishGEOS_r . argtypes = [ CONTEXT_PTR ] <EOL> else : <EOL> lgeos . initGEOS ( notice_h , error_h ) <EOL> import atexit <EOL> atexit . register ( lgeos . finishGEOS ) </s>
