o
    b	                     @   s   d dl Z d dlZd dlmZ d dlmZ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S )    N)Path)PIPErun)appsget_random_string)DEFAULT_LOCALE_ENCODING   )CommandErrorCommandParserutf-8c              
   C   sf   zt | tt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.
    nt)stdoutstderr	close_fdszError executing %sr   Nreplace)errors)r   r   osnameOSErrorr
   r   decoder   r   
returncode)argsZstdout_encodingperr r   [/var/www/secure340b-portal/env/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)
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 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)cmdr3   pathextr(   r   fZfextr   r   r   find_command4   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_keyM   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_appsZ	get_modelLookupErrorr
   addZget_app_configr1   )labelsr   modelslabelmodelZ
app_configer   r   r   parse_apps_and_model_labelsU   s$   rE   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
   rH   )argvoptionparseroptions_r   r   r   get_command_line_optionp   s   rR   c                 C   sn   dd | D } dd dt jhD }g }| D ]}|D ]}||r.||dt|    nq|| 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>   s    z+normalize_path_patterns.<locals>.<listcomp>c                 S   s   h | ]}d | qS )z%s*r   )rT   path_sepr   r   r   	<setcomp>   s    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]   )rb   r   r   	<genexpr>   s    z"is_ignored_path.<locals>.<genexpr>)r   anyr^   )r3   ignore_patternsr   )rb   r3   r   is_ignored_path   s   rf   )r   )NN)r`   r   pathlibr   
subprocessr   r   Zdjango.appsr   r=   Zdjango.utils.cryptor   Zdjango.utils.encodingr   baser
   r   r   r*   r9   r<   rE   rR   r^   rf   r   r   r   r   <module>   s     

