ó
J~Pc           @   s@   d  Z  d d l m Z d d l m Z d e f d     YZ d S(   sų   
The GeometryProxy object, allows for lazy-geometries.  The proxy uses
Python descriptors for instantiating and setting Geometry objects
corresponding to geographic model fields.

Thanks to Robert Coup for providing this functionality (see #4322).
i’’’’(   t
   memoryview(   t   sixt   GeometryProxyc           B   s&   e  Z d    Z d d  Z d   Z RS(   c         C   s   | |  _  | |  _ d S(   sp   
        Proxy initializes on the given Geometry class (not an instance) and
        the GeometryField.
        N(   t   _fieldt   _klass(   t   selft   klasst   field(    (    s;   ../Django//lib/python/django/contrib/gis/db/models/proxy.pyt   __init__   s    	c         C   s   | d k r |  S| j |  j j } t | |  j  r> | } nF | d k sV | d k r_ d } n% |  j |  } t | |  j j |  | S(   sź   
        This accessor retrieves the geometry, initializing it using the geometry
        class specified during initialization and the HEXEWKB value of the field.
        Currently, only GEOS or OGR geometries are supported.
        t    N(   t   Nonet   __dict__R   t   attnamet
   isinstanceR   t   setattr(   R   t   objt   typet
   geom_valuet   geom(    (    s;   ../Django//lib/python/django/contrib/gis/db/models/proxy.pyt   __get__   s    		c         C   sŹ   |  j  j } t | |  j  ri t | j  j   | k sE | d k ri | j d k r³ |  j  j | _ q³ nJ | d k s³ t | t j	 t
 f  r n" t d | j j t |  f   | | j |  j  j <| S(   sĢ   
        This accessor sets the proxied geometry with the geometry class
        specified during initialization.  Values of None, HEXEWKB, or WKT may
        be used to set the geometry as well.
        t   GEOMETRYs2   cannot set %s GeometryProxy with value of type: %sN(   R   t	   geom_typeR   R   t   strt   uppert   sridR
   R   t   string_typesR    t	   TypeErrort	   __class__t   __name__R   R   R   (   R   R   t   valuet   gtype(    (    s;   ../Django//lib/python/django/contrib/gis/db/models/proxy.pyt   __set__,   s    9 %"N(   R   t
   __module__R   R
   R   R   (    (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/proxy.pyR      s   	N(   t   __doc__t   django.contrib.gisR    t   django.utilsR   t   objectR   (    (    (    s;   ../Django//lib/python/django/contrib/gis/db/models/proxy.pyt   <module>   s   