o
    h-                     @  s   d Z ddlm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m
Z
 ddlmZ ddlmZ eeZed	d
ZddddddZG dd dZG dd dZdS )z,Option handling and Option management logic.    )annotationsN)Any)Callable)Sequence)utils)Plugins_ARGNOFcomma_separated_listnormalize_pathsvaluestrargsr   boolr   returnstr | list[str]c                G  sV   | }|rt |trt| }|r)t |tr tj|g|R  }|S tj|g|R  }|S N)
isinstancer   r   parse_comma_separated_listnormalize_pathr   )r   r   r   r   ret r   L/var/www/html/ai/venv/lib/python3.10/site-packages/flake8/options/manager.py_flake8_normalize   s   

r   c                   @  s~   e Zd ZdZejejejejejejejejejejejejdddfd-ddZed.dd Zd/d"d#Z	d0d'd(Z
d1d*d+Zd,S )2Optionz@Our wrapper around an argparse argument parsers to add features.Fshort_option_name
str | _ARGlong_option_nameaction"str | type[argparse.Action] | _ARGdefault
Any | _ARGtypeCallable[..., Any] | _ARGdestnargsint | str | _ARGconstchoicesSequence[Any] | _ARGhelpmetavarrequiredbool | _ARGparse_from_configr   r   r   r   Nonec                 C  s  |t ju r|t jur|drt j|}}|s|r!tjt||d}|| _|| _dd ||fD | _|| _	|| _
|| _|| _|| _|| _|	| _|
| _|| _|| _| j	| j
| j| j| j| j| j| j| j| jd
| _|| _|| _|| _d| _|r|t ju r~td|dd d	d
| _d| _dS )a  Initialize an Option instance.

        The following are all passed directly through to argparse.

        :param short_option_name:
            The short name of the option (e.g., ``-x``). This will be the
            first argument passed to ``ArgumentParser.add_argument``
        :param long_option_name:
            The long name of the option (e.g., ``--xtra-long-option``). This
            will be the second argument passed to
            ``ArgumentParser.add_argument``
        :param default:
            Default value of the option.
        :param dest:
            Attribute name to store parsed option value as.
        :param nargs:
            Number of arguments to parse for this option.
        :param const:
            Constant value to store on a common destination. Usually used in
            conjunction with ``action="store_const"``.
        :param choices:
            Possible values for the option.
        :param help:
            Help text displayed in the usage information.
        :param metavar:
            Name to use instead of the long option name for help text.
        :param required:
            Whether this option is required or not.

        The following options may be passed directly through to :mod:`argparse`
        but may need some massaging.

        :param type:
            A callable to normalize the type (as is the case in
            :mod:`argparse`).
        :param action:
            Any action allowed by :mod:`argparse`.

        The following parameters are for Flake8's option handling alone.

        :param parse_from_config:
            Whether or not this option should be parsed out of config files.
        :param comma_separated_list:
            Whether the option is a comma separated list when parsing from a
            config file.
        :param normalize_paths:
            Whether the option is expecting a path or list of paths and should
            attempt to normalize the paths to absolute paths.
        z--r
   c                 S  s   g | ]	}|t jur|qS r   r   r	   ).0xr   r   r   
<listcomp>   s
    
z#Option.__init__.<locals>.<listcomp>)
r   r!   r#   r%   r&   r(   r)   r+   r,   r-   NzRWhen specifying parse_from_config=True, a long_option_name must also be specified.   -_)r   r	   
startswith	functoolspartialr   r   r   option_argsr   r!   r#   r%   r&   r(   r)   r+   r,   r-   option_kwargsr/   r   r   config_name
ValueErrorreplace_opt)selfr   r   r   r!   r#   r%   r&   r(   r)   r+   r,   r-   r/   r   r   r   r   r   __init__,   s`   
F


zOption.__init__dict[str, Any]c                 C  s   dd | j  D S )z(Return any actually-specified arguments.c                 S  s    i | ]\}}|t jur||qS r   r1   )r2   kvr   r   r   
<dictcomp>   s    z1Option.filtered_option_kwargs.<locals>.<dictcomp>)r<   itemsrA   r   r   r   filtered_option_kwargs   s   zOption.filtered_option_kwargsr   c                 C  sT   g }| j D ]}|| q| j D ]\}}|| d| qdd| dS )N=zOption(z, ))r;   appendrI   rG   join)rA   partsargrD   rE   r   r   r   __repr__   s   
zOption.__repr__r   r   normalize_argsc                 G  sV   | j rt|trt|}| jr)t|tr tj|g|R  }|S tj|g|R  }|S )z6Normalize the value based on the option configuration.)r   r   r   r   r   r   listr   )rA   r   rQ   r   r   r   	normalize   s   

