
 XH                 @   s  d  Z  d d l Z d d l Z d d l Z d d l m Z m Z m Z m Z m	 Z	 d d l
 m Z d d l m Z d d l m Z d d l m Z e j d  Z d	 d
   Z e d e	 e	  Z d d   Z e e  Z e d e	 e	  Z d d   Z e e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z e e  Z e e  Z e e  Z e e  Z  d d   Z! e e  Z" Gd d   d e#  Z$ e$ d d e	 Z% e j& d  Z' d d   Z( d S) a  
 This module houses the ctypes initialization procedures, as well
 as the notice and error handler function callbacks (get called
 when an error occurs in GEOS).

 This module also houses GEOS Pointer utilities, including
 get_pointer_arr(), and GEOM_PTR.
    N)CDLL	CFUNCTYPEPOINTER	Structurec_char_p)find_library)GEOSException)ImproperlyConfigured)SimpleLazyObjectzdjango.contrib.gisc              C   s+  y d d l  m }  |  j } Wn$ t t t t f k
 rC d  } Yn X| rS d  } nO t j d k rq d d g } n1 t j d k r d d g } n t d t j   | r x- | D]" } t	 |  } | d  k	 r Pq q Wn  | d  k r t d	 d
 j
 |    n  t |  } t | j _ t g | j _ | S)Nr   )settingsntZgeos_czlibgeos_c-1posixZGEOSzUnsupported OS "%s"z]Could not find the GEOS library (tried "%s"). Try setting GEOS_LIBRARY_PATH in your settings.z", ")Zdjango.confr   ZGEOS_LIBRARY_PATHAttributeErrorEnvironmentErrorImportErrorr	   osnamer   joinr   CONTEXT_PTRZ
initGEOS_rrestypeZfinishGEOS_rargtypes)r   Zlib_pathZ	lib_namesZlib_nameZ_lgeos r   M/home/ubuntu/projects/ifolica/build/django/django/contrib/gis/geos/libgeos.py	load_geos   s4    	r   c             C   sV   |  j    | j    }  } y |  | } Wn t k
 rA |  } Yn Xt j d |  d  S)NzGEOS_NOTICE: %s
)decode	TypeErrorloggerwarning)fmtlstZwarn_msgr   r   r   notice_hO   s    r    c             C   sV   |  j    | j    }  } y |  | } Wn t k
 rA |  } Yn Xt j d |  d  S)NzGEOS_ERROR: %s
)r   r   r   error)r   r   err_msgr   r   r   error_h[   s    r#   c               @   s   e  Z d  Z d S)
GEOSGeom_tN)__name__
__module____qualname__r   r   r   r   r$   h   s   r$   c               @   s   e  Z d  Z d S)GEOSPrepGeom_tN)r%   r&   r'   r   r   r   r   r(   l   s   r(   c               @   s   e  Z d  Z d S)GEOSCoordSeq_tN)r%   r&   r'   r   r   r   r   r)   p   s   r)   c               @   s   e  Z d  Z d S)GEOSContextHandle_tN)r%   r&   r'   r   r   r   r   r*   t   s   r*   c             C   s   t  |  } |   S)zJGets a ctypes pointer array (of length `n`) for GEOSGeom_t opaque pointer.)GEOM_PTR)nZGeomArrr   r   r   get_pointer_arr   s    
r-   c               @   sL   e  Z d  Z d Z d Z d Z d Z d d   Z d d   Z d d   Z	 d S)	GEOSFuncFactoryz)
    Lazy loading of GEOS functions.
    Nc             O   sp   | |  _  | j d |  j  |  _ | j d |  j  |  _ | j d |  j  |  _ | |  _ | |  _ d  |  _ d  S)Nr   errcheckr   )	func_namepopr   r/   r   argskwargsfunc)selfr0   r2   r3   r   r   r   __init__   s    			zGEOSFuncFactory.__init__c             O   s=   |  j  d  k r- |  j |  j |  j   |  _  n  |  j  | |   S)N)r4   get_funcr2   r3   )r5   r2   r3   r   r   r   __call__   s    zGEOSFuncFactory.__call__c             O   sY   d d l  m } | |  j  } |  j p+ g  | _ |  j | _ |  j rU |  j | _ n  | S)Nr   )GEOSFunc)Z-django.contrib.gis.geos.prototypes.threadsafer9   r0   r   r   r/   )r5   r2   r3   r9   r4   r   r   r   r7      s    	zGEOSFuncFactory.get_func)
r%   r&   r'   __doc__r   r   r/   r6   r8   r7   r   r   r   r   r.      s   	r.   ZGEOSversionr   z^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.(?P<subminor>\d+))((rc(?P<release_candidate>\d+))|dev)?-CAPI-(?P<capi_version>\d+\.\d+\.\d+)( r\d+)?$c                 sN   t    j   }  t j |       s7 t d |    n    f d d   d
 D S)z
    Returns a dictionary containing the various version metadata parsed from
    the GEOS version string, including the version number, whether the version
    is a release candidate (and what number release candidate), and the C API
    version.
    z(Could not parse version info string "%s"c                s"   i  |  ] }   j  |  |  q Sr   )group).0key)mr   r   
<dictcomp>   s   	 z%geos_version_info.<locals>.<dictcomp>versionrelease_candidatecapi_versionmajorminorsubminor)zversionrA   rB   zmajorzminorrE   )geos_versionr   version_regexmatchr   )verr   )r>   r   geos_version_info   s    rJ   ))r:   loggingr   rectypesr   r   r   r   r   ctypes.utilr   Zdjango.contrib.gis.geos.errorr   Zdjango.core.exceptionsr	   Zdjango.utils.functionalr
   	getLoggerr   r   Z
NOTICEFUNCr    Z	ERRORFUNCr#   r$   r(   r)   r*   r+   ZPREPGEOM_PTRZCS_PTRr   r-   Zlgeosobjectr.   rF   compilerG   rJ   r   r   r   r   <module>   s>   (6"	