o
    <g:                     @   s   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mZ	 d dl
mZ d dlmZ ddlmZmZ dd
dZdd ZdddZdd Zdd Zdd Zdd Zdd Zdd Ze  ZfddZdS )     N)Path)run)appsget_random_string)DEFAULT_LOCALE_ENCODING   )CommandErrorCommandParserutf-8c              
   C   sd   zt | dtjdkd}W n ty! } z	td| d  |d}~ww |j||jjtdd|j	fS )	zf
    Friendly wrapper around Popen.

    Return stdout output, stderr output, and OS status code.
    Tnt)capture_output	close_fdszError executing %sr   Nreplace)errors)
r   osnameOSErrorr	   stdoutdecodestderrr   
returncode)argsstdout_encodingperr r   O/var/www/html/venv/lib/python3.10/site-packages/django/core/management/utils.pypopen_wrapper   s   
r   c                 C   sZ   g }| D ]}| |ddd qt|D ]\}}|ds(d||  ||< qt|S )a  
    Organize multiple extensions that are separated with commas or passed by
    using --extension/-e multiple times.

    For example: running 'django-admin makemessages -e js,txt -e xhtml -a'
    would result in an extension list: ['.js', '.txt', '.xhtml']

    >>> handle_extensions(['.html', 'html,js,py,py,py,.py', 'py,.py'])
    {'.html', '.js', '.py'}
    >>> handle_extensions(['.html, txt,.tpl'])
    {'.html', '.tpl', '.txt'}
      ,.z.%s)extendr   split	enumerate
startswithset)
extensionsext_listextir   r   r   handle_extensions    s   
r,   c                 C   s   |d u rt jddt j}t|tr|g}|d u r&t jddt j}|D ]}| |r4dg} nq(|D ](}t j	|| }t j
|rJ|  S |D ]}|| }t j
|r^|    S qLq7d S )NPATHr    PATHEXTz.COM;.EXE;.BAT;.CMD)r   environgetr$   pathsep
isinstancestrendswithpathjoinisfile)cmdr5   pathextr*   r   ffextr   r   r   find_command6   s,   

r<   c                  C   s   d} t d| S )zS
    Return a 50 character random string usable as a SECRET_KEY setting value.
    z2abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)2   r   )charsr   r   r   get_random_secret_keyO   s   
r?   c                 C   s   t  }t  }| D ]@}d|v r)zt|}W n ty"   td| w || qzt|}W n tyB } ztt|d}~ww || q||fS )z
    Parse a list of "app_label.ModelName" or "app_label" strings into actual
    objects and return a two-element tuple:
        (set of model classes, set of app_configs).
    Raise a CommandError if some specified models or apps don't exist.
    r"   zUnknown model: %sN)r'   installed_apps	get_modelLookupErrorr	   addget_app_configr3   )labelsr   modelslabelmodel
app_configer   r   r   parse_apps_and_model_labelsW   s$   rK   c                 C   sN   t ddd}|j|dd z|| dd \}}W |jS  ty&   Y dS w )z
    Return the value of a command line option (which should include leading
    dashes, e.g. '--testrunner') from an argument list. Return None if the
    option wasn't passed or if the argument list couldn't be parsed.
    F)add_helpallow_abbrevvalue)dest   N)r
   add_argumentparse_known_argsr	   rN   )argvoptionparseroptions_r   r   r   get_command_line_optionr   s   rX   c                 C   sf   dd | D } dd dt jhD }g }| D ]}|D ]}||r*|||  nq|| q|S )z9Normalize an iterable of glob style patterns based on OS.c                 S   s   g | ]}t j|qS r   )r   r5   normcase).0r   r   r   r   
<listcomp>   s    z+normalize_path_patterns.<locals>.<listcomp>c                 S   s   h | ]}d | qS )z%s*r   )rZ   path_sepr   r   r   	<setcomp>   s    z*normalize_path_patterns.<locals>.<setcomp>/)r   sepr4   appendremovesuffix)patternsdir_suffixesnorm_patternspattern
dir_suffixr   r   r   normalize_path_patterns   s   

rg   c                    s.   t fdd t fddt|D S )zy
    Check if the given path should be ignored or not based on matching
    one of the glob style `ignore_patterns`.
    c                    s   t  j| pt t | S N)fnmatchfnmatchcaser   r3   )re   )r5   r   r   ignore   s   zis_ignored_path.<locals>.ignorec                 3   s    | ]} |V  qd S rh   r   )rZ   re   )rk   r   r   	<genexpr>   s    z"is_ignored_path.<locals>.<genexpr>)r   anyrg   )r5   ignore_patternsr   )rk   r5   r   is_ignored_path   s   ro   c                   C   s   dt diS )N
black_pathblack)shutilwhichr   r   r   r   find_formatters   s   rt   c                 C   s6   |t u r	td}|rtj|ddg| dd dS dS )z9
    Run the black formatter on the specified files.
    rq   z--fastz--T)r   N)sentinelrr   rs   
subprocessr   )written_filesrp   r   r   r   run_formatters   s   

rx   )r   )NN)ri   r   rr   rv   pathlibr   r   django.appsr   r@   django.utils.cryptor   django.utils.encodingr   baser	   r
   r   r,   r<   r?   rK   rX   rg   ro   rt   objectru   rx   r   r   r   r   <module>   s(    

