
    k"g7<                         d dl Z d dlZd dlZd dl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Zd dlmZ d dlmZmZ d dlmZmZmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZ  G d de      Zy)    N)	find_spec)build_opener)settings)BaseCommandCommandError)find_formattershandle_extensionsrun_formatters)ContextEngine)archive)parse_header_parameters)get_docs_versionc                   `    e Zd ZdZg Zg dZdZd ZddZd Z	ddZ
d	 Zd
 Zd Zd Zd Zd Zy)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.pyc           	      "   |j                  dd       |j                  ddd       |j                  dd	       |j                  d
ddddgd       |j                  ddddg d       |j                  dddt        j                  ddd       y )Nnamez#Name of the application or project.)help	directory?zOptional destination directory)nargsr   z
--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defaultr   z--namez-nfilesz_The file name(s) to render. Separate multiple file names with commas, or use -n multiple times.z	--excludez-x zbThe directory name(s) to exclude, in addition to .git and __pycache__. Can be used multiple times.)r   r    r   constr   )add_argumentargparseSUPPRESS)selfparsers     Y/var/www/html/djangosite/lib/python3.12/site-packages/django/core/management/templates.pyadd_argumentszTemplateCommand.add_arguments.   s    F)NOs)I 	 	
 	K 	 	
 	F! 	 		
 	5 	 	
 	%%; 	 	
    Nc                 \   || _         |dk(  rdnd| _        g | _        |d   | _        | j	                  |       |It
        j                  j                  t        j                         |      }	 t        j                  |       nt
        j                  j                  t
        j                  j                  |            }|dk(  r/| j	                  t
        j                  j                  |      d       t
        j                  j!                  |      st        d|z        t#               }t%        t'        |d               }g }	d	d
g}
|d   D ]-  }|	j)                  t+        d |j-                  d                   / |j/                  d      x}r&|D ]!  }|
j1                  |j3                                # | j                  dk\  r`| j4                  j7                  d|ddj                  |             | j4                  j7                  d|ddj                  |	             d|z  }d|z  }d|z  }d|z  }dj                  d |j9                         D              }t;        i |||||||dt=               dt>        j@                  id      }tB        jD                  s(tC        jF                          t?        jH                          | jK                  |d   |      }tM        |      dz   }t        jN                  |      D ]}  \  }}}||d  }|jQ                  ||      }|r7t
        j                  j                  ||      }t        j                  |d !       |d d  D ]E  }d|vr)|jS                  d"      s|d
k(  s|jU                  |       0||
v s5|jU                  |       G |D ]  }|jW                  d#      rt
        j                  j                  ||      }t
        j                  j                  |||jQ                  ||            }| jX                  D ],  \  } }!|jW                  |       s|j[                  |       |!z   } n t
        j                  j!                  |      rt        |d$| j                  d%|d&      |jW                  |      s||	v ryt]        |d'(      5 }"|"j_                         }#d d d        ta               jc                  #      }$|$je                  |      }#t]        |d)d'(      5 }%|%j7                  |#       d d d        ntg        jh                  ||       | j                  dk\  r| j4                  j7                  d*|z         	 | jk                  ||       | jm                  |         | j                  r| j                  dk\  r| j4                  j7                  d,       | j                  D ]L  }&t
        j                  ju                  |&      rt        jT                  |&       8tg        jv                  |&       N ty        |gfi | y # t        $ r t        d|z        t        $ r}t        |      d }~ww xY w# 1 sw Y   xY w# 1 sw Y   ?xY w# t        $ r7 | jn                  j7                  d+|z  | jp                  jr                         Y w xY w)-Nappana	verbosityz'%s' already existsr   zBDestination directory '%s' does not exist, please create it first.r   z.git__pycache__r!   c                 "    | j                         S N)strip)xs    r)   <lambda>z(TemplateCommand.handle.<locals>.<lambda>y   s    QWWY r+   ,exclude   z
