U
    8ÄT_8  ã                   @   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r dZnNejdkr¾d	d
dddddgZn0ejdkrà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�r0edd e¡ ƒ‚eeƒZejdk�rXd 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)d*„ Z(e(d+e&ge&ƒZ)e)e'ƒ dS ),é    N)ÚCDLLÚ	CFUNCTYPEÚc_char_pÚc_int)Úfind_library)ÚGDALException)ÚImproperlyConfiguredzdjango.contrib.gis)ÚsettingsÚntZgdal301Zgdal300Zgdal204Zgdal203Zgdal202Zgdal201Zgdal20ÚposixZgdalZGDALz	gdal3.1.0z	gdal3.0.0z	gdal2.4.0z	gdal2.3.0z	gdal2.2.0z	gdal2.1.0z	gdal2.0.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-dv63caxw/django/contrib/gis/gdal/libgdal.pyÚstd_call=   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_versionP   s    r   c                   C   s   t dƒS )z)Return the full GDAL version information.ó    r   r   r   r   r   Úgdal_full_versionU   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_infoZ   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_handleri   s    r&   c                 C   s   t | ƒ}||_||_|S )N)r   ÚargtypesÚrestype)r   Úargsr(   r   r   r   r   Úfunctionp   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>   sr   




      ý
þÿ	