ó
®â0_c           @  sÜ   d  d l  m Z m Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m	 Z	 d  d l
 m Z m Z 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 d S(   iÿÿÿÿ(   t   print_functiont   unicode_literalsN(   t   apps(   t   NOT_PROVIDED(   t   datetime_safet   sixt   timezone(   t   inputi   (   t   MigrationLoadert   MigrationQuestionerc           B  s_   e  Z d  Z d	 d	 d	 d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(
   uÌ   
    Gives the autodetector responses to questions it might have.
    This base class has a built-in noninteractive mode, but the
    interactive subclass is what the command-line arguments will use.
    c         C  s.   | p	 i  |  _  | p t ƒ  |  _ | |  _ d  S(   N(   t   defaultst   sett   specified_appst   dry_run(   t   selfR
   R   R   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyt   __init__   s    c         C  sK  | |  j  k r t Sy t j | ƒ } Wn! t k
 rI |  j j d t ƒ SXt j	 | j
 ƒ \ } } | d k r |  j j d t ƒ Sy t j | ƒ } Wn! t k
 r· |  j j d t ƒ SXt | d d ƒ rë t j t j j | j ƒ ƒ } nG t | d ƒ r2t | j ƒ d k rt St j t | j ƒ d ƒ } n  t d „  | Dƒ ƒ Sd S(   u2   Should we create an initial migration for the app?u   ask_initialu   __file__u   __path__i   i    c         s  s*   |  ]  } | d  k r | j  d ƒ Vq d S(   u   __init__.pyu   .pyN(   t   endswith(   t   .0t   x(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pys	   <genexpr>8   s    N(   R   t   TrueR   t   get_app_configt   LookupErrorR
   t   gett   FalseR   t   migrations_modulet   labelt   Nonet	   importlibt   import_modulet   ImportErrort   getattrt   ost   listdirt   patht   dirnamet   __file__t   hasattrt   lent   __path__t   listt   any(   R   t	   app_labelt
   app_configt   migrations_import_patht   _R   t	   filenames(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyt   ask_initial   s(    !c         C  s   d S(   u"   Adding a NOT NULL field to a modelN(   R   (   R   t
   field_namet
   model_name(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyt   ask_not_null_addition:   s    c         C  s   d S(   u!   Changing a NULL field to NOT NULLN(   R   (   R   R/   R0   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyt   ask_not_null_alteration?   s    c         C  s   |  j  j d t ƒ S(   u   Was this field really renamed?u
   ask_rename(   R
   R   R   (   R   R0   t   old_namet   new_namet   field_instance(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyt
   ask_renameD   s    c         C  s   |  j  j d t ƒ S(   u   Was this model really renamed?u   ask_rename_model(   R
   R   R   (   R   t   old_model_statet   new_model_state(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyt   ask_rename_modelH   s    c         C  s   |  j  j d t ƒ S(   u-   Do you really want to merge these migrations?u	   ask_merge(   R
   R   R   (   R   R)   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyt	   ask_mergeL   s    c         C  s   d S(   u'   Adding an auto_now_add field to a modelN(   R   (   R   R/   R0   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyt   ask_auto_now_add_additionP   s    N(   t   __name__t
   __module__t   __doc__R   R   R.   R1   R2   R6   R9   R:   R;   (    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyR	      s   						t   InteractiveMigrationQuestionerc           B  s_   e  Z d
 d  „ Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(   c         C  sv   t  d | ƒ } | r' | d  k	 r' | Sx8 t | ƒ d k  sR | d j ƒ  d k ra t  d ƒ } q* W| d j ƒ  d k S(   Nu   %s i   i    u   ynu   Please answer yes or no: u   y(   R   R   R%   t   lower(   R   t   questiont   defaultt   result(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyt   _boolean_inputX   s    +c         C  s²   t  | ƒ x2 t | ƒ D]$ \ } } t  d | d | f ƒ q Wt d ƒ } x` t r­ y6 t | ƒ } d | k  o€ t | ƒ k n r‰ | SWn t k
 r n Xt d ƒ } qN Wd  S(   Nu    %s) %si   u   Select an option: i    u   Please select a valid option: (   t   printt	   enumerateR   R   t   intR%   t
   ValueError(   R   RA   t   choicest   it   choiceRC   t   value(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyt   _choice_input`   s    
	"u    c         C  s-  t  d ƒ | r& t  d j | ƒ ƒ n  t  d ƒ t  d ƒ xì t r(| r[ d j | ƒ } n d } t j ry t | ƒ } n t | ƒ j t j j	 ƒ } | rª | rª | } n  | s½ t  d ƒ q= | d k rÙ t j
 d	 ƒ q= y" t | i  i t d
 6t d 6ƒ SWq= t t f k
 r$} t  d | ƒ q= Xq= Wd S(   uÿ   
        Prompt for a default value.

        The ``default`` argument allows providing a custom default value (as a
        string) which will be shown to the user and used as the return value
        if the user doesn't provide any other input.
        u3   Please enter the default value now, as valid PythonuU   You can accept the default '{}' by pressing 'Enter' or you can provide another value.u]   The datetime and django.utils.timezone modules are available, so you can do e.g. timezone.nowu   Type 'exit' to exit this promptu   [default: {}] >>> u   >>> u;   Please enter some code, or 'exit' (with no quotes) to exit.u   exiti   u   datetimeu   timezoneu   Invalid input: %sN(   RE   t   formatR   R   t   PY3R   t   decodet   syst   stdint   encodingt   exitt   evalR   R   t   SyntaxErrort	   NameError(   R   RB   t   promptt   codet   e(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyt   _ask_defaultn   s0    


			"c         C  sX   |  j  sT |  j d | | f d d g ƒ } | d k rG t j d ƒ qT |  j ƒ  Sn  d S(   u"   Adding a NOT NULL field to a modelu¨   You are trying to add a non-nullable field '%s' to %s without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:ub   Provide a one-off default now (will be set on all existing rows with a null value for this column)u+   Quit, and let me add a default in models.pyi   i   N(   R   RM   RQ   RT   R[   R   (   R   R/   R0   RK   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyR1   –   s    	
c         C  sk   |  j  sg |  j d | | f d d d g ƒ } | d k r> t S| d k rZ t j d ƒ qg |  j ƒ  Sn  d S(   u!   Changing a NULL field to NOT NULLu¹   You are trying to change the nullable field '%s' on %s to non-nullable without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:ub   Provide a one-off default now (will be set on all existing rows with a null value for this column)u¬   Ignore for now, and let me handle existing rows with NULL myself (e.g. because you added a RunPython or RunSQL operation to handle NULL values in a previous data migration)u+   Quit, and let me add a default in models.pyi   i   N(   R   RM   R   RQ   RT   R[   R   (   R   R/   R0   RK   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyR2   ©   s    	
c         C  s/   d } |  j  | | | | | | j j f t ƒ S(   u   Was this field really renamed?u+   Did you rename %s.%s to %s.%s (a %s)? [y/N](   RD   t	   __class__R<   R   (   R   R0   R3   R4   R5   t   msg(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyR6   Â   s    c         C  s,   d } |  j  | | j | j | j f t ƒ S(   u   Was this model really renamed?u+   Did you rename the %s.%s model to %s? [y/N](   RD   R)   t   nameR   (   R   R7   R8   R]   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyR9   È   s    c         C  s   |  j  d d d t ƒ S(   NuH   
Merging will only work if the operations printed above do not conflict
u8   with each other (working on different fields or models)
u4   Do you want to merge these migration branches? [y/N](   RD   R   (   R   R)   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyR:   Î   s    c         C  s`   |  j  s\ |  j d j | | ƒ d d g ƒ } | d k rI t j d ƒ q\ |  j d d ƒ Sn  d S(	   u'   Adding an auto_now_add field to a modelu   You are trying to add the field '{}' with 'auto_now_add=True' to {} without a default; the database needs something to populate existing rows.
u@   Provide a one-off default now (will be set on all existing rows)u+   Quit, and let me add a default in models.pyi   i   RB   u   timezone.nowN(   R   RM   RN   RQ   RT   R[   R   (   R   R/   R0   RK   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyR;   Ö   s    		N(   R<   R=   R   RD   RM   R[   R1   R2   R6   R9   R:   R;   (    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyR?   V   s   	(					t!   NonInteractiveMigrationQuestionerc           B  s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C  s   t  j d ƒ d  S(   Ni   (   RQ   RT   (   R   R/   R0   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyR1   ì   s    c         C  s   t  S(   N(   R   (   R   R/   R0   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyR2   ð   s    c         C  s   t  j d ƒ d  S(   Ni   (   RQ   RT   (   R   R/   R0   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyR;   ô   s    (   R<   R=   R1   R2   R;   (    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyR_   ê   s   		(   t
   __future__R    R   R   R   RQ   t   django.appsR   t   django.db.models.fieldsR   t   django.utilsR   R   R   t   django.utils.six.movesR   t   loaderR   t   objectR	   R?   R_   (    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/db/migrations/questioner.pyt   <module>   s   G”