
    +'&h                     ^    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	  G d de          Z
dS )	    )defaultdict)partial)event)CreateEnginePlugin)select_dialectc                   D     e Zd ZdZ fdZed             Zd Zd Z xZ	S )	GeoEnginea  A plugin to create `sqlalchemy.Engine` objects with specific events to handle spatial data.

    This plugin should only be used with the :func:`sqlalchemy.create_engine` function. This plugin
    will automatically attach the relevant event listeners to the new engine depending on its
    dialect. For some specific dialects it's even possible to pass arguments to customize the
    functions called by the listeners. These arguments have the following form:
    `geoalchemy2_<event>_<dialect>_<argument_name>`.
    For example, creating a new SQLite DB and initialize the SpatiaLite extension with only the
    WGS84 SRID can be performed this way:

    .. code-block:: python

        db_url = "sqlite:////tmp/test_db.sqlite?geoalchemy2_connect_sqlite_init_mode=WGS84"
        engine = sqlalchemy.create_engine(db_url, plugins=["geoalchemy2"])

    The names of the parameters can be found in the event listener of each dialect. Note that all
    dialects don't have listeners for all events.
    c                    t                                          ||           t          d           | _        |j                            dd           }|)|                     |          | j        d         d         d<   |j                            dd           }||| j        d         d         d<   |j                            dd           }||| j        d         d         d	<   |j                            d
d           }|)|                     |          | j        d         d         d<   |j                            dd           }|+|                     |          | j        d         d         d<   d S d S )Nc                  *    t          t                    S )N)r   dict     S/var/www/html/reinick/venv/lib/python3.11/site-packages/geoalchemy2/admin/plugin.py<lambda>z$GeoEngine.__init__.<locals>.<lambda>"   s    +d*;*; r   &geoalchemy2_connect_sqlite_transactionconnectsqlitetransaction$geoalchemy2_connect_sqlite_init_mode	init_mode'geoalchemy2_connect_sqlite_journal_modejournal_mode/geoalchemy2_before_cursor_execute_mysql_convertbefore_cursor_executemysqlconvert1geoalchemy2_before_cursor_execute_mariadb_convertmariadb)super__init__r   paramsquerygetstr_to_bool)	selfurlkwargsr   r   r   #before_cursor_execute_convert_mysql%before_cursor_execute_convert_mariadb	__class__s	           r   r    zGeoEngine.__init__   s   f%%% "";";<<imm$LdSS">B>N>N{>[>[DK	"8,];IMM"H$OO	 <EDK	"8,[9y}}%NPTUU#?KDK	"8,^<.1imm=t/
 /
+ /:GKGWGW3H HDK/09)D 14	?1
 1
- 1<IMIYIY5J JDK/0;IFFF =<r   c                 z    t          |                                           }|dv rdS |dv rdS t          |           )zCast argument to bool.)yesytruet1enableonT)nonfalsef0disableoffF)strlower
ValueError)argumentlowereds     r   r$   zGeoEngine.str_to_bool@   sK     h--%%''DDD4HHH5"""r   c                 0    |                     g d          S )zBUpdate the URL to one that no longer includes specific parameters.)r   r   r   r   r   )difference_update_query)r%   r&   s     r   
update_urlzGeoEngine.update_urlJ   s)    **  
 
 	
r   c                     t          |j        j                  }t          |d          r`t	          | j        d                             |j        j        i                     }t          |j        fi |}t          j
        |d|           t          |d          rdt	          | j        d                             |j        j        i                     }t          |j        fi |}t          j
        |d|d           dS dS )z>Attach event listeners after the new Engine object is created.r   r   T)retvalN)r   dialectnamehasattrr   r!   r#   r   r   r   listenr   )r%   enginedialect_moduler!   funcs        r   engine_createdzGeoEngine.engine_createdV   s    '(;<<>9-- 	2$+i044V^5H"MMNNF>1<<V<<DLD111>#:;; 	M$+&=>BB6>CVXZ[[\\F>?JJ6JJDL!8$tLLLLLL	M 	Mr   )
__name__
__module____qualname____doc__r    staticmethodr$   rA   rK   __classcell__)r*   s   @r   r	   r	   
   s         &         D # # \#

 

 

M M M M M M Mr   r	   N)collectionsr   	functoolsr   
sqlalchemyr   sqlalchemy.enginer   geoalchemy2.adminr   r	   r   r   r   <module>rW      s    # # # # # #             0 0 0 0 0 0 , , , , , ,XM XM XM XM XM" XM XM XM XM XMr   