o
    ó<âg½  ã                   @   s:   d Z ddlmZ ddlmZ ddlmZ G dd„ dƒZdS )zL
 This object provides quoting for GEOS geometries into PostgreSQL/PostGIS.
é    )Úto_pgraster)ÚGEOSGeometry)Úsqlc                   @   sJ   e Zd Zddd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zedd„ ƒZ	dd„ Z
dS )ÚPostGISAdapterFc                 C   s@   t |ttfƒ| _| jrt|jƒ| _nt|ƒ| _|j| _|| _dS )z3
        Initialize on the spatial object.
        N)	Ú
isinstancer   r   Úis_geometryÚbytesÚewkbr   ÚsridÚ	geography)ÚselfÚobjr   © r   úa/var/www/html/venv/lib/python3.10/site-packages/django/contrib/gis/db/backends/postgis/adapter.pyÚ__init__   s   

zPostGISAdapter.__init__c                 C   s    ddl m} ||kr| S tdƒ‚)z9Does the given protocol conform to what Psycopg2 expects?r   )Ú	ISQLQuotez<Error implementing psycopg2 protocol. Is psycopg2 installed?)Úpsycopg2.extensionsr   Ú	Exception)r   Úprotor   r   r   r   Ú__conform__   s   ÿzPostGISAdapter.__conform__c                 C   s   t |tƒo
| j|jkS ©N)r   r   r	   )r   Úotherr   r   r   Ú__eq__&   s   zPostGISAdapter.__eq__c                 C   s
   t | jƒS r   )Úhashr	   ©r   r   r   r   Ú__hash__)   s   
zPostGISAdapter.__hash__c                 C   s   |   ¡  ¡ S r   )Ú	getquotedÚdecoder   r   r   r   Ú__str__,   s   zPostGISAdapter.__str__c                 C   s   |S r   r   )ÚclsÚpolyr   r   r   Ú_fix_polygon/   s   zPostGISAdapter._fix_polygonc                 C   s:   | j rd| jr	dndt | j¡ ¡ f S d| j ¡  ¡  S )zP
        Return a properly quoted string for use in PostgreSQL/PostGIS.
        s   %s(%s)s   ST_GeogFromWKBs   ST_GeomFromEWKBs   '%s'::raster)r   r   r   Úquoter	   ÚencodeÚhexr   r   r   r   r   3   s   þzPostGISAdapter.getquotedN)F)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   Úclassmethodr!   r   r   r   r   r   r   
   s    

r   N)Ú__doc__Ú/django.contrib.gis.db.backends.postgis.pgrasterr   Údjango.contrib.gis.geosr   Ú)django.db.backends.postgresql.psycopg_anyr   r   r   r   r   r   Ú<module>   s
    