
    Evg7<                         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dS )    N)	find_spec)build_opener)settings)BaseCommandCommandError)find_formattershandle_extensionsrun_formatters)ContextEngine)archive)parse_header_parameters)get_docs_versionc                   b    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dS )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           	      L   |                     dd           |                     ddd           |                     dd	           |                     d
ddddgd           |                     ddddg d           |                     dddt          j        ddd           d S )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     ]/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/core/management/templates.pyadd_argumentszTemplateCommand.add_arguments.   s   F)NOOOs)I 	 	
 	
 	
 	K 	 	
 	
 	
 	F! 	 		
 		
 		
 	5 	 	
 	
 	
 	%; 	 	
 	
 	
 	
 	
    Nc                 N   || _         |dk    rdnd| _        g | _        |d         | _        |                     |           |t
          j                            t          j                    |          }	 t          j	        |           n# t          $ r t          d|z            t          $ r}t          |          d }~ww xY wt
          j                            t
          j                            |                    }|dk    r3|                     t
          j                            |          d           t
          j                            |          st          d|z            t#                      }t%          t'          |d                             }g }	d	d
g}
|d         D ]9}|	                    t+          d |                    d                               :|                    d          x}r,|D ])}|
                    |                                           *| j        dk    rf| j                            d|dd                    |                     | j                            d|dd                    |	                     d|z  }d|z  }d|z  }d|z  }d                    d |                                D                       }t;          i |||||||dt=                      dt>          j         id          }tB          j"        s&tC          j#                     t?          j$                     | %                    |d         |          }tM          |          dz   }t          j'        |          D ]\  }}}||d          }|(                    ||          }|r6t
          j                            ||          }t          j	        |d !           |d d          D ]P}d|vr1|)                    d"          s|d
k    r|*                    |           7||
v r|*                    |           Q|D ]T}|+                    d#          rt
          j                            ||          }t
          j                            |||(                    ||                    }| j,        D ]4\  } }!|+                    |           r|-                    |           |!z   } n5t
          j                            |          rt          |d$| j        d%|d&          |+                    |          s||	v rt]          |d'(          5 }"|"/                                }#d d d            n# 1 swxY w Y   ta                      1                    |#          }$|$2                    |          }#t]          |d)d'(          5 }%|%                    |#           d d d            n# 1 swxY w Y   ntg          j4        ||           | j        dk    r| j                            d*|z             	 | 5                    ||           | 6                    |           # t          $ r, | j7                            d+|z  | j8        j9                   Y Rw xY w| j        rw| j        dk    r| j                            d,           | j        D ]J}&t
          j        :                    |&          rt          j*        |&           6tg          j;        |&           Kty          |gfi | d S )-Nappana	verbosityz'%s' already existsr   zBDestination directory '%s' does not exist, please create it first.r   z.git__pycache__r!   c                 *    |                                  S N)strip)xs    r)   <lambda>z(TemplateCommand.handle.<locals>.<lambda>y   s    QWWYY 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 k    |V  dS )_N ).0r5   s     r)   	<genexpr>z)TemplateCommand.handle.<locals>.<genexpr>   s&      "G"Ga3hh1hhhh"G"Gr+   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   s1   ,-66ttC! -4    >gll29;;55G&G$$$$" D D D"#87#BCCC & & &"1oo%& goobg&8&8&@&@AAG&&""27#3#3G#<#<kJJJ7>>'** "57>?   *++,W\-BCCDD
 &6G$ 	J 	JDs#6#6

3HHIIIIkk),,,7 	?$ ? ?	$++IOO,=,=>>>>>QK!>>499Z#8#8#8:   K!>>499[#9#9#9;   .	#n4'.8.?77"G"Gdjjll"G"G"GGG4!1 0 2 2 &"4  

 

 

 " 	   LNNN++GJ,?MML))A-!#!6!6 =	 =	D$]^^,I$,,Y==L 7W\\'<@@
