a
    5Xh5                     @   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   sp   zt | dtjdkd}W n6 tyN } ztd| d  |W Y d}~n
d}~0 0 |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)argsZstdout_encodingperr r   a/var/www/viveiro_mudafortebrasil/venv/lib/python3.9/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)
extensionsZ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 rLt jddt j}|D ]}| |rPdg} qjqP|D ]P}t j	|| }t j
|r|  S |D ]$}|| }t j
|r|    S qqnd S )NPATHr   PATHEXTz.COM;.EXE;.BAT;.CMD)r   environgetr#   pathsep
isinstancestrendswithpathjoinisfile)cmdr3   pathextr(   r   fZfextr   r   r   find_command6   s&    

r9   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 rVzt|}W n tyH   td| Y n0 || qzt|}W n0 ty } ztt|W Y d}~n
d}~0 0 || 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_appsZ	get_modelLookupErrorr	   addZget_app_configr1   )labelsr   modelslabelmodelZ
app_configer   r   r   parse_apps_and_model_labelsW   s    "rE   c                 C   sT   t ddd}|j|dd z|| dd \}}W n tyH   Y dS 0 |jS dS )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	   rH   )argvoptionparseroptions_r   r   r   get_command_line_optionr   s    rR   c                 C   sn   dd | D } dd dt jhD }g }| D ]>}|D ]*}||r2||dt|    q*q2|| q*|S )z9Normalize an iterable of glob style patterns based on OS.c                 S   s   g | ]}t j|qS r   )r   r3   normcase).0r   r   r   r   
<listcomp>       z+normalize_path_patterns.<locals>.<listcomp>c                 S   s   h | ]}d | qS )z%s*r   )rT   path_sepr   r   r   	<setcomp>   rV   z*normalize_path_patterns.<locals>.<setcomp>/N)r   sepr2   appendlen)patternsZdir_suffixesZnorm_patternspatternZ
dir_suffixr   r   r   normalize_path_patterns   s    
r_   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   r1   )r^   )r3   r   r   ignore   s    zis_ignored_path.<locals>.ignorec                 3   s   | ]} |V  qd S r`   r   )rT   r^   )rc   r   r   	<genexpr>   rV   z"is_ignored_path.<locals>.<genexpr>)r   anyr_   )r3   ignore_patternsr   )rc   r3   r   is_ignored_path   s    rg   c                   C   s   dt diS )N
black_pathblack)shutilwhichr   r   r   r   find_formatters   s    rl   c                 C   s2   |t u rtd}|r.tj|ddg| dd dS )z9
    Run the black formatter on the specified files.
    ri   z--fastz--T)r   N)sentinelrj   rk   
subprocessr   )Zwritten_filesrh   r   r   r   run_formatters   s    
ro   )r   )NN)ra   r   rj   rn   pathlibr   r   Zdjango.appsr   r=   Zdjango.utils.cryptor   Zdjango.utils.encodingr   baser	   r
   r   r*   r9   r<   rE   rR   r_   rg   rl   objectrm   ro   r   r   r   r   <module>   s&   

