ó
®â0_c           @  sÁ  d  d l  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  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 m Z e j d d ƒ d „  ƒ Z! d „  Z" d d d „ Z# d d d „ Z$ d d „ Z% d d „ Z& e e& e ƒ Z' d e( f d „  ƒ  YZ) d e( f d „  ƒ  YZ* d e( f d „  ƒ  YZ+ d e( f d „  ƒ  YZ, d S(   iÿÿÿÿ(   t   unicode_literalsN(   t   SequenceMatcher(   t   settings(   t   FieldDoesNotExistt   ImproperlyConfiguredt   ValidationError(   t	   lru_cache(   t   upath(   t
   force_text(   t   lazy(   t   format_html(   t   import_string(   t   string_typest	   text_type(   t   ugettextt	   ungettextt   maxsizec           C  s   t  t j ƒ S(   N(   t   get_password_validatorsR   t   AUTH_PASSWORD_VALIDATORS(    (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyt   get_default_password_validators   s    c         C  s|   g  } xo |  D]g } y t  | d ƒ } Wn+ t k
 rT d } t | | d ƒ ‚ n X| j | | j d i  ƒ   ƒ q W| S(   Nu   NAMEuZ   The module in NAME could not be imported: %s. Check your AUTH_PASSWORD_VALIDATORS setting.u   OPTIONS(   R   t   ImportErrorR   t   appendt   get(   t   validator_configt
   validatorst	   validatort   klasst   msg(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyR      s    #c         C  s   g  } | d k r t ƒ  } n  xE | D]= } y | j |  | ƒ Wq% t k
 ra } | j | ƒ q% Xq% W| r{ t | ƒ ‚ n  d S(   uÈ   
    Validate whether the password meets all validator requirements.

    If the password is valid, return ``None``.
    If the password is invalid, raise ValidationError with all error messages.
    N(   t   NoneR   t   validateR   R   (   t   passwordt   usert   password_validatorst   errorsR   t   error(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyt   validate_password(   s    c         C  sO   | d k r t ƒ  } n  x0 | D]( } t | d d „  ƒ } | |  | ƒ q Wd S(   uy   
    Inform all validators that have implemented a password_changed() method
    that the password has been changed.
    u   password_changedc          W  s   d  S(   N(   R   (   t   a(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyt   <lambda>C   t    N(   R   R   t   getattr(   R   R   R    R   t   password_changed(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyR(   ;   s
    c         C  sF   g  } |  d k r t ƒ  }  n  x! |  D] } | j | j ƒ  ƒ q% W| S(   uG   
    Return a list of all help texts of all configured validators.
    N(   R   R   R   t   get_help_text(   R    t
   help_textsR   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyt   password_validators_help_textsG   s    c         C  sI   t  |  ƒ } g  | D] } t d | ƒ ^ q } | rE d d j | ƒ Sd S(   u`   
    Return an HTML string with all help texts of all configured validators
    in an <ul>.
    u   <li>{}</li>u   <ul>%s</ul>u    (   R+   R
   t   join(   R    R*   t	   help_textt
   help_items(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyt#   _password_validators_help_text_htmlS   s    "t   MinimumLengthValidatorc           B  s/   e  Z d  Z d d „ Z d d „ Z d „  Z RS(   u?   
    Validate whether the password is of a minimum length.
    i   c         C  s   | |  _  d  S(   N(   t
   min_length(   t   selfR1   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyt   __init__d   s    c         C  sM   t  | ƒ |  j k  rI t t d d |  j ƒ d d d i |  j d 6ƒ‚ n  d  S(   NuN   This password is too short. It must contain at least %(min_length)d character.uO   This password is too short. It must contain at least %(min_length)d characters.t   codeu   password_too_shortt   paramsu
   min_length(   t   lenR1   R   R   (   R2   R   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyR   g   s    c         C  s!   t  d d |  j ƒ i |  j d 6S(   Nu=   Your password must contain at least %(min_length)d character.u>   Your password must contain at least %(min_length)d characters.u
   min_length(   R   R1   (   R2   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyR)   s   s
    	N(   t   __name__t
   __module__t   __doc__R3   R   R   R)   (    (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyR0   `   s   t    UserAttributeSimilarityValidatorc           B  s8   e  Z d  Z d	 Z e d d „ Z d
 d „ Z d „  Z RS(   u²  
    Validate whether the password is sufficiently different from the user's
    attributes.

    If no specific attributes are provided, look at a sensible list of
    defaults. Attributes that don't exist are ignored. Comparison is made to
    not only the full attribute value, but also its components, so that, for
    example, a password is validated against either part of an email address,
    as well as the full address.
    u   usernameu
   first_nameu	   last_nameu   emailgffffffæ?c         C  s   | |  _  | |  _ d  S(   N(   t   user_attributest   max_similarity(   R2   R;   R<   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyR3   ˆ   s    	c      
   C  s  | s
 d  Sxû |  j  D]ð } t | | d  ƒ } | s t | t ƒ rI q n  t j d | ƒ | g } xŸ | D]— } t d | j ƒ  d | j ƒ  ƒ j	 ƒ  |  j
 k ri y t | j j | ƒ j ƒ } Wn t k
 r× | } n Xt t d ƒ d d d i | d 6ƒ‚ qi qi Wq Wd  S(	   Nu   \W+R$   t   bu4   The password is too similar to the %(verbose_name)s.R4   u   password_too_similarR5   u   verbose_name(   R;   R'   R   t
   isinstanceR   t   ret   splitR   t   lowert   quick_ratioR<   R   t   _metat	   get_fieldt   verbose_nameR   R   t   _(   R2   R   R   t   attribute_namet   valuet   value_partst
   value_partRE   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyR   Œ   s"    0
c         C  s
   t  d ƒ S(   NuF   Your password can't be too similar to your other personal information.(   RF   (   R2   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyR)   ¡   s    (   u   usernameu
   first_nameu	   last_nameu   emailN(   R7   R8   R9   t   DEFAULT_USER_ATTRIBUTESR3   R   R   R)   (    (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyR:   {   s
   
t   CommonPasswordValidatorc           B  sb   e  Z d  Z e j j e j j e j j e e	 ƒ ƒ ƒ d ƒ Z
 e
 d „ Z d d „ Z d „  Z RS(   u#  
    Validate whether the password is a common password.

    The password is rejected if it occurs in a provided list, which may be gzipped.
    The list Django ships with contains 1000 common passwords, created by Mark Burnett:
    https://xato.net/passwords/more-top-worst-passwords/
    u   common-passwords.txt.gzc         C  sƒ   y7 t  j | ƒ " } | j ƒ  j d ƒ j ƒ  } Wd  QXWn2 t k
 rk t | ƒ  } | j ƒ  } Wd  QXn Xd „  | Dƒ |  _ d  S(   Nu   utf-8c         S  s   h  |  ] } | j  ƒ  ’ q S(    (   t   strip(   t   .0t   p(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pys	   <setcomp>¹   s   	 (   t   gzipt   opent   readt   decodet
   splitlinest   IOErrort	   readlinest	   passwords(   R2   t   password_list_patht   ft   common_passwords_lines(    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyR3   ±   s    %c         C  s:   | j  ƒ  j ƒ  |  j k r6 t t d ƒ d d ƒ‚ n  d  S(   Nu   This password is too common.R4   u   password_too_common(   RA   RM   RW   R   RF   (   R2   R   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyR   »   s    c         C  s
   t  d ƒ S(   Nu0   Your password can't be a commonly used password.(   RF   (   R2   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyR)   Â   s    N(   R7   R8   R9   t   ost   pathR,   t   dirnamet   realpathR   t   __file__t   DEFAULT_PASSWORD_LIST_PATHR3   R   R   R)   (    (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyRL   ¥   s   	*
t   NumericPasswordValidatorc           B  s#   e  Z d  Z d d „ Z d „  Z RS(   u8   
    Validate whether the password is alphanumeric.
    c         C  s+   | j  ƒ  r' t t d ƒ d d ƒ‚ n  d  S(   Nu"   This password is entirely numeric.R4   u   password_entirely_numeric(   t   isdigitR   RF   (   R2   R   R   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyR   Ê   s    c         C  s
   t  d ƒ S(   Nu(   Your password can't be entirely numeric.(   RF   (   R2   (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyR)   Ñ   s    N(   R7   R8   R9   R   R   R)   (    (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyRa   Æ   s   (-   t
   __future__R    RP   R[   R?   t   difflibR   t   django.confR   t   django.core.exceptionsR   R   R   t   django.utilsR   t   django.utils._osR   t   django.utils.encodingR   t   django.utils.functionalR	   t   django.utils.htmlR
   t   django.utils.module_loadingR   t   django.utils.sixR   R   t   django.utils.translationR   RF   R   R   R   R   R#   R(   R+   R/   t"   password_validators_help_text_htmlt   objectR0   R:   RL   Ra   (    (    (    sI   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/password_validation.pyt   <module>   s2   	
*!