

_V                 @   sa   d  Z  d d l Z d d l m Z Gd d   d e  Z Gd d   d e  Z d d d	  Z d S)
a  
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.
    N)RemovedInDjango110Warningc                   s(   e  Z d  Z d Z   f d d   Z   S)SubfieldBasez
    A metaclass for custom Field subclasses. This ensures the model's attribute
    has the descriptor protocol attached to it.
    c                sV   t  j d t d d t t |   j |  | | |  } t | | j d   | _ | S)NzBSubfieldBase has been deprecated. Use Field.from_db_value instead.
stacklevel   contribute_to_class)	warningswarnr   superr   __new__make_contribgetr   )clsnamebasesattrs	new_class)	__class__ E/tmp/pip-build-ghmbqnp_/Django/django/db/models/fields/subclassing.pyr
      s    	!zSubfieldBase.__new__)__name__
__module____qualname____doc__r
   r   r   )r   r   r      s   r   c               @   s=   e  Z d  Z d Z d d   Z d d d  Z d d   Z d S)	CreatorzT
    A placeholder class that provides a way to set the attribute on the model.
    c             C   s   | |  _  d  S)N)field)selfr   r   r   r   __init__#   s    zCreator.__init__Nc             C   s!   | d  k r |  S| j  |  j j S)N)__dict__r   r   )r   objtyper   r   r   __get__&   s    zCreator.__get__c             C   s#   |  j  j |  | j |  j  j <d  S)N)r   Z	to_pythonr   r   )r   r   valuer   r   r   __set__+   s    zCreator.__set__)r   r   r   r   r   r    r"   r   r   r   r   r      s   r   c                s      f d d   } | S)aP  
    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                sU     r   |  | | |  n t   |   j | | |  t | |  j t |    d  S)N)r	   r   setattrr   r   )r   r   r   kwargs)func
superclassr   r   r   8   s    z)make_contrib.<locals>.contribute_to_classr   )r&   r%   r   r   )r%   r&   r   r   /   s    	r   )	r   r   Zdjango.utils.deprecationr   r   r   objectr   r   r   r   r   r   <module>   s
   