J66667 ) )G++))#.. -']2J2JG,,, 444KK(((! / /$$%BCC 7<<h777<<\8+;+;It+L+L  /3.L  *J
((44 #+#8#8#D#Dz#Q 7>>(++ 	& %HH LLL*NN   $$Z00 8H4K4Kh999 7]"/"4"4"6"67 7 7 7 7 7 7 7 7 7 7 7 7 7 7%xx33G<<H&oog66Ghg>>> 0( w///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 OHh777>Q&&K%%mh&>???	$$Xx888''1111   K%%#%-. 
)	    S/b  	2~""!!"@AAA"&"6 2 27>>.11 2In----M.1111y44O44444sN   4B	 	%C.B==CU22U69U6W''W+.W+1+Y2ZZc                    |1t           j                            t          j        d         d|          S |                    d          }t           j                            |          }t           j                            |          }t           j                            |          r|S | 	                    |          r| 
                    |          }nt           j                            |          }t           j                            |          r|                     |          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.
        Nr   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    7<< 2FFCCC,,Y77H " 2 28 < < " 0 01B C Cw}}.// )(({{8$$ C $h 7 7 "0A B Bw~~m,, 3||M222l151D1D1DhhhO
 
 	
r+   r   c                 `   |.t          d                    | j        | j                            |                                s*t          d                    || j        |                    t          |          0t          d                    || j        | j        |                    d S )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 1   T??&""(&|+$	 #) # #	 	 	 '&r+   c           	         d }d| j         z  }t          j        |d          }| j                            |            ||          \  }}| j        dk    r| j                            d|z             t          j	        
                    ||          }t                      }ddt          j         fg|_        	 |                    |          5 }	t          |d	          5 }
|	                                }|
                    |	                                           d
d
d
           n# 1 swxY w Y   d
d
d
           n# 1 swxY w Y   n*# t$          $ r}t'          d|d|d|          d
}~ww xY w|                    d          d         }|d         }|r*t+          |          \  }}|                    d          p|}n|}|                     |          d         }|d         }|s|rt1          j        |          }|r||z  }||k    r7t          j	        
                    ||          }t5          j        ||           |S |S )zB
        Download the given URL and return the file name.
        c                     |                      d          }|                    d          d         }|                     d          r|dz   }n| }||fS )N/)rstripr[   rk   )urltmpr   display_urls       r)   cleanup_urlz-TemplateCommand.download.<locals>.cleanup_url(  sT    **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EE##G,,, +C 0 0+>QK.<===7<<22*,Jf6H,J,JKL	S!! ,VT(D-A-A ,V ++--V[[]]+++, , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,  	 	 	,8;XXXqqI  	
 NN3''+	 &&;< 	)/0CDDIAv%zz*55B( mm,--a0~. 	(| 	(+L99C ( C'  (((7<<1ABBLK,/// s`   :E D? <D(D?(D,	,D?/D,	0D?3E ?EE EE 
E2E--E2c                     t          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  s^     &x00	c::<<  (( 	rss)c/C9DSyr+   c           	      b   d| j         z  }t          j        |d          }| j                            |           | j        dk    r| 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DD##G,,,>QKo8999	OHg...N('2 	 	 	,8@'''11M  	s   $A; ;B.B))B.c                 |    d|vrdS |                     dd          d                                         }|| 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}  sD    h5Q''*0022)))r+   c                     t          j        d          }t          j        |           t          j        t          j        |          j                  }t          j        ||| z             d S )Nr   )rM   umaskstatS_IMODEst_modechmod)r'   r   r   current_umaskcurrent_modes        r)   rt   zTemplateCommand.apply_umask  sZ    
|BGH$5$5$=>>
<=.899999r+   c                     t          j        |t           j                  sQt          j        |          }t          j        |j                  t          j        z  }t          j        ||           dS dS )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  sc    
 y27++ 	0""B"l2:66EOHX/////	0 	0r+   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      s        	 	  ***K!
&
 &
 &
PR5 R5 R5 R5h
 
 
4   >< < <|    $* * *: : :0 0 0 0 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      sa        				        $ $ $ $ $ $ ' ' ' ' ' '              A A A A A A A A         
 , + + + + + + +             5 5 5 5 5 5 1 1 1 1 1 1y0 y0 y0 y0 y0k y0 y0 y0 y0 y0r+   