
    gf                     *    d Z ddlmZ  G d de      Zy)a  
The SpatialProxy object allows for lazy-geometries and lazy-rasters. The proxy
uses Python descriptors for instantiating and setting Geometry or Raster
objects corresponding to geographic model fields.

Thanks to Robert Coup for providing this functionality (see #4322).
    )DeferredAttributec                   2     e Zd Zd fd	Zd fd	Zd Z xZS )SpatialProxyc                 H    || _         |xs || _        t        |   |       y)zy
        Initialize on the given Geometry or Raster class (not an instance)
        and the corresponding field.
        N)_klass
_load_funcsuper__init__)selfklassfield	load_func	__class__s       z/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/contrib/gis/db/models/proxy.pyr
   zSpatialProxy.__init__   s%    
 #,u    c                 D   || S 	 |j                   | j                  j                     }t        || j                        r|}|S ||dk(  rd}|S | j                  |      }t        || j                  j                  |       |S # t        $ r t        |   ||      }Y tw xY w)z
        Retrieve the geometry or raster, initializing it using the
        corresponding class specified during initialization and the value of
        the field. Currently, GEOS or OGR geometries as well as GDALRasters are
        supported.
        N )
__dict__r   attnameKeyErrorr	   __get__
isinstancer   r   setattr)r   instancecls	geo_valuegeo_objr   s        r   r   zSpatialProxy.__get__   s     K	7 ))$***<*<=I i-G  Y"_G  ooi0GHdjj00':  	7#6I	7s   #B BBc           
         | j                   j                  }|dk(  r$|!t        |t        t        | j
                  f      rnt        || j
                        r(|j                  f| j                   j                  |_        nJ|t        |t        t        f      rn1t        d|j                  j                  d|dt        |            ||j                  | j                   j                  <   |S )z
        Retrieve the proxied geometry or raster with the corresponding class
        specified during initialization.

        To set geometries, use values of None, HEXEWKB, or WKT.
        To set rasters, use JSON or dict values.
        RASTERzCannot set z SpatialProxy (z) with value of type: )r   	geom_typer   strdictr   srid
memoryview	TypeErrorr   __name__typer   r   )r   r   valuegtypes       r   __set__zSpatialProxy.__set__2   s     

$$HMZT4;;/GH t{{+ zz!!ZZ__
]jj0AB%%..tE{D  16$**,,-r   )N)r&   
__module____qualname__r
   r   r*   __classcell__)r   s   @r   r   r      s     8"r   r   N)__doc__django.db.models.query_utilsr   r    r   r   <module>r1      s    ;H$ Hr   