ó
®â0_c           @  sª   d  d l  m Z d  d l m Z d  d l m Z d d l m Z d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ	 d
 e f d „  ƒ  YZ
 e j r¦ d „  Z e e ƒ e
 _ n  d S(   iÿÿÿÿ(   t   unicode_literals(   t   router(   t   sixi   (   t	   Operationt   SeparateDatabaseAndStatec           B  sV   e  Z d  Z d d g Z d	 d	 d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(
   u"  
    Takes two lists of operations - ones that will be used for the database,
    and ones that will be used for the state change. This allows operations
    that don't support state change to have it applied, or have operations
    that affect the state or not the database, or so on.
    u   database_operationsu   state_operationsc         C  s"   | p	 g  |  _  | p g  |  _ d  S(   N(   t   database_operationst   state_operations(   t   selfR   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyt   __init__   s    c         C  sK   i  } |  j  r |  j  | d <n  |  j r8 |  j | d <n  |  j j g  | f S(   Nu   database_operationsu   state_operations(   R   R   t	   __class__t   __name__(   R   t   kwargs(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyt   deconstruct   s    			c         C  s(   x! |  j  D] } | j | | ƒ q
 Wd  S(   N(   R   t   state_forwards(   R   t	   app_labelt   statet   state_operation(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR   #   s    c         C  sP   xI |  j  D]> } | j ƒ  } | j | | ƒ | j | | | | ƒ | } q
 Wd  S(   N(   R   t   cloneR   t   database_forwards(   R   R   t   schema_editort
   from_statet   to_statet   database_operation(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR   '   s
    c         C  s„   i  } x7 |  j  D], } | | | <| j ƒ  } | j | | ƒ q Wx= t |  j  ƒ D], } | } | | } | j | | | | ƒ qP Wd  S(   N(   R   R   R   t   reversedt   database_backwards(   R   R   R   R   R   t	   to_statest   dbopR   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR   /   s    

c         C  s   d S(   Nu(   Custom state/database change combination(    (   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyt   describe>   s    N(   R
   t
   __module__t   __doc__t   serialization_expand_argst   NoneR   R   R   R   R   R   (    (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR   	   s   				t   RunSQLc           B  sn   e  Z d  Z d Z d
 d
 d
 e d „ Z d „  Z e d „  ƒ Z	 d „  Z
 d „  Z d „  Z d „  Z d	 „  Z RS(   uá   
    Runs some raw SQL. A reverse SQL statement may be provided.

    Also accepts a list of operations that represent the state change effected
    by this SQL change, in case it's custom column/table creation/deletion.
    u    c         C  s=   | |  _  | |  _ | p g  |  _ | p* i  |  _ | |  _ d  S(   N(   t   sqlt   reverse_sqlR   t   hintst   elidable(   R   R!   R"   R   R#   R$   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR   K   s
    		c         C  st   i |  j  d 6} |  j d  k	 r/ |  j | d <n  |  j rH |  j | d <n  |  j ra |  j | d <n  |  j j g  | f S(   Nu   sqlu   reverse_sqlu   state_operationsu   hints(   R!   R"   R   R   R#   R	   R
   (   R   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR   R   s    			c         C  s   |  j  d  k	 S(   N(   R"   R   (   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyt
   reversibleb   s    c         C  s(   x! |  j  D] } | j | | ƒ q
 Wd  S(   N(   R   R   (   R   R   R   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR   f   s    c         C  s8   t  j | j j | |  j  r4 |  j | |  j ƒ n  d  S(   N(   R   t   allow_migratet
   connectiont   aliasR#   t   _run_sqlR!   (   R   R   R   R   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR   j   s    c         C  sV   |  j  d  k r t d ƒ ‚ n  t j | j j | |  j  rR |  j | |  j  ƒ n  d  S(   Nu!   You cannot reverse this operation(	   R"   R   t   NotImplementedErrorR   R&   R'   R(   R#   R)   (   R   R   R   R   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR   n   s    c         C  s   d S(   Nu   Raw SQL operation(    (   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR   t   s    c         C  sà   t  | t t f ƒ r‘ xÄ | D]n } d  } t  | t t f ƒ rw t | ƒ } | d k rd | \ } } qw t d | ƒ ‚ n  | j | d | ƒq WnK | t j k rÜ | j	 j
 j | ƒ } x$ | D] } | j | d d  ƒq¼ Wn  d  S(   Ni   u   Expected a 2-tuple but got %dt   params(   t
   isinstancet   listt   tupleR   t   lent
   ValueErrort   executeR    t   noopR'   t   opst   prepare_sql_script(   R   R   t   sqlsR!   R+   t   elementst
   statementst	   statement(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR)   w   s    N(   R
   R   R   R2   R   t   FalseR   R   t   propertyR%   R   R   R   R   R)   (    (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR    B   s   					t	   RunPythonc           B  st   e  Z d  Z e Z d	 d	 d	 e d „ Z d „  Z e d „  ƒ Z	 d „  Z
 d „  Z d „  Z d „  Z e d „  ƒ Z RS(
   uT   
    Runs Python code in a context suitable for doing versioned ORM operations.
    c         C  s…   | |  _  t | ƒ s$ t d ƒ ‚ n  | |  _ | d  k rE d  |  _ n$ t | ƒ s` t d ƒ ‚ n  | |  _ | pr i  |  _ | |  _ d  S(   Nu*   RunPython must be supplied with a callableu2   RunPython must be supplied with callable arguments(   t   atomict   callableR0   t   codeR   t   reverse_codeR#   R$   (   R   R>   R?   R<   R#   R$   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR      s    			c         C  sz   i |  j  d 6} |  j d  k	 r/ |  j | d <n  |  j d  k	 rN |  j | d <n  |  j rg |  j | d <n  |  j j g  | f S(   Nu   codeu   reverse_codeu   atomicu   hints(   R>   R?   R   R<   R#   R	   R
   (   R   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR   Ÿ   s    		c         C  s   |  j  d  k	 S(   N(   R?   R   (   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR%   ¯   s    c         C  s   d  S(   N(    (   R   R   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR   ³   s    c         C  sB   | j  ƒ  t j | j j | |  j  r> |  j | j | ƒ n  d  S(   N(   t   clear_delayed_apps_cacheR   R&   R'   R(   R#   R>   t   apps(   R   R   R   R   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR   ¸   s    
c         C  sV   |  j  d  k r t d ƒ ‚ n  t j | j j | |  j  rR |  j  | j | ƒ n  d  S(   Nu!   You cannot reverse this operation(	   R?   R   R*   R   R&   R'   R(   R#   RA   (   R   R   R   R   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR   Ã   s    c         C  s   d S(   Nu   Raw Python operation(    (   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR   É   s    c         C  s   d  S(   N(   R   (   RA   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR2   Ì   s    N(   R
   R   R   R9   t   reduces_to_sqlR   R   R   R:   R%   R   R   R   R   t   staticmethodR2   (    (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR;   ˆ   s   					c         C  s   d  S(   N(   R   (   RA   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyR2   Ô   s    N(   t
   __future__R    t	   django.dbR   t   django.utilsR   t   baseR   R   R    R;   t   PY2R2   RC   (    (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/operations/special.pyt   <module>   s   9FK		