Rendering z! template files with extensions: z, z  template files with filenames: z%s_namez%s_templatez%s_directoryzcamel_case_%s_namer"   c              3   ,   K   | ]  }|d k7  s	|  yw)_N ).0r5   s     r)   	<genexpr>z)TemplateCommand.handle.<locals>.<genexpr>   s     "Ga3h1"Gs   
docs_versiondjango_versionF)
autoescapetemplate   T)exist_ok.)z.pyoz.pycz	.py.classz already exists. Overlaying  z< into an existing directory won't replace conflicting files.zutf-8)encodingwzCreating %szkNotice: Couldn't set permission bits on %s. You're probably using an uncommon filesystem setup. No problem.zCleaning up temporary files.)=app_or_projecta_or_anpaths_to_remover0   validate_nameospathjoingetcwdmakedirsFileExistsErrorr   OSErrorabspath
expanduserbasenameexistsr   tupler	   extendmapsplitgetr   r4   stdoutwritetitler   r   django__version__r   
configured	configuresetuphandle_templatelenwalkreplace
startswithremoveendswithrewrite_template_suffixesremovesuffixopenreadr   from_stringrendershutilcopyfileapply_umaskmake_writeablestderrstyleNOTICEisfilermtreer
   )'r'   rI   r   targetoptionstop_direformatter_pathsr   extra_filesexcluded_directoriesfiler8   r   	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contentrB   new_filepath_to_removes'                                          r)   handlezTemplateCommand.handleV   s
   ,-6tC! -4  >ggll299;5G&G$ ggoobgg&8&8&@AG&""277#3#3G#<kJ77>>'*"57>?  *+,W\-BCD
 &6G$ 	JDs#6

3HI	Jkk),,7,$ ?	$++IOO,=>?>>QKK!499Z#8: KK!499[#9; .	#n4'.8.?77"Gdjjl"GG4!1 0 2 &"4"4 

 "" LLN++GJ,?ML)A-!#!6 =	D$]^,I$,,Y=LWW\\'<@
J67 )G+))#.']2JG, 44KK() " /$$%BC77<<h777<<\8+;+;It+L /3.L.L *J
((4#+#8#8#Dz#Q
 77>>(+& % LL*  $$Z0H4Kh9 7]"/"4"4"67%x33G<H&oog6Ghg> 0( w/0 0 OOHh7>>Q&KK%%mh&>?	$$Xx8''1Q/=	~ ~~"!!"@A"&"6"6 277>>.1IIn-MM.1	2 	y4O4K # D"#87#BCC &"1o%&H7 70 0  KK%%#%-. 

))	sB   -X 'Y8Y#Y+Y>Y		YYY(+<Z+*Z+c                 f   |2t         j                  j                  t        j                  d   d|      S |j                  d      }t         j                  j                  |      }t         j                  j                  |      }t         j                  j                  |      r|S | j                  |      r| j                  |      }nt         j                  j                  |      }t         j                  j                  |      r| j                  |      S t        d| j                  d|d      )z
        Determine where the app or project templates are.
        Use django.__path__[0] as the default because the Django install
        directory isn't known.
        r   confzfile://zcouldn't handle z
 template rE   )rM   rN   rO   r`   __path__removeprefixrU   normpathisdiris_urldownloadrT   rW   extractr   rI   )r'   rB   subdirexpanded_templateabsolute_paths        r)   re   zTemplateCommand.handle_template   s     77<< 2FFCC,,Y7H " 2 28 < " 0 01B Cww}}./(({{8$ $h 7 "0A Bww~~m,||M22151D1DhO
 	
r+   c                 P   |0t        dj                  | j                  | j                              |j	                         s't        dj                  || j                  |            t        |      2t        dj                  || j                  | j                  |            y )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.)r   r-   typez'{name}' conflicts with the name of an existing Python module and cannot be used as {an} {app} {type}. Please try another {type}.)r   r.   r-   r   )r   formatrJ   rI   isidentifierr   )r'   r   name_or_dirs      r)   rL   zTemplateCommand.validate_name  s    <299||++ :     "006++$ 17 1  T?&""(&||++$	 #) #	 	 'r+   c           	      .   d }d| j                   z  }t        j                  |d      }| j                  j	                  |        ||      \  }}| j
                  dk\  r| j                  j                  d|z         t        j                  j                  ||      }t               }ddt        j                   fg|_        	 |j                  |      5 }	t        |d	      5 }
|	j!                         }|
j                  |	j#                                d
d
d
       d
d
d
       |j)                  d      d   }d   }|r$t+        |      \  }}|j-                  d      xs |}n|}| j/                  |      d   }|d   }|s|rt1        j2                  |      }|r||z  }||k7  r8t        j                  j                  ||      }t5        j6                  ||       |S |S # 1 sw Y   xY w# 1 sw Y   xY w# t$        $ r}t'        d|d|d|      d
}~ww xY w)zB
        Download the given URL and return the file name.
        c                     | j                  d      }|j                  d      d   }| j                  d      r	|dz   }||fS | }||fS )N/)rstripr[   rk   )urltmpr   display_urls       r)   cleanup_urlz-TemplateCommand.download.<locals>.cleanup_url(  sU    **S/Cyy~b)H||C !Ci [(( "[((r+   django_%s_template_	_downloadprefixsuffixr9   zDownloading %sz
User-AgentzDjango/wbNzcouldn't download URL  to : r   r   zcontent-dispositionr   rC   zcontent-type)rI   tempfilemkdtemprK   r   r0   r]   r^   rM   rN   rO   r   r`   ra   
addheadersrn   inforo   rS   r   r[   r   r\   splitext	mimetypesguess_extensionrr   move)r'   r   r   r   tempdirr   r   the_pathopenersourcer{   headersr~   	used_namecontent_dispositionr;   paramsguessed_filenameextcontent_typeguessed_paths                        r)   r   zTemplateCommand.download#  s   
	) ')<)<<""&E##G, +C 0+>>QKK.<=77<<2*gf6H6H5I,JKL	S! ,VT(D-A ,V ++-V[[]+, , NN3'+	 &&;</0CDIAv%zz*5B( mm,-a0~.|++L9C C'  ((77<<1ABLKK,/ E, , , ,  	8;XqI 	sH   G2 G&!0GG&G2 G#	G&&G/+G2 2	H;HHc                     t        j                  |      \  }}|j                         j                  d      r|dd |z   }|dd }||fS )z@
        Like os.path.splitext, but takes off .tar, too
        z.tarN)	posixpathr   lowerrk   )r'   r   baser   s       r)   r   zTemplateCommand.splitexta  sP     &&x0	c::<  (rs)c/C9DSyr+   c           	      z   d| j                   z  }t        j                  |d      }| j                  j	                  |       | j
                  dk\  r| j                  j                  d|z         	 t        j                  ||       |S # t        j                  t        f$ r}t        d|d|d|      d	}~ww xY w)
