ó
EõMPc           @   sB   d  Z  d e f d „  ƒ  YZ d e f d „  ƒ  YZ d d „ Z d S(   s  
Convenience routines for creating non-trivial Field subclasses, as well as
backwards compatibility utilities.

Add SubfieldBase as the metaclass for your Field subclass, implement
to_python() and the other necessary methods and everything will work
seamlessly.
t   SubfieldBasec           B   s   e  Z d  Z d „  Z RS(   s…   
    A metaclass for custom Field subclasses. This ensures the model's attribute
    has the descriptor protocol attached to it.
    c         C   s@   t  t |  ƒ j |  | | | ƒ } t | | j d ƒ ƒ | _ | S(   Nt   contribute_to_class(   t   superR    t   __new__t   make_contribt   getR   (   t   clst   namet   basest   attrst	   new_class(    (    s<   ../Django//lib/python/django/db/models/fields/subclassing.pyR      s    !(   t   __name__t
   __module__t   __doc__R   (    (    (    s<   ../Django//lib/python/django/db/models/fields/subclassing.pyR    
   s   t   Creatorc           B   s,   e  Z d  Z d „  Z d d „ Z d „  Z RS(   sT   
    A placeholder class that provides a way to set the attribute on the model.
    c         C   s   | |  _  d  S(   N(   t   field(   t   selfR   (    (    s<   ../Django//lib/python/django/db/models/fields/subclassing.pyt   __init__   s    c         C   s,   | d  k r t d ƒ ‚ n  | j |  j j S(   Ns%   Can only be accessed via an instance.(   t   Nonet   AttributeErrort   __dict__R   R   (   R   t   objt   type(    (    s<   ../Django//lib/python/django/db/models/fields/subclassing.pyt   __get__   s    c         C   s#   |  j  j | ƒ | j |  j  j <d  S(   N(   R   t	   to_pythonR   R   (   R   R   t   value(    (    s<   ../Django//lib/python/django/db/models/fields/subclassing.pyt   __set__"   s    N(   R   R   R   R   R   R   R   (    (    (    s<   ../Django//lib/python/django/db/models/fields/subclassing.pyR      s   	c            s   ‡  ‡ f d †  } | S(   sP  
    Returns a suitable contribute_to_class() method for the Field subclass.

    If 'func' is passed in, it is the existing contribute_to_class() method on
    the subclass and it is called before anything else. It is assumed in this
    case that the existing contribute_to_class() calls all the necessary
    superclass methods.
    c            sO   ˆ r ˆ |  | | ƒ n t  ˆ  |  ƒ j | | ƒ t | |  j t |  ƒ ƒ d  S(   N(   R   R   t   setattrR   R   (   R   R   R   (   t
   superclasst   func(    s<   ../Django//lib/python/django/db/models/fields/subclassing.pyR   .   s    (    (   R   R   R   (    (   R   R   s<   ../Django//lib/python/django/db/models/fields/subclassing.pyR   %   s    	N(   R   R   R    t   objectR   R   R   (    (    (    s<   ../Django//lib/python/django/db/models/fields/subclassing.pyt   <module>   s   