File: //usr/lib/python3/dist-packages/django/contrib/auth/management/__pycache__/__init__.cpython-310.pyc
o
�a � @ s� d Z ddlZddlZddlmZ ddlmZ ddlm Z ddl
mZ ddlm
Z
mZ dd � Zd
d� Zdd
e
efdd�Zdd� Zd
e
fdd�ZdS )zC
Creates permissions for all installed apps that need permissions.
� N)�apps)�get_permission_codename)�create_contenttypes)�
exceptions)�DEFAULT_DB_ALIAS�routerc C s g t | ��| j�S )zH
Return (codename, name) for all permissions in the given opts.
)�_get_builtin_permissions�permissions)�opts� r �I/usr/lib/python3/dist-packages/django/contrib/auth/management/__init__.py�_get_all_permissions s r
c C s2 g }| j D ]}|�t|| �d|| jf f� q|S )z�
Return (codename, name) for all autogenerated permissions.
By default, this is ('add', 'change', 'delete', 'view')
z Can %s %s)�default_permissions�appendr �verbose_name_raw)r
�perms�actionr r r r s
�r � Tc s8 | j sd S t| f||||d�|�� | j}z|�|�} |�dd�}|�dd�� W n
ty2 Y d S w t�|� �s;d S g }t� } | � � D ]!}
|j
�|�j|
dd�}| �
|� t|
j�D ] }|�||f� q[qDt� j
�|�j| d��d d
���� �fdd�|D �}
� j
�|��|
� |d
kr�|
D ]
}td| � q�d S d S )N)� verbosity�interactive�usingr �contenttypes�ContentType�auth�
PermissionF)�for_concrete_model)�content_type__in�content_type�codenamec s0 g | ]\}\}}|j |f�vr� |||d ��qS ))r �namer )�pk)�.0�ctr r �r � all_permsr r �
<listcomp>N s
�z&create_permissions.<locals>.<listcomp>r zAdding permission '%s')�
models_moduler �label�get_app_config� get_model�LookupErrorr �allow_migrate_model�set�
get_models�objects�
db_manager�
get_for_model�addr
�_metar r �filter�values_list�bulk_create�print)�
app_configr r r r �kwargs� app_labelr �searched_perms�ctypes�klass�ctype�permr r r# r �create_permissions# sJ
�
������r? c C s( zt �� } W | S ttfy Y dS w )zt
Return the current system user's username, or an empty string if the
username could not be determined.
� )�getpass�getuser�ImportError�KeyError)�resultr r r �get_system_usernameY s
��rF c C s� ddl m} |jjjr
dS t� }zt�d|��dd�� d��
dd��� }W n
ty/ Y dS w z|jj�
d��|� W n tjyG Y dS w | rg|rgz|jj�|�j|d � W dS |jjyf Y |S w |S )
a�
Try to determine the current system user's username to use as a default.
:param check_db: If ``True``, requires that the username does not match an
existing ``auth.User`` (otherwise returns an empty string).
:param database: The database where the unique check will be performed.
:returns: The username, or an empty string if no username can be
determined or the suggested username is already taken.
r )�modelsr@ �NFKD�ascii�ignore� �username)rL )�django.contrib.authrG �Userr2 �swappedrF �unicodedata� normalize�encode�decode�replace�lower�UnicodeDecodeError� get_field�run_validatorsr �ValidationError�_default_managerr/ �get�DoesNotExist)�check_db�database�auth_app�default_usernamer r r �get_default_usernameh s8
������ra )�__doc__rA rP �django.appsr �global_appsrM r �&django.contrib.contenttypes.managementr �django.corer � django.dbr r r
r r? rF ra r r r r �<module> s 6