zOption.normalize tuple[list[str], dict[str, Any]]c                 C  s   | j | jfS )z?Convert a Flake8 Option to argparse ``add_argument`` arguments.)r;   rI   rH   r   r   r   to_argparse   s   zOption.to_argparseN) r   r   r   r   r   r    r!   r"   r#   r$   r%   r   r&   r'   r(   r"   r)   r*   r+   r   r,   r   r-   r.   r/   r   r   r   r   r   r   r0   )r   rC   )r   r   )r   r   rQ   r   r   r   )r   rT   )__name__
__module____qualname____doc__r   r	   rB   propertyrI   rP   rS   rU   r   r   r   r   r   )   s0     

r   c                   @  sR   e Zd ZdZd#ddZd$ddZd%ddZd&ddZd&ddZ		d'd(d!d"Z	dS ))OptionManagerz=Manage Options and OptionParser while adding post-processing.versionr   plugin_versionsparentslist[argparse.ArgumentParser]formatter_names	list[str]r   r0   c             	   C  sz   || _ tjdd|d| d| _| jjdd| d| dt  d	 | jjd
ddd i | _g | _g | _	g | _
d| _dS )z+Initialize an instance of an OptionManager.flake8z %(prog)s [options] file file ...zInstalled plugins: )progusager^   epilogz	--versionr\   z (z) )r   r\   	filenames*filename)r&   r,   N)r`   argparseArgumentParserparseradd_argumentr   get_python_versionconfig_options_dictoptionsextended_default_ignoreextended_default_select_current_group)rA   r\   r]   r^   r`   r   r   r   rB      s(   	
zOptionManager.__init__pluginsr   c                   sn   i  d
 fdd}|  D ]#}t|jdd}|r#||jj | |jjjd	kr1|jg qd_	dS )z(Register the plugin options (if needed).namer   r   r0   c                   s@   z |  _ W d S  ty   j| }| _  | < Y d S w r   )rr   KeyErrorrk   add_argument_group)rt   groupgroupsrA   r   r   
_set_group   s   z2OptionManager.register_plugins.<locals>._set_groupadd_optionsNzflake8.extension)rt   r   r   r0   )
all_pluginsgetattrobjpluginpackageentry_pointrw   extend_default_select
entry_namerr   )rA   rs   rz   loadedr{   r   rx   r   register_plugins   s   
zOptionManager.register_pluginsr   r   kwargsc                 O  s   t |i |}| \}}| jdur| jj|i | n	| jj|i | | j| |jrE|j}|dus7J || j	|< || j	|
dd< td| dS )a<  Create and register a new option.

        See parameters for :class:`~flake8.options.manager.Option` for
        acceptable arguments to this method.

        .. note::

            ``short_option_name`` and ``long_option_name`` may be specified
            positionally as they are with argparse normally.
        Nr7   r6   zRegistered option "%s".)r   rU   rr   rl   rk   ro   rL   r/   r=   rn   r?   LOGdebug)rA   r   r   optionr;   r<   rt   r   r   r   
add_option  s   

zOptionManager.add_optionerror_codesSequence[str]c                 C     t d| | j| dS )zExtend the default ignore list with the error codes provided.

        :param error_codes:
            List of strings that are the error/warning codes with which to
            extend the default ignore list.
        z%Extending default ignore list with %rN)r   r   rp   extendrA   r   r   r   r   extend_default_ignore$     z#OptionManager.extend_default_ignorec                 C  r   )zExtend the default select list with the error codes provided.

        :param error_codes:
            List of strings that are the error/warning codes with which
            to extend the default select list.
        z%Extending default select list with %rN)r   r   rq   r   r   r   r   r   r   .  r   z#OptionManager.extend_default_selectNSequence[str] | Nonevaluesargparse.Namespace | Noneargparse.Namespacec                 C  s&   |r| j jdi t| | j |S )z6Proxy to calling the OptionParser's parse_args method.Nr   )rk   set_defaultsvars
parse_args)rA   r   r   r   r   r   r   8  s   zOptionManager.parse_args)
r\   r   r]   r   r^   r_   r`   ra   r   r0   )rs   r   r   r0   )r   r   r   r   r   r0   )r   r   r   r0   )NN)r   r   r   r   r   r   )
rV   rW   rX   rY   rB   r   r   r   r   r   r   r   r   r   r[      s    

"



r[   )
r   r   r   r   r   r   r   r   r   r   )rY   
__future__r   ri   enumr9   loggingtypingr   r   r   rb   r   flake8.plugins.finderr   	getLoggerrV   r   Enumr   r   r   r[   r   r   r   r   <module>   s&    
 '