z
        Extract the given file to a temporary directory and return
        the path of the directory with the extracted content.
        r   _extractr   r9   zExtracting %szcouldn't extract file r   r   N)rI   r   r   rK   r   r0   r]   r^   r   r   ArchiveExceptionrS   r   )r'   r   r   r   r~   s        r)   r   zTemplateCommand.extractk  s    
 ')<)<<""&D##G,>>QKKo89	OOHg.N(('2 	8@'1M 	s   0B B:!B55B:c                 n    d|vry|j                  dd      d   j                         }|| j                  v S )z)Return True if the name looks like a URL.:FrC   r   )r[   r   url_schemes)r'   rB   schemes      r)   r   zTemplateCommand.is_url}  s<    hQ'*002))))r+   c                     t        j                  d      }t        j                  |       t        j                  t        j                  |      j                        }t        j
                  ||| z         y )Nr   )rM   umaskstatS_IMODEst_modechmod)r'   r   r   current_umaskcurrent_modes        r)   rt   zTemplateCommand.apply_umask  sM    
||BGGH$5$=$=>
<=.89r+   c                    t        j                  |t         j                        s\t        j                  |      }t        j                  |j
                        t        j                  z  }t        j                  ||       yy)zb
        Make sure that the file is writeable.
        Useful if our source is read-only.
        N)rM   accessW_OKr   r   r   S_IWUSRr   )r'   r   stnew_permissionss       r)   ru   zTemplateCommand.make_writeable  sR    
 yy277+"B"ll2::6EOHHX/ ,r+   r3   )r   )__name__
__module____qualname____doc__requires_system_checksr   rl   r*   r   re   rL   r   r   r   r   rt   ru   r<   r+   r)   r   r      sR    	  *K!
&
PR5h
4><|$*:0r+   r   )r%   r   rM   r   rr   r   r   importlib.utilr   urllib.requestr   r`   django.confr   django.core.management.baser   r   django.core.management.utilsr   r	   r
   django.templater   r   django.utilsr   django.utils.httpr   django.utils.versionr   r   r<   r+   r)   <module>r      sO      	     $ '    A 
 ,   5 1y0k y0r+   