
    h7<                         S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKJr  S SK	J
r
  S SKrS SKJr  S SKJrJr  S SKJrJrJr  S SKJrJr  S SKJr  S S	KJr  S S
KJr   " S S\5      rg)    N)	find_spec)build_opener)settings)BaseCommandCommandError)find_formattershandle_extensionsrun_formatters)ContextEngine)archive)parse_header_parameters)get_docs_versionc                   l    \ rS rSrSr/ r/ SQrSrS rSS jr	S r
SS	 jrS
 rS rS rS rS rS rSrg)TemplateCommand   a  
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           
          UR                  SSS9  UR                  SSSS9  UR                  SS	S9  UR                  S
SSSS/SS9  UR                  SSSS/ SS9  UR                  SSS[        R                  SSSS9  g )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     R/var/www/html/env/lib/python3.13/site-packages/django/core/management/templates.pyadd_argumentsTemplateCommand.add_arguments.   s    F)NOs)I 	 	
 	K 	 	
 	F! 	 		
 	5 	 	
 	%%; 	 	
    Nc                 &   Xl         US:X  a  SOSU l        / U l        US   U l        U R	                  U5        UcK  [
        R                  R                  [
        R                  " 5       U5      n [
        R                  " U5        O[
        R                  R                  [
        R                  R                  U5      5      nUS:X  a/  U R	                  [
        R                  R                  U5      S5        [
        R                  R!                  U5      (       d  [        SU-  5      e[#        5       n[%        ['        US   5      5      n/ n	S	S
/n
US    H.  nU	R)                  [+        S UR-                  S5      5      5        M0     UR/                  S5      =n(       a(  U H"  nU
R1                  UR3                  5       5        M$     U R                  S:  ad  U R4                  R7                  SU< SSR                  U5      < 35        U R4                  R7                  SU< SSR                  U	5      < 35        SU-  nSU-  nSU-  nSU-  nSR                  S UR9                  5        5       5      n[;        0 UEXUUUUS[=        5       S[>        R@                  0ESS9n[B        RD                  (       d*  [B        RF                  " 5         [>        RH                  " 5         U RK                  US   U5      n[M        U5      S-   n[
        RN                  " U5       GH  u  nnnUUS  nURQ                  X5      nU(       a5  [
        R                  R                  UU5      n[
        R                  " US S!9  US S   HS  nSU;  a1  URS                  S"5      (       d  US
:X  a  URU                  U5        M8  M:  UU
;   d  MB  URU                  U5        MU     U GH  nURW                  S#5      (       a  M  [
        R                  R                  UU5      n[
        R                  R                  UUURQ                  X5      5      nU RX                   H2  u  n n!URW                  U 5      (       d  M  UR[                  U 5      U!-   n  O   [
        R                  R!                  U5      (       a!  [        U< S$U R                  < S%U< S&35      eURW                  U5      (       d  UU	;   as  []        US'S(9 n"U"R_                  5       n#S S S 5        [a        5       Rc                  W#5      n$U$Re                  U5      n#[]        US)S'S(9 n%U%R7                  U#5        S S S 5        O[f        Rh                  " UU5        U R                  S:  a  U R4                  R7                  S*U-  5         U Rk                  UU5        U Rm                  U5        GM     GM     U R                  (       a  U R                  S:  a  U R4                  R7                  S,5        U R                   HU  n&[
        R                  Ru                  U&5      (       a  [
        RT                  " U&5        M?  [f        Rv                  " U&5        MW     [y        U/40 UD6  g ! [         a    [        SU-  5      e[         a  n[        U5      eS nAff = f! , (       d  f       GN= f! , (       d  f       GN`= f! [         a8    U Rn                  R7                  S+U-  U Rp                  Rr                  5         GM=  f = f)-Nappana	verbosityz'%s' already existsr   zBDestination directory '%s' does not exist, please create it first.r   z.git__pycache__r"   c                 "    U R                  5       $ N)strip)xs    r*   <lambda>(TemplateCommand.handle.<locals>.<lambda>y   s
    QWWYr-   ,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   4   #    U  H  oS :w  d  M
  Uv   M     g7f)_N ).0r7   s     r*   	<genexpr>)TemplateCommand.handle.<locals>.<genexpr>   s     "Gl3h11ls   		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_remover2   validate_nameospathjoingetcwdmakedirsFileExistsErrorr   OSErrorabspath
expanduserbasenameexistsr   tupler	   extendmapsplitgetr   r6   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(   rM   r   targetoptionstop_direformatter_pathsr   extra_filesexcluded_directoriesfiler;   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contentrF   new_filepath_to_removes'                                          r*   handle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$Ds#6

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

))	 sB   /Y6 +Z*9Z<#[6!Z'Z""Z'*
Z9<
[=\\c                    Uc2  [         R                  R                  [        R                  S   SU5      $ UR                  S5      n[         R                  R                  U5      n[         R                  R                  U5      n[         R                  R                  U5      (       a  U$ U R                  U5      (       a  U R                  U5      nO[         R                  R                  U5      n[         R                  R                  U5      (       a  U R                  U5      $ [        SU R                  < SU< S35      e)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 rI   )rQ   rR   rS   rd   __path__removeprefixrY   normpathisdiris_urldownloadrX   r[   extractr   rM   )r(   rF   subdirexpanded_templateabsolute_paths        r*   ri   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           	      L   Uc-  [        SR                  U R                  U R                  S95      eUR	                  5       (       d$  [        SR                  UU R                  US95      e[        U5      b/  [        SR                  UU R                  U R                  US95      eg )Nz you must provide {an} {app} name)r0   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   r0   r/   r   )r   formatrN   rM   isidentifierr   )r(   r   name_or_dirs      r*   rP   TemplateCommand.validate_name  s    <299||++ :     ""006++$ 17 1  T?&""(&||++$	 #) #	 	 'r-   c           	      |   S nSU R                   -  n[        R                  " USS9nU R                  R	                  U5        U" U5      u  pVU R
                  S:  a  U R                  R                  SU-  5        [        R                  R                  XE5      n[        5       nSS[        R                   34/Ul         UR                  U5       n	[        US	5       n
U	R!                  5       nU
R                  U	R#                  5       5        S
S
S
5        S
S
S
5        UR)                  S5      S   nWS   nU(       a)  [+        U5      u  nnUR-                  S5      =(       d    UnOUnU R/                  U5      S   nUS   nU(       d)  U(       a"  [0        R2                  " U5      nU(       a  UU-  nUU:w  a9  [        R                  R                  UU5      n[4        R6                  " UU5        U$ U$ ! , (       d  f       N= f! , (       d  f       N= f! [$         a  n['        SU< SU< SU< 35      eS
nAff = f)z2
Download the given URL and return the file name.
c                     U R                  S5      nUR                  S5      S   nU R                  S5      (       a  US-   nX#4$ U nX#4$ )N/)rstripr_   ro   )urltmpr   display_urls       r*   cleanup_url-TemplateCommand.download.<locals>.cleanup_url(  sT    **S/Cyy~b)H||C  !Ci (( "((r-   django_%s_template_	_downloadprefixsuffixr<   zDownloading %sz
User-AgentzDjango/wbNzcouldn't download URL  to : r   r   zcontent-dispositionr   rG   zcontent-type)rM   tempfilemkdtemprO   r   r2   ra   rb   rQ   rR   rS   r   rd   re   
addheadersrr   infors   rW   r   r_   r   r`   splitext	mimetypesguess_extensionrv   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   TemplateCommand.download#  s   
	) ')<)<<""&E##G, +C 0>>QKK.<=77<<2*gf6H6H5I,JKL	S!VT(D-AV ++-V[[]+ .B! NN3'+	 &&;</0CDIAv%zz*5B( mm,-a0~.|++L9C C'  ((77<<1ABLKK,/ E .B-A!!  	8;XqI 	sN    H H0G3HH 3
H	=H
HH H 
H;H66H;c                     [         R                  " U5      u  p#UR                  5       R                  S5      (       a  USS U-   nUSS nX#4$ )z0
Like os.path.splitext, but takes off .tar, too
z.tarN)	posixpathr   lowerro   )r(   r   baser   s       r*   r   TemplateCommand.splitexta  sO     &&x0	::<  ((rs)c/C9Dyr-   c           	         SU R                   -  n[        R                  " USS9nU R                  R	                  U5        U R
                  S:  a  U R                  R                  SU-  5         [        R                  " X5        U$ ! [        R                  [        4 a  n[        SU< SU< SU< 35      eS	nAff = f)
zr
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 r   r   N)rM   r   r   rO   r   r2   ra   rb   r   r   ArchiveExceptionrW   r   )r(   r   r   r   r   s        r*   r   TemplateCommand.extractk  s    
 ')<)<<""&D##G,>>QKKo89	OOH.N(('2 	8@'1M 	s   /B B=!B88B=c                 r    SU;  a  gUR                  SS5      S   R                  5       nX R                  ;   $ )z)Return True if the name looks like a URL.:FrG   r   )r_   r   url_schemes)r(   rF   schemes      r*   r   TemplateCommand.is_url}  s:    hQ'*002))))r-   c                     [         R                  " S5      n[         R                  " U5        [        R                  " [         R                  " U5      R                  5      n[         R
                  " X$U) -  5        g )Nr   )rQ   umaskstatS_IMODEst_modechmod)r(   r   r   current_umaskcurrent_modes        r*   rx   TemplateCommand.apply_umask  sK    
||BGGH$5$=$=>
=.89r-   c                    [         R                  " U[         R                  5      (       d^  [         R                  " U5      n[        R                  " UR
                  5      [        R                  -  n[         R                  " X5        gg)zJ
Make sure that the file is writeable.
Useful if our source is read-only.
N)rQ   accessW_OKr   r   r   S_IWUSRr   )r(   r   stnew_permissionss       r*   ry   TemplateCommand.make_writeable  sS    
 yy277++"B"ll2::6EOHHX/ ,r-   )rN   rM   rO   r2   r5   )r   )__name__
__module____qualname____firstlineno____doc__requires_system_checksr   rp   r+   r   ri   rP   r   r   r   r   rx   ry   __static_attributes__r?   r-   r*   r   r      sR    	  *K!
&
PR5h
4><|$*:0r-   r   )r&   r   rQ   r   rv   r   r   importlib.utilr   urllib.requestr   rd   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-   