U
    [+d                      @   s`   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	d
ZdddZdS )    )chain)
MethodType)apps)settings)checks   )_get_builtin_permissionsNc                    s  | d krt tj n6tjd\}}| D ]}|j|kr*||  qLq*g S g }t jtt	fsv|
tjd dd  j jkr|
tjdd j jf  dd  j jjs.t fd	d
 jjD s.tjdgkr|
tjd jj jf  dd n&|
tjd jj jf d dd t  jtrX|
tjd   dd t  jtr|
tjd   dd |S )N.z*'REQUIRED_FIELDS' must be a list or tuple.z	auth.E001objidzjThe field named as the 'USERNAME_FIELD' for a custom user model must not be included in 'REQUIRED_FIELDS'.zaThe 'USERNAME_FIELD' is currently set to '%s', you should remove '%s' from the 'REQUIRED_FIELDS'.z	auth.E002)hintr   r   c                 3   s   | ]}|j  jfkV  qd S N)fieldsUSERNAME_FIELD).0
constraintcls >/tmp/pip-unpacked-wheel-n7e__lmp/django/contrib/auth/checks.py	<genexpr>7   s   z#check_user_model.<locals>.<genexpr>z)django.contrib.auth.backends.ModelBackendzC'%s.%s' must be unique because it is named as the 'USERNAME_FIELD'.z	auth.E003z?'%s.%s' is named as the 'USERNAME_FIELD', but it is not unique.zKEnsure that your authentication backend(s) can handle non-unique usernames.z	auth.W004z%s.is_anonymous must be an attribute or property rather than a method. Ignoring this is a security issue as anonymous users will be treated as authenticated!z	auth.C009z%s.is_authenticated must be an attribute or property rather than a method. Ignoring this is a security issue as anonymous users will be treated as authenticated!z	auth.C010)r   	get_modelr   ZAUTH_USER_MODELsplitlabel
isinstanceZREQUIRED_FIELDSlisttupleappendr   Errorr   _meta	get_fielduniqueanyZtotal_unique_constraintsZAUTHENTICATION_BACKENDSZobject_nameWarningZis_anonymousr   ZCriticalis_authenticated)app_configskwargsZ	app_label
model_name
app_configerrorsr   r   r   check_user_model   s    

	

			r+   c              	   K   s  | d krt  }ntdd | D }t dd}|jdj}|jdj}g }|D ]}|j}tt	|}	|	rt
dd |	 D nd}
|
|kr||
t|j  }|tjd	|j||f |d
d |	rt
dd |	 D nd}||kr$||t|j  }|tjd|j||f |dd t }|jD ]\}}t||krh|tjd||j|f |dd t||kr|tjd||j|f |dd ||	kr|tjd||jf |dd n*||kr|tjd||jf |dd || q0qV|S )Nc                 s   s   | ]}|  V  qd S r   )
get_models)r   r)   r   r   r   r   o   s    z+check_models_permissions.<locals>.<genexpr>auth
Permissionnamecodenamec                 s   s   | ]}t |V  qd S r   len)r   r/   r   r   r   r   }   s     r   zzThe verbose_name of model '%s' must be at most %d characters for its builtin permission names to be at most %d characters.z	auth.E007r
   c                 s   s   | ]}t |V  qd S r   r1   )r   r0   r   r   r   r      s     zvThe name of model '%s' must be at most %d characters for its builtin permission codenames to be at most %d characters.z	auth.E011zEThe permission named '%s' of model '%s' is longer than %d characters.z	auth.E008zIThe permission codenamed '%s' of model '%s' is longer than %d characters.z	auth.E012zOThe permission codenamed '%s' clashes with a builtin permission for model '%s'.z	auth.E005z;The permission codenamed '%s' is duplicated for model '%s'.z	auth.E006)r   r,   r   from_iterabler   r    r!   
max_lengthdictr   maxvaluesr2   Zverbose_name_rawr   r   r   r   keysr(   setpermissionsadd)r&   r'   modelsr.   Zpermission_name_max_lengthZpermission_codename_max_lengthr*   modeloptsZbuiltin_permissionsZ"max_builtin_permission_name_lengthZverbose_name_max_lengthZ&max_builtin_permission_codename_lengthZmodel_name_max_lengthZ	codenamesr0   r/   r   r   r   check_models_permissionsk   s    






r?   )N)N)	itertoolsr   typesr   Zdjango.appsr   Zdjango.confr   Zdjango.corer   Z
managementr   r+   r?   r   r   r   r   <module>   s   
`