HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/django/core/management/__pycache__/templates.cpython-310.pyc
o

3�aU5�@s�ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlZddlm
Z
ddlmZmZddlmZddlmZmZddlmZdd	lmZGd
d�de�ZdS)�N)�
import_module)�urlretrieve)�settings)�BaseCommand�CommandError)�handle_extensions)�Context�Engine)�archive)�get_docs_versionc@sleZdZdZgZgd�ZdZdd�Zddd�Zd	d
�Z	ddd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�TemplateCommanda�
    Copy either a Django application layout template or a Django project
    layout template into the specified directory.

    :param style: A color style object (see django.core.management.color).
    :param app_or_project: The string 'app' or 'project'.
    :param name: The name of the application or project.
    :param directory: The directory to which the template should be copied.
    :param options: The additional variables passed to project or app templates
    )�http�https�ftp))z.py-tplz.pycCs^|jddd�|jdddd�|jdd	d�|jd
ddd
dgdd�|jdddd
gdd�dS)N�namez#Name of the application or project.)�help�	directory�?zOptional destination directory)�nargsrz
--templatez*The path or URL to load the template from.z--extensionz-e�
extensions�append�pyztThe file extension(s) to render (default: "py"). Separate multiple extensions with commas, or use -e multiple times.)�dest�action�defaultrz--namez-n�filesz_The file name(s) to render. Separate multiple file names with commas, or use -n multiple times.)�add_argument)�self�parser�r�B/usr/lib/python3/dist-packages/django/core/management/templates.py�
add_arguments(s�
�zTemplateCommand.add_argumentsNc#Ksv||_|dkr	dnd|_g|_|d|_|�|�|durJtj�t��|�}zt�	|�Wn@t
y:td|��tyI}zt|��d}~ww|dkrX|�tj�
|�d�tj�tj�|��}tj�|�sntd|��tt|d��}g}|d	D]}	|�td
d�|	�d���q||jd
kr�|j�d|d�|�f�|j�d|d�|�f�d|}
d|}d|}d|}
d�dd�|��D��}ti|�|
||||
|dt�dtji�dd�}tjs�t��t� �|�!|d|�}t"|�d}t�#|�D�]\}}}||d�}|�$|
|�}|�rtj�||�}tj	|dd�|dd�D]}|�%d ��s1|d!k�r6|�&|��q$|D]�}|�'d"��rD�q:tj�||�}tj�|||�$|
|��}|j(D]\}}|�'|��rq|dt"|��|}n�qZtj�|��r�td#||j|f��|�'|��s�||v�r�t)|d$d%��}|�*�}Wd�n	1�s�wYt+��,|�} | �-|�}t)|d&d$d%��
}!|!�|�Wd�n	1�s�wYnt.�/||�|jd
k�r�|j�d'|�zt.�0||�|�1|�W�q:t�y|j2�d(||j3j4�Y�q:wq�|j�r7|jd
k�r|j�d)�|jD]}"tj�5|"��r0t�&|"��q t.�6|"��q dSdS)*N�app�an�a�	verbosityz'%s' already existsrzBDestination directory '%s' does not exist, please create it first.rrcSs|��S�N)�strip)�xrrr �<lambda>Vsz(TemplateCommand.handle.<locals>.<lambda>�,�z/Rendering %s template files with extensions: %sz, z.Rendering %s template files with filenames: %sz%s_namez%s_templatez%s_directoryzcamel_case_%s_name�css�|]	}|dkr|VqdS)�_Nr)�.0r(rrr �	<genexpr>ds�z)TemplateCommand.handle.<locals>.<genexpr>�docs_version�django_versionF)�
autoescape�template�T)�exist_ok�.�__pycache__)z.pyoz.pycz	.py.classz_%s already exists. Overlaying %s %s into an existing directory won't replace conflicting files.zutf-8)�encoding�wzCreating %szkNotice: Couldn't set permission bits on %s. You're probably using an uncommon filesystem setup. No problem.zCleaning up temporary files.)7�app_or_project�a_or_an�paths_to_remover%�
validate_name�os�path�join�getcwd�makedirs�FileExistsErrorr�OSError�basename�abspath�
expanduser�exists�tupler�extend�map�split�stdout�write�titlerr�django�__version__r�
configured�	configure�setup�handle_template�len�walk�replace�
startswith�remove�endswith�rewrite_template_suffixes�open�readr	�from_string�render�shutil�copyfile�copymode�make_writeable�stderr�style�NOTICE�isfile�rmtree)#rr:r�target�options�top_dir�er�extra_files�file�	base_name�base_subdir�base_directory�camel_case_name�camel_case_value�context�template_dir�
prefix_length�root�dirsr�	path_rest�relative_dir�
target_dir�dirname�filename�old_path�new_path�
old_suffix�
new_suffix�
template_file�contentr3�new_file�path_to_removerrr �handle:s�

