
v^                 @   s   d  d l  m Z d  d l m Z d  d l m Z d  d l m Z d d l	 m
 Z
 d d l m Z d d l m Z d d	 l m Z d d
 l m Z Gd d   d e  Z d S)    )find_library)settings)ImproperlyConfigured)DatabaseWrapper   )SpatiaLiteClient)DatabaseFeatures)SpatiaLiteIntrospection)SpatiaLiteOperations)SpatialiteSchemaEditorc                   sd   e  Z d  Z e Z e Z e Z e	 Z
 e Z   f d d   Z   f d d   Z   f d d   Z   S)r   c                sK   d d   t  t d d   d d t d  g D |  _ t   j | |   d  S)Nc             S   s"   g  |  ] } | d  k	 r |  q S)N ).0namer   r   P/tmp/pip-build-8lau8j11/django/django/contrib/gis/db/backends/spatialite/base.py
<listcomp>   s   	 z,DatabaseWrapper.__init__.<locals>.<listcomp>SPATIALITE_LIBRARY_PATHzmod_spatialite.soZmod_spatialiteZ
spatialite)getattrr   r   lib_spatialite_pathssuper__init__)selfargskwargs)	__class__r   r   r      s    	zDatabaseWrapper.__init__c                s   t    j |  } y | j d  Wn t k
 rC t d   Yn Xxu |  j D]N } y | j |  Wn3 t k
 r t t	 d d   r t d   wN YqN XPqN Wt d d j
 |  j    | S)NTzGSpatiaLite requires SQLite to be configured to allow extension loading.r   zeUnable to load the SpatiaLite library extension as specified in your SPATIALITE_LIBRARY_PATH setting.zHUnable to load the SpatiaLite library extension. Library names tried: %sz, )r   get_new_connectionZenable_load_extensionAttributeErrorr   r   Zload_extension	Exceptionr   r   join)r   Zconn_paramsconnpath)r   r   r   r   &   s&    	z"DatabaseWrapper.get_new_connectionc          	      sS   t    j   |  j   3 } | j d  | j   g  k rH | j d  Wd  QRXd  S)Nz$PRAGMA table_info(geometry_columns);zSELECT InitSpatialMetaData(1))r   prepare_databasecursorexecuteZfetchall)r   r!   )r   r   r   r    D   s
    z DatabaseWrapper.prepare_database)__name__
__module____qualname__r   ZSchemaEditorClassr   Zclient_classr   Zfeatures_classr	   Zintrospection_classr
   Z	ops_classr   r   r    r   r   )r   r   r      s   r   N)ctypes.utilr   Zdjango.confr   Zdjango.core.exceptionsr   Zdjango.db.backends.sqlite3.baser   ZSQLiteDatabaseWrapperclientr   featuresr   Zintrospectionr	   
operationsr
   Zschemar   r   r   r   r   <module>   s   