3
®?d]~   ã               @   s`  d Z ddlmZmZmZmZ ddlmZ ddlZddl	Z	ddl
Z
ddlZddlZe	jeƒZe	jƒ Zejeƒ dejkr‚eje	jƒ dZdejkrêejd ZyeeƒZW n   ejdeƒ Y nX erêeedƒrÚejd	ƒ ned
eeƒ ƒ‚dejk�rejd Zejdeƒ ndZdd„ ZyedƒZ W n ek
�r@   dZY nX e �rˆe�rˆdZ!dZ"xDe j#ƒ D ]8Z$e$j%dƒ�r€e$dd… Z!ne$j%dƒ�rbe$dd… Z"�qbW ej&dk�r²dgZ'n,ej&dk�rÊdddgZ'nej"dk�rÞddgZ'g Z(xNe'D ]FZ)e)j*e"d�Z+ej,j-e!e+ƒZyeeƒZP W n   e(j.eƒ Y nX �qèW e�rbeedƒ�rPejd ƒ ned!eeƒ ƒ‚n&ejd"ee ƒ ejd#e/e(ƒd$j-e(ƒƒ d@d%d&„Z0ej&j%d'ƒ�rÒe�s¶e0dd(d)gd*�Ze0d+ƒj1Z1ege1_2de1_3�nvej&dk�rBe�s eed,ƒ�rej,j-ejd- d.d/d0ƒgZ4nd1d2gZ4e0de4d*�Ze0d+d3gd*�j1Z1ege1_2de1_3�nej&dk�rØe�sÎyZej,j5ej,j-ej,j6e7ƒd4ƒƒZ8ej,j5ej7d5 ƒZ9ejd6 Z:d7e8e9e:f ejd6< ed8ƒZW n e;e<efk
�rÌ   ‚ Y nX d9d:„ Z1npej&d;k�re�súe0dd(d)gd*�Zed<ƒj1Z1ege1_2de1_3n4e�s*e0dd(d)gd*�Ze0d+d=gd*�j1Z1ege1_2de1_3d>d?„ Z=e=ƒ \Z>Z?Z@dS )Aa½  
Minimal proxy to a GEOS C dynamic library, which is system dependant

Two environment variables influence this module: GEOS_LIBRARY_PATH and/or
GEOS_CONFIG.

If GEOS_LIBRARY_PATH is set to a path to a GEOS C shared library, this is
used. Otherwise GEOS_CONFIG can be set to a path to `geos-config`. If
`geos-config` is already on the PATH environment variable, then it will
be used to help better guess the name for the GEOS C dynamic library.
é    )ÚCDLLÚcdllÚc_void_pÚc_char_p)Úfind_libraryNÚallZGEOS_LIBRARY_PATHz4cannot open shared object from GEOS_LIBRARY_PATH: %sÚGEOSversionz,found GEOS C library using GEOS_LIBRARY_PATHz9shared object GEOS_LIBRARY_PATH is not a GEOS C library: ZGEOS_CONFIGzgeos_config: %szgeos-configc             C   sÎ   t ƒ jdƒ}| st|tƒ r&tdƒ‚y$tj|| gtjtjd�jƒ \}}W n2 tk
r| } ztd||f ƒ‚W Y dd}~X nX |r”| r”t	|j
ƒ ƒ‚tjd dkr²|jdƒj
ƒ }n|j
ƒ }tjd	|| |ƒ |S )
z³Get configuration option from the `geos-config` development utility

    Path to utility is set with a module-level `geos_config` variable, which
    can be changed or unset.
    Úgeos_configzPath to geos-config is not set)ÚstdoutÚstderrz!Could not find geos-config %r: %sNr   é   Úasciiz	%s %s: %r)ÚglobalsÚgetÚ
isinstanceÚstrÚOSErrorÚ
subprocessÚPopenÚPIPEÚcommunicateÚ
ValueErrorÚstripÚsysÚversion_infoÚdecodeÚlogÚdebug)Úoptionr	   r
   r   ÚexÚresult© r!   ú4/tmp/pip-build-op5p2y5_/shapely/shapely/_buildcfg.pyÚget_geos_config;   s"     
r#   z--clibsÚ Zgeos_cz-Lé   z-lÚwin32z
{name}.dllÚdarwinzlib{name}.dylibz{name}.dylibz{name}.framework/{name}Úposixzlib{name}.sozlib{name}.so.1)Únamez&found GEOS C library using geos-configz<shared object found by geos-config is not a GEOS C library: z/cannot open shared object from '%s --clibs': %rz*there were %d guess(es) for this path:
	%sz
	c             C   sà   t | ƒ}d }|d k	rNytjd|ƒ t|ƒ}W n  tk
rL   tjd|ƒ Y nX | r¤|d k	r¤xF|D ]>}ytjd|ƒ t|ƒ}W qb tk
rž   tjd|ƒ Y qbX qbW |rÈtjd|p´|ƒ tjd|ƒ |S tdj| |pÖg ƒƒ‚d S )NzTrying `CDLL(%s)`zFailed `CDLL(%s)`zLibrary path: %rzDLL: %rz:Could not find library {0} or load any of its variants {1})r   r   r   r   r   ÚwarnÚformat)ÚlibnameÚ	fallbacksÚlibÚdllr)   r!   r!   r"   Úload_dll„   s0    

r0   Úlinuxzlibgeos_c.so.1zlibgeos_c.so)r-   ÚcÚfrozenZRESOURCEPATHz..Z
Frameworkszlibgeos_c.dylibz8/Library/Frameworks/GEOS.framework/Versions/Current/GEOSz/opt/local/lib/libgeos_c.dylibz/usr/lib/libc.dylibZDLLsz../../../DLLsÚPATHz%s;%s;%sz
geos_c.dllc             C   s*   yt jj| ƒ W n tk
r$   Y nX d S )N)r   ÚmsvcrtÚfreeÚWindowsError)Úmr!   r!   r"   r6   Ì   s    r6   Zsunos5z	libc.so.1z	libc.so.6c              C   s†   t j} t| _g | _| ƒ }tjd dkr0|jdƒ}tj	d|ƒ}t
|ƒdksPt|ƒ‚tdd„ |d D ƒƒ}tdd„ |d	 D ƒƒ}|||fS )
Nr   r   r   z(\d+)\.(\d+)\.(\d+)r%   c             s   s   | ]}t |ƒV  qd S )N)Úint)Ú.0Úxr!   r!   r"   ú	<genexpr>ó   s    z _geos_version.<locals>.<genexpr>c             s   s   | ]}t |ƒV  qd S )N)r9   )r:   r;   r!   r!   r"   r<   ô   s    é   )Úlgeosr   r   ÚrestypeÚargtypesr   r   r   ÚreÚfindallÚlenÚAssertionErrorÚtuple)r   Úgeos_version_stringÚresÚgeos_versionZcapi_versionr!   r!   r"   Ú_geos_versionç   s    
rI   )N)AÚ__doc__Úctypesr   r   r   r   Úctypes.utilr   ÚosÚloggingrA   r   r   Ú	getLoggerÚ__name__r   ÚStreamHandlerÚchÚ
addHandlerÚwarnoptionsÚsetLevelÚDEBUGr>   ÚenvironZgeos_library_pathr*   Úhasattrr   r   r   r	   r#   ZclibsÚbaser)   ÚsplitÚitemÚ
startswithÚplatformZfmtsZguessesÚfmtr+   Zlib_nameÚpathÚjoinÚappendrC   r0   r6   r@   r?   Z	alt_pathsÚabspathÚdirnameÚ__file__Zegg_dllsZwininst_dllsZoriginal_pathÚImportErrorr7   rI   rF   rH   Zgeos_capi_versionr!   r!   r!   r"   Ú<module>   sæ   









 





