ó
®â0_c           @  s´  d  d l  m Z d  d l Z d  d l m Z d  d l m Z d  d l m Z m	 Z	 d  d l
 m Z m Z d  d l m Z d  d l m Z i  Z d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e e d <d e f d „  ƒ  YZ e e d <d e f d „  ƒ  YZ e e d <d e f d „  ƒ  YZ e e d <d e f d „  ƒ  YZ e e d <d e f d „  ƒ  YZ e e d <d e f d  „  ƒ  YZ e e d! <d" e f d# „  ƒ  YZ e e d$ <d% e f d& „  ƒ  YZ e e d' <d( e f d) „  ƒ  YZ e e d* <d+ e f d, „  ƒ  YZ e e d- <d. e f d/ „  ƒ  YZ e e d0 <d1 e f d2 „  ƒ  YZ  e  e d3 <d4 e f d5 „  ƒ  YZ! e! e d6 <d7 e f d8 „  ƒ  YZ" e" e d9 <d: e f d; „  ƒ  YZ# e# e d< <d= e f d> „  ƒ  YZ$ e$ e d? <d@ e f dA „  ƒ  YZ% e% e dB <dC e f dD „  ƒ  YZ& e& e dE <dF e f dG „  ƒ  YZ' e' e dH <dI e f dJ „  ƒ  YZ( e( e dK <dL e f dM „  ƒ  YZ) e) e dN <dO e f dP „  ƒ  YZ* e* e dQ <dR e f dS „  ƒ  YZ+ e+ e dT <dU e f dV „  ƒ  YZ, e, e dW <dX e f dY „  ƒ  YZ- e- e dZ <d[ e f d\ „  ƒ  YZ. d] e. f d^ „  ƒ  YZ/ e/ e d_ <d` e. f da „  ƒ  YZ0 e0 e db <dc e. f dd „  ƒ  YZ1 e1 e de <df e. f dg „  ƒ  YZ2 e2 e dh <di e. f dj „  ƒ  YZ3 e3 e dk <d S(l   iÿÿÿÿ(   t   unicode_literalsN(   t   FieldDoesNotExist(   t
   LOOKUP_SEP(   t   Colt
   Expression(   t   Lookupt	   Transform(   t   Query(   t   sixt   RasterBandTransformc           B  s   e  Z d  „  Z RS(   c         C  s   | j  |  j ƒ S(   N(   t   compilet   lhs(   t   selft   compilert
   connection(    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyt   as_sql   s    (   t   __name__t
   __module__R   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR	      s   t	   GISLookupc           B  sn   e  Z d Z d Z e Z d Z d Z d  „  Z	 e
 d „  ƒ Z e d „ Z d „  Z d „  Z d „  Z d „  Z RS(   c         O  s&   t  t |  ƒ j | | Ž  i  |  _ d  S(   N(   t   superR   t   __init__t   template_params(   R   t   argst   kwargs(    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR      s    c         C  sµ   d d l  m } | j t ƒ } | j ƒ  | j ƒ  } yJ | j | ƒ } x4 t | ƒ r} | j j	 j
 } | j | j ƒ  ƒ } qJ WWn t t f k
 r™ t SXt | | ƒ r­ | St Sd S(   u”  
        Utility for checking the given lookup with the given model options.
        The lookup is a string either specifying the geographic field, e.g.
        'point, 'the_geom', or a related lookup on a geographic field like
        'address__point'.

        If a BaseSpatialField exists according to the given lookup on the model
        options, it will be returned. Otherwise return None.
        iÿÿÿÿ(   t   BaseSpatialFieldN(   t#   django.contrib.gis.db.models.fieldsR   t   splitR   t   reverset   popt	   get_fieldt   lent   remote_fieldt   modelt   _metaR   t   AttributeErrort   Falset
   isinstance(   t   clst   optst   lookupR   t
   field_listt   fld_namet   geo_fld(    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyt   _check_geo_field   s    
c         C  s±   | r& d |  _  |  j j d |  _ d St |  j t ƒ rN |  j j d |  _ n	 d |  _ |  j d |  _  t |  j ƒ d k r |  j d |  _ n |  j d f |  j d |  _ d S(   u   
        Extract the lhs band index from the band transform class and the rhs
        band index from the input tuple.
        i   Ni    i   (   t   band_rhsR   t
   band_indext   band_lhsR$   R	   t   rhsR   (   R   t   only_lhs(    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyt   process_band_indicesG   s    		c         C  s^   t  | t t f ƒ r? | j j | d ƒ g t | ƒ d } n | j j | ƒ g } d | f S(   Ni    i   u   %s(   R$   t   tuplet   listt   opst   Adapter(   R   t   valueR   t   params(    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyt   get_db_prep_lookup^   s    *c         C  sº  t  |  j t ƒ r+ t t |  ƒ j | | ƒ S|  j } t  |  j t ƒ r‚ |  j j } t | d ƒ sp t	 d ƒ ‚ n  | j
 |  j _
 nï t  |  j t ƒ r£ t	 d ƒ ‚ nÎ t  |  j t t f ƒ rL|  j d } t |  j ƒ d k rí |  j d k st |  j ƒ d k r|  j d k r|  j ƒ  qqt |  j ƒ d k rqt	 d |  j ƒ ‚ qqn% t  |  j t ƒ rq|  j d	 t ƒ n  t t |  ƒ j | | ƒ \ } } | j j |  j j | | ƒ } | | f S(
   Nu   sridu(   No geographic field found in expression.u5   Complex expressions not supported for spatial fields.i    i   u   relatei   u   Tuple too long for lookup %s.R0   (   R$   R/   R   R   R   t   process_rhsR   t   output_fieldt   hasattrt
   ValueErrort   sridR   R3   R2   R   t   lookup_nameR1   R   R	   t   TrueR4   t   get_geom_placeholder(   R   R   R   t   geomR*   R/   t
   rhs_params(    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR9   g   s,    	%$!c         C  s   | j  j |  j S(   N(   R4   t   gis_operatorsR>   (   R   R   R/   (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyt
   get_rhs_op†   s    c   	      C  s   |  j  | | ƒ \ } } |  j | | ƒ \ } } | j | ƒ i | d 6| d 6d d 6} | j |  j ƒ |  j | | ƒ } | j | |  | | ƒ S(   Nu   lhsu   rhsu   %su   value(   t   process_lhsR9   t   extendt   updateR   RD   R   (	   R   R   R   t   lhs_sqlt
   sql_paramst   rhs_sqlRB   R   t   rhs_op(    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR   Œ   s    N(   R   R   t   Nonet   sql_templatet   transform_funcR#   t   distanceR,   R.   R   t   classmethodR+   R1   R8   R9   RD   R   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR      s   	(				t   OverlapsLeftLookupc           B  s   e  Z d  Z d Z RS(   uy   
    The overlaps_left operator returns true if A's bounding box overlaps or is to the
    left of B's bounding box.
    u   overlaps_left(   R   R   t   __doc__R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRQ   ›   s   u   overlaps_leftt   OverlapsRightLookupc           B  s   e  Z d  Z d Z RS(   u}   
    The 'overlaps_right' operator returns true if A's bounding box overlaps or is to the
    right of B's bounding box.
    u   overlaps_right(   R   R   RR   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRS   ¦   s   u   overlaps_rightt   OverlapsBelowLookupc           B  s   e  Z d  Z d Z RS(   us   
    The 'overlaps_below' operator returns true if A's bounding box overlaps or is below
    B's bounding box.
    u   overlaps_below(   R   R   RR   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRT   ±   s   u   overlaps_belowt   OverlapsAboveLookupc           B  s   e  Z d  Z d Z RS(   us   
    The 'overlaps_above' operator returns true if A's bounding box overlaps or is above
    B's bounding box.
    u   overlaps_above(   R   R   RR   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRU   ¼   s   u   overlaps_abovet
   LeftLookupc           B  s   e  Z d  Z d Z RS(   uo   
    The 'left' operator returns true if A's bounding box is strictly to the left
    of B's bounding box.
    u   left(   R   R   RR   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRV   Ç   s   u   leftt   RightLookupc           B  s   e  Z d  Z d Z RS(   uq   
    The 'right' operator returns true if A's bounding box is strictly to the right
    of B's bounding box.
    u   right(   R   R   RR   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRW   Ò   s   u   rightt   StrictlyBelowLookupc           B  s   e  Z d  Z d Z RS(   up   
    The 'strictly_below' operator returns true if A's bounding box is strictly below B's
    bounding box.
    u   strictly_below(   R   R   RR   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRX   Ý   s   u   strictly_belowt   StrictlyAboveLookupc           B  s   e  Z d  Z d Z RS(   up   
    The 'strictly_above' operator returns true if A's bounding box is strictly above B's
    bounding box.
    u   strictly_above(   R   R   RR   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRY   è   s   u   strictly_abovet   SameAsLookupc           B  s   e  Z d  Z d Z RS(   uÃ   
    The "~=" operator is the "same as" operator. It tests actual geometric
    equality of two features. So if A and B are the same feature,
    vertex-by-vertex, the operator returns true.
    u   same_as(   R   R   RR   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRZ   ó   s   u   same_ast   ExactLookupc           B  s   e  Z d  Z RS(   u   exact(   R   R   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR[   ÿ   s   u   exactt   BBContainsLookupc           B  s   e  Z d  Z d Z RS(   uq   
    The 'bbcontains' operator returns true if A's bounding box completely contains
    by B's bounding box.
    u
   bbcontains(   R   R   RR   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR\     s   u
   bbcontainst   BBOverlapsLookupc           B  s   e  Z d  Z d Z RS(   u_   
    The 'bboverlaps' operator returns true if A's bounding box overlaps B's bounding box.
    u
   bboverlaps(   R   R   RR   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR]     s   u
   bboverlapst   ContainedLookupc           B  s   e  Z d  Z d Z RS(   ut   
    The 'contained' operator returns true if A's bounding box is completely contained
    by B's bounding box.
    u	   contained(   R   R   RR   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR^     s   u	   containedt   ContainsLookupc           B  s   e  Z d  Z RS(   u   contains(   R   R   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR_   +  s   u   containst   ContainsProperlyLookupc           B  s   e  Z d  Z RS(   u   contains_properly(   R   R   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR`   2  s   u   contains_properlyt   CoveredByLookupc           B  s   e  Z d  Z RS(   u	   coveredby(   R   R   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRa   9  s   u	   coveredbyt   CoversLookupc           B  s   e  Z d  Z RS(   u   covers(   R   R   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRb   @  s   u   coverst   CrossesLookupc           B  s   e  Z d  Z RS(   u   crosses(   R   R   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRc   G  s   u   crossest   DisjointLookupc           B  s   e  Z d  Z RS(   u   disjoint(   R   R   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRd   N  s   u   disjointt   EqualsLookupc           B  s   e  Z d  Z RS(   u   equals(   R   R   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRe   U  s   u   equalst   IntersectsLookupc           B  s   e  Z d  Z RS(   u
   intersects(   R   R   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRf   \  s   u
   intersectst   IsValidLookupc           B  s   e  Z d  Z d Z d „  Z RS(   u   isvalidu   %(func)s(%(lhs)s)c         C  sž   |  j  j j d k r$ t d ƒ ‚ n  | j j |  j } |  j | | ƒ \ } } | j | |  i | j	 d 6| d 6| ƒ \ } } |  j
 s” d | } n  | | f S(   Nu   RASTERu8   The isvalid lookup is only available on geometry fields.u   funcu   lhsu   NOT (   R   t   fieldt	   geom_typeR<   R4   RC   R>   RE   R   t   funcR/   (   R   R   R   t   gis_opt   sqlR7   (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR   g  s    /	(   R   R   R>   RM   R   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRg   c  s   u   isvalidt   OverlapsLookupc           B  s   e  Z d  Z RS(   u   overlaps(   R   R   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRm   u  s   u   overlapst   RelateLookupc           B  s,   e  Z d  Z d Z e j d ƒ Z d „  Z RS(   u   relateu   %(func)s(%(lhs)s, %(rhs)s, %%s)u   ^[012TF\*]{9}$c         C  s³   t  | ƒ d k r! t d ƒ ‚ n  | j j |  j } t | d ƒ rW | j | d ƒ nC | d } t | t j	 ƒ s‡ |  j
 j | ƒ rš t d | ƒ ‚ n  t t |  ƒ j | | ƒ S(   Ni   u!   relate must be passed a two-tupleu   check_relate_argumenti   u)   Invalid intersection matrix pattern "%s".(   R   R<   R4   RC   R>   R;   t   check_relate_argumentR$   R   t   string_typest   pattern_regext   matchR   Rn   R8   (   R   R6   R   t
   backend_opt   pattern(    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR8     s    
&(   R   R   R>   RM   t   reR
   Rq   R8   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRn   |  s   u   relatet   TouchesLookupc           B  s   e  Z d  Z RS(   u   touches(   R   R   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRv   ’  s   u   touchest   WithinLookupc           B  s   e  Z d  Z RS(   u   within(   R   R   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRw   ™  s   u   withint   DistanceLookupBasec           B  s   e  Z e Z d  Z d „  Z RS(   u+   %(func)s(%(lhs)s, %(rhs)s) %(op)s %(value)sc         C  s¤  t  |  j t t f ƒ s? d t |  j ƒ k o9 d k n rU t d |  j ƒ ‚ n8 t |  j ƒ d k r |  j d d k r t d ƒ ‚ n  t |  j ƒ d k rÃ |  j d d k rÃ |  j ƒ  n  | j j	 |  j d ƒ g } |  j d } t
 | d	 ƒ r?| j | j ƒ } | j | ƒ \ } } | |  j d
 <| j | ƒ n9 | | j j |  j j | f |  j d |  j d t ƒ7} | j j |  j j | d | ƒ } | | f S(   Ni   i   u2   2, 3, or 4-element tuple required for '%s' lookup.i   u   spheroiduG   For 4-element tuples the last argument must be the 'speroid' directive.i    i   u   resolve_expressionu   valuet   handle_spheroid(   R$   R/   R2   R3   R   R<   R>   R1   R4   R5   R;   t   resolve_expressiont   queryR
   R   RF   t   get_distanceR   R:   R#   R@   (   R   R   R   R7   t
   dist_paramRl   t   expr_paramsR/   (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR9   ¤  s$    ?))"(   R   R   R?   RO   RM   R9   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRx      s   t   DWithinLookupc           B  s   e  Z d  Z d Z RS(   u   dwithinu   %(func)s(%(lhs)s, %(rhs)s, %%s)(   R   R   R>   RM   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR   À  s   u   dwithint   DistanceGTLookupc           B  s   e  Z d  Z RS(   u   distance_gt(   R   R   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR€   È  s   u   distance_gtt   DistanceGTELookupc           B  s   e  Z d  Z RS(   u   distance_gte(   R   R   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR   Ï  s   u   distance_gtet   DistanceLTLookupc           B  s   e  Z d  Z RS(   u   distance_lt(   R   R   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyR‚   Ö  s   u   distance_ltt   DistanceLTELookupc           B  s   e  Z d  Z RS(   u   distance_lte(   R   R   R>   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyRƒ   Ý  s   u   distance_lte(4   t
   __future__R    Ru   t   django.core.exceptionsR   t   django.db.models.constantsR   t   django.db.models.expressionsR   R   t   django.db.models.lookupsR   R   t   django.db.models.sql.queryR   t   django.utilsR   t   gis_lookupsR	   R   RQ   RS   RT   RU   RV   RW   RX   RY   RZ   R[   R\   R]   R^   R_   R`   Ra   Rb   Rc   Rd   Re   Rf   Rg   Rm   Rn   Rv   Rw   Rx   R   R€   R   R‚   Rƒ   (    (    (    sF   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/models/lookups.pyt   <module>   s’   ‡







	

















 



