ó
®â0_c           @  sô   d  Z  d d l m Z d d l Z d d l Z d d l m Z d d l m Z d d l	 m
 Z
 d d l m Z d d l m Z m Z 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 S(   u*   
Management utility to create superusers.
iÿÿÿÿ(   t   unicode_literalsN(   t   get_user_model(   t   get_default_username(   t   validate_password(   t
   exceptions(   t   BaseCommandt   CommandError(   t   DEFAULT_DB_ALIAS(   t	   force_str(   t   input(   t   capfirstt   NotRunningInTTYExceptionc           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sY   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/management/commands/createsuperuser.pyR      s   t   Commandc           B  sD   e  Z d  Z e Z d „  Z d „  Z d „  Z d „  Z d d „ Z
 RS(   u   Used to create a superuser.c         O  sG   t  t |  ƒ j | | Ž  t ƒ  |  _ |  j j j |  j j ƒ |  _ d  S(   N(	   t   superR   t   __init__R   t	   UserModelt   _metat	   get_fieldt   USERNAME_FIELDt   username_field(   t   selft   argst   kwargs(    (    sY   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/management/commands/createsuperuser.pyR      s    c         C  sÈ   | j  d |  j j d |  j j d d  d d ƒ| j  d d d d	 d d
 d t d d |  j j ƒ| j  d d d d d d t d d ƒx; |  j j D]- } | j  d | d | d d  d d | ƒq“ Wd  S(   Nu   --%st   destt   defaultt   helpu&   Specifies the login for the superuser.u	   --noinputu
   --no-inputt   actionu   store_falseu   interactiveuò   Tells Django to NOT prompt the user for input of any kind. You must use --%s with --noinput, along with an option for any other required field. Superusers created with --noinput will not be able to log in until they're given a valid password.u
   --databaseu   storeu   databaseu4   Specifies the database to use. Default is "default".u#   Specifies the %s for the superuser.(   t   add_argumentR   R   t   Nonet   TrueR   t   REQUIRED_FIELDS(   R   t   parsert   field(    (    sY   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/management/commands/createsuperuser.pyt   add_arguments!   s"    	c         O  s1   | j  d t j ƒ |  _ t t |  ƒ j | | Ž  S(   Nu   stdin(   t   gett   syst   stdinR   R   t   execute(   R   R   t   options(    (    sY   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/management/commands/createsuperuser.pyR'   =   s    c         O  sÉ  | |  j  j } | d } d  } i  } i  } | d sy› | sX t d |  j  j ƒ ‚ n  |  j j | d  ƒ } x` |  j  j D]R } | | r¼ |  j  j j | ƒ }	 |	 j | | d  ƒ | | <qz t d | ƒ ‚ qz WWqct	 j
 k
 r}
 t d j |
 j ƒ ƒ ‚ qcXn^t ƒ  } yt |  j d ƒ rB|  j j ƒ  rBt d ƒ ‚ n  |  j j } xþ | d  k rNt | ƒ } | r€| d | 7} n  |  j j } t d | | r·d	 | j j j | j f n d
 f ƒ } |  j |  j | | ƒ } | sèqQn  |  j j rQy  |  j  j j | ƒ j | ƒ Wn |  j  j k
 r-qKX|  j j  d | ƒ d  } qQqQWxà |  j  j D]Ò } |  j  j j | ƒ }	 | | | | <x¦ | | d  k r-t d t |	 j ƒ |	 j rÕd	 |	 j j j j |	 j j f n d
 f ƒ } |  j |	 | ƒ } | | | <| | | <|	 j rˆ|	 j j | ƒ | | <qˆqˆWq\WxÜ | d  k rt! j! ƒ  } t! j! t d ƒ ƒ } | | k rŠ|  j j  d ƒ d  } q5n  | j" ƒ  d
 k r¸|  j j  d ƒ d  } q5n  y t# | |  j  |   ƒ Wq5t	 j
 k
 r} |  j j  d j | j ƒ ƒ d  } q5Xq5WWnN t$ k
 rB|  j j  d ƒ t% j& d ƒ n! t k
 rb|  j' j  d ƒ n X| rÅ| | |  j  j <| | d <|  j  j j | ƒ j( |   | d d k rÅ|  j' j  d ƒ qÅn  d  S(   Nu   databaseu   interactiveu!   You must use --%s with --noinput.u   ; u   isattyu   Not running in a TTYu    (leave blank to use '%s')u   %s%s: u    (%s.%s)u    u    Error: That %s is already taken.u   Password (again): u#   Error: Your passwords didn't match.u&   Error: Blank passwords aren't allowed.u   
u   
Operation cancelled.i   u‡   Superuser creation skipped due to not running in a TTY. You can run `manage.py createsuperuser` in your project to create one manually.u   passwordu	   verbosityu   Superuser created successfully.()   R   R   R   R   R   t   cleanR    R   R   R   t   ValidationErrort   joint   messagesR   t   hasattrR&   t   isattyR   t   verbose_nameR
   t   remote_fieldR   t   modelt   object_namet
   field_namet   get_input_datat   uniquet   _default_managert
   db_managert   get_by_natural_keyt   DoesNotExistt   stderrt   writet   getpasst   stripR   t   KeyboardInterruptR%   t   exitt   stdoutt   create_superuser(   R   R   R(   t   usernamet   databaset   passwordt	   user_datat   fake_user_dataR3   R"   t   et   default_usernamet   verbose_field_namet	   input_msgt   username_relt   messaget   input_valuet	   password2t   err(    (    sY   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/management/commands/createsuperuser.pyt   handleA   s     


	"/ 8

	!	
c         C  s€   t  | ƒ } | r' | d k r' | } n  y | j | d ƒ } Wn< t j k
 r{ } |  j j d d j | j ƒ ƒ d } n X| S(   um   
        Override this method if you want to customize data inputs or
        validation exceptions.
        u    u	   Error: %su   ; N(	   R	   R)   R   R   R*   R:   R;   R+   R,   (   R   R"   RL   R   t	   raw_valuet   valRG   (    (    sY   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/management/commands/createsuperuser.pyR4   »   s    	 
N(   R   R   R   R   t   requires_migrations_checksR   R#   R'   RP   R   R4   (    (    (    sY   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/management/commands/createsuperuser.pyR      s   				z(   t   __doc__t
   __future__R    R<   R%   t   django.contrib.authR   t   django.contrib.auth.managementR   t'   django.contrib.auth.password_validationR   t   django.coreR   t   django.core.management.baseR   R   t	   django.dbR   t   django.utils.encodingR   t   django.utils.six.movesR	   t   django.utils.textR
   t	   ExceptionR   R   (    (    (    sY   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/management/commands/createsuperuser.pyt   <module>   s   