U
    e"                     @   s  d dl Z d dlZd dlZd dlmZmZmZmZ d dlm	Z	 d dl
mZ d dlmZ e dZzd dlmZ ejZW n  eeeefk
r   dZY nX erdZnZejdkrd	d
ddddddddg
Zn6ejdkrddddddddddddgZned ej er$eD ]Ze	eZedk	r q$qedkr@ed!d"e eeZejdkrhd d#lmZ eeZd$d% Zed&Zege_ ee_!d'd( Z"d)d* Z#d+d, Z$e$ Z%edeeeZ&d-d. Z'e&e'Z'd/d0 Z(e(d1e&ge&Z)e)e' dS )2    N)CDLL	CFUNCTYPEc_char_pc_int)find_library)GDALException)ImproperlyConfiguredzdjango.contrib.gis)settingsntZgdal306Zgdal305Zgdal304Zgdal303Zgdal302Zgdal301Zgdal300Zgdal204Zgdal203Zgdal202posixZgdalZGDALz	gdal3.6.0z	gdal3.5.0z	gdal3.4.0z	gdal3.3.0z	gdal3.2.0z	gdal3.1.0z	gdal3.0.0z	gdal2.4.0z	gdal2.3.0z	gdal2.2.0zGDAL is unsupported on OS "%s".zzCould not find the GDAL library (tried "%s"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.z", ")WinDLLc                 C   s   t jdkrt|  S t|  S dS )z^
    Return the correct STDCALL function for certain OSR routines on Win32
    platforms.
    r
   N)osnamelwingdallgdal)func r   C/tmp/pip-unpacked-wheel-lctamlir/django/contrib/gis/gdal/libgdal.pystd_callS   s    
r   ZGDALVersionInfoc                   C   s   t dS )z0Return only the GDAL version number information.s   RELEASE_NAME_version_infor   r   r   r   gdal_versionf   s    r   c                   C   s   t dS )z)Return the full GDAL version information.    r   r   r   r   r   gdal_full_versionk   s    r   c                  C   sJ   t  } td| }|s"td|  | \}}}t|t||oFt|fS )Ns7   ^(?P<major>\d+)\.(?P<minor>\d+)(?:\.(?P<subminor>\d+))?z(Could not parse GDAL version string "%s")r   rematchr   groupsint)vermmajorminorZsubminorr   r   r   gdal_version_infop   s    r"   c                 C   s   t d|| d S )NzGDAL_ERROR %d: %s)loggererror)Zerror_classZerror_numbermessager   r   r   err_handler   s    r&   c                 C   s   t | }||_||_|S )N)r   argtypesrestype)r   argsr(   r   r   r   r   function   s    r*   ZCPLSetErrorHandler)*loggingr   r   ctypesr   r   r   r   Zctypes.utilr   Zdjango.contrib.gis.gdal.errorr   Zdjango.core.exceptionsr   	getLoggerr#   Zdjango.confr	   ZGDAL_LIBRARY_PATHZlib_pathAttributeErrorImportErrorOSErrorZ	lib_namesr   Zlib_namejoinr   r   r   r   r   r'   r(   r   r   r"   ZGDAL_VERSIONZCPLErrorHandlerr&   r*   Zset_error_handlerr   r   r   r   <module>   s   







	