î
ªÍ XÍ  ã               @   sp   d  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)
zL
 This object provides quoting for GEOS geometries into PostgreSQL/PostGIS.
é    )Úunicode_literals)ÚBinary)Ú	ISQLQuote)Úto_pgraster)ÚGeometryc               @   sg   e  Z d  Z d d d „ Z d d „  Z d d „  Z d d	 „  Z d
 d „  Z d d „  Z d d „  Z	 d S)ÚPostGISAdapterFc             C   sp   t  | t t f ƒ |  _ |  j rH t | j ƒ |  _ t |  j ƒ |  _ n t | ƒ |  _ | j	 |  _	 | |  _
 d S)z3
        Initialize on the spatial object.
        N)Ú
isinstancer   r   Úis_geometryÚbytesÚewkbr   Ú_adapterr   ÚsridÚ	geography)ÚselfÚobjr   © r   ú\/home/ubuntu/projects/ifolica/build/django/django/contrib/gis/db/backends/postgis/adapter.pyÚ__init__   s    	zPostGISAdapter.__init__c             C   s    | t  k r |  St d ƒ ‚ d  S)Nz<Error implementing psycopg2 protocol. Is psycopg2 installed?)r   Ú	Exception)r   Úprotor   r   r   Ú__conform__   s    zPostGISAdapter.__conform__c             C   s5   t  | t ƒ s d S|  j | j k o4 |  j | j k S)NF)r   r   r   r   )r   Úotherr   r   r   Ú__eq__&   s    zPostGISAdapter.__eq__c             C   s   t  |  j |  j f ƒ S)N)Úhashr   r   )r   r   r   r   Ú__hash__+   s    zPostGISAdapter.__hash__c             C   s
   |  j  ƒ  S)N)Ú	getquoted)r   r   r   r   Ú__str__.   s    zPostGISAdapter.__str__c             C   s    |  j  r |  j j | ƒ n  d S)zŒ
        This method allows escaping the binary in the style required by the
        server's `standard_conforming_string` setting.
        N)r	   r   Úprepare)r   Úconnr   r   r   r   1   s    	zPostGISAdapter.preparec             C   sJ   |  j  r; t d |  j r d n d |  j j ƒ  j ƒ  f ƒ Sd |  j Sd S)zP
        Return a properly quoted string for use in PostgreSQL/PostGIS.
        z%s(%s)ZST_GeogFromWKBZST_GeomFromEWKBz'%s'::rasterN)r	   Ústrr   r   r   Údecoder   )r   r   r   r   r   9   s
    	zPostGISAdapter.getquotedN)
Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r   r   r   r   r      s   r   N)Ú__doc__Ú
__future__r   Zpsycopg2r   Zpsycopg2.extensionsr   Z/django.contrib.gis.db.backends.postgis.pgrasterr   Z#django.contrib.gis.geometry.backendr   Úobjectr   r   r   r   r   Ú<module>   s   