���
�������

�
������	
�
���
���,
�zTemplateCommand.handlecCs�|durtj�tjdd|�S|�d�r|dd�}tj�|�}tj�|�}tj�|�r.|S|�	|�r9|�
|�}ntj�|�}tj�|�rJ|�
|�Std|j|f��)z�
        Determine where the app or project templates are.
        Use django.__path__[0] as the default because the Django install
        directory isn't known.
        Nr�confzfile://�zcouldn't handle %s template %s.)r>r?r@rP�__path__rYrG�normpath�isdir�is_url�downloadrFrH�extractrr:)rr3�subdir�expanded_template�
absolute_pathrrr rU�s 


�zTemplateCommand.handle_templatercCsx|durtdj|j|jd���|��stdj||j|d���zt|�Wn
ty.YdSwtdj||j|j|d���)Nz you must provide {an} {app} name)r#r"zX'{name}' is not a valid {app} {type}. Please make sure the {type} is a valid identifier.)rr"�typez�'{name}' conflicts with the name of an existing Python module and cannot be used as {an} {app} {type}. Please try another {type}.)rr#r"r�)r�formatr;r:�isidentifierr�ImportError)rr�name_or_dirrrr r=�s8���	���zTemplateCommand.validate_namec
Cs8dd�}d|j}tj|dd�}|j�|�||�\}}|jdkr)|j�d|�zt|t	j
�||��\}}WntyL}	z	t
d|||	f��d	}	~	ww|�d
�d}
|�d�}|rjt�|�\}}
|
�d
�ph|
}n|
}|�|�d}|�d�}|s�|r�t�|�}|r�||7}|
|kr�t	j
�||�}t�||�|S|S)zB
        Download the given URL and return the file name.
        cSs>|�d�}|�d�d}|�d�r|d}||fS|}||fS)N�/���)�rstriprLr[)�url�tmpr~�display_urlrrr �cleanup_url�s

�z-TemplateCommand.download.<locals>.cleanup_url�django_%s_template_�	_download��prefix�suffixr+zDownloading %sz"couldn't download URL %s to %s: %sNr�r�zcontent-dispositionr~r4zcontent-type)r:�tempfile�mkdtempr<rr%rMrNrr>r?r@rDrrL�get�cgi�parse_header�splitext�	mimetypes�guess_extensionra�move)rr�r�r��tempdirr~r��the_path�inform�	used_name�content_dispositionr-�params�guessed_filename�ext�content_type�guessed_pathrrr r��s@
	
���


zTemplateCommand.downloadcCs@t�|�\}}|���d�r|dd�|}|dd�}||fS)z@
        Like os.path.splitext, but takes off .tar, too
        z.tar���N)�	posixpathr��lowerr[)rr��baser�rrr r�*s
zTemplateCommand.splitextc
Cs�d|j}tj|dd�}|j�|�|jdkr|j�d|�z	t�	||�|WStj
tfy@}z	td|||f��d}~ww)z�
        Extract the given file to a temporary directory and return
        the path of the directory with the extracted content.
        r��_extractr�r+z
Extracting %sz"couldn't extract file %s to %s: %sN)
r:r�r�r<rr%rMrNr
r��ArchiveExceptionrDr)rr~r�r�rmrrr r�4s

���zTemplateCommand.extractcCs*d|vrdS|�dd�d��}||jvS)z)Return True if the name looks like a URL.�:Fr4r)rLr��url_schemes)rr3�schemerrr r�Es
zTemplateCommand.is_urlcCs>t�|tj�st�|�}t�|j�tjB}t�||�dSdS)zb
        Make sure that the file is writeable.
        Useful if our source is read-only.
        N)r>�access�W_OK�stat�S_IMODE�st_mode�S_IWUSR�chmod)rr~�st�new_permissionsrrr rdLs

�zTemplateCommand.make_writeabler&)r)�__name__�
__module__�__qualname__�__doc__�requires_system_checksr�r\r!r�rUr=r�r�r�r�rdrrrr rs


!6
r)r�r�r>r�rar�r��	importlibr�urllib.requestrrP�django.confr�django.core.management.baserr�django.core.management.utilsr�django.templaterr	�django.utilsr
�django.utils.versionrrrrrr �<module>s"