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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d	ZG d
d dZG dd dZdddZdS )zModule containing shims around Flake8 2.x behaviour.

Previously, users would import :func:`get_style_guide` from ``flake8.engine``.
In 3.0 we no longer have an "engine" module but we maintain the API from it.
    )annotationsN)Any)expand_paths)base)application)
parse_args)get_style_guidec                   @  s2   e Zd ZdZdddZedd	d
ZdddZdS )Reporta"  Public facing object that mimic's Flake8 2.0's API.

    .. note::

        There are important changes in how this object behaves compared to
        the object provided in Flake8 2.x.

    .. warning::

        This should not be instantiated by users.

    .. versionchanged:: 3.0.0
    r   app.ApplicationreturnNonec                 C  s*   |j dusJ || _|j | _| jj| _dS )zlInitialize the Report for the user.

        .. warning:: This should not be instantiated by users.
        N)guide_application_style_guidestats_statsselfr    r   G/var/www/html/ai/venv/lib/python3.10/site-packages/flake8/api/legacy.py__init__'   s   zReport.__init__intc                 C  s   | j jS )z"Return the total number of errors.)r   result_countr   r   r   r   total_errors1   s   zReport.total_errors	violationstr	list[str]c                 C  s   dd | j |D S )zGet the list of occurrences of a violation.

        :returns:
            List of occurrences of a violation formatted as:
            {Count} {Error Code} {Message}, e.g.,
            ``8 E531 Some error message about the error``
        c                 S  s&   g | ]}|j  d |j d |j qS ) )count
error_codemessage).0sr   r   r   
<listcomp>>   s    z)Report.get_statistics.<locals>.<listcomp>)r   statistics_for)r   r   r   r   r   get_statistics6   s   
zReport.get_statisticsNr   r
   r   r   )r   r   )r   r   r   r   )__name__
__module____qualname____doc__r   propertyr   r&   r   r   r   r   r	      s    

r	   c                   @  sn   e Zd ZdZd&ddZed'd	d
Zed(ddZd)d*ddZd)d+ddZ		d)d,ddZ
			d-d.d$d%ZdS )/
StyleGuideaD  Public facing object that mimic's Flake8 2.0's StyleGuide.

    .. note::

        There are important changes in how this object behaves compared to
        the StyleGuide object provided in Flake8 2.x.

    .. warning::

        This object should not be instantiated directly by users.

    .. versionchanged:: 3.0.0
    r   r
   r   r   c                 C  s   || _ |j| _dS )zInitialize our StyleGuide.N)r   file_checker_manager_file_checker_managerr   r   r   r   r   S   s   zStyleGuide.__init__argparse.Namespacec                 C  s   | j jdusJ | j jS )zuReturn application's options.

        An instance of :class:`argparse.Namespace` containing parsed options.
        N)r   optionsr   r   r   r   r1   X   s   zStyleGuide.optionsr   c                 C  s   | j jdusJ | j jjS )z+Return the extra arguments passed as paths.N)r   r1   	filenamesr   r   r   r   pathsa   s   
zStyleGuide.pathsNr3   list[str] | Noner	   c                 C  s8   | j jdusJ || j j_| j   | j   t| j S )a)  Run collected checks on the files provided.

        This will check the files passed in and return a :class:`Report`
        instance.

        :param paths:
            List of filenames (or paths) to check.
        :returns:
            Object that mimic's Flake8 2.0's Reporter class.
        N)r   r1   r2   
run_checksreport_errorsr	   )r   r3   r   r   r   check_filesg   s
   



zStyleGuide.check_filesfilenamer   parent
str | Noneboolc                   s0   d fdd}||p|duo|t j||S )	a"  Determine if a file is excluded.

        :param filename:
            Path to the file to check if it is excluded.
        :param parent:
            Name of the parent directory containing the file.
        :returns:
            True if the filename is excluded, False otherwise.
        pathr   r   r;   c                   s(   t t| g jj jj jjd}| S )N)r3   stdin_display_namefilename_patternsexclude)tupler   r1   r=   r8   r?   )r<   r3   r   r   r   excluded   s   z%StyleGuide.excluded.<locals>.excludedN)r<   r   r   r;   )osr<   join)r   r8   r9   rA   r   r   r   rA   x   s   zStyleGuide.excludedreporter$type[formatter.BaseFormatter] | Nonec                 C  sX   |du rdS t |tjstd|| j| j_d| j_| j  d| j_| j	g  dS )z*Set up a formatter for this run of Flake8.Nz<Report should be subclass of flake8.formatter.BaseFormatter.)

issubclass	formatterBaseFormatter
ValueErrorr1   r   r   
make_guider.   make_file_checker_manager)r   rD   r   r   r   init_report   s   
zStyleGuide.init_reportr   lines
Any | Noneexpectedline_offsetc                 C  s   |  |gS )a  Run collected checks on a single file.

        This will check the file passed in and return a :class:`Report`
        instance.

        :param filename:
            The path to the file to check.
        :param lines:
            Ignored since Flake8 3.0.
        :param expected:
            Ignored since Flake8 3.0.
        :param line_offset:
            Ignored since Flake8 3.0.
        :returns:
            Object that mimic's Flake8 2.0's Reporter class.
        )r7   )r   r8   rM   rO   rP   r   r   r   
input_file   s   zStyleGuide.input_filer'   )r   r0   )r   r   )N)r3   r4   r   r	   )r8   r   r9   r:   r   r;   )rD   rE   r   r   )NNr   )
r8   r   rM   rN   rO   rN   rP   rN   r   r	   )r(   r)   r*   r+   r   r,   r1   r3   r7   rA   rL   rQ   r   r   r   r   r-   D   s    
r-   kwargsr   r   c               	   K  s   t  }tg \|_|_|j}|  D ] \}}zt|| t||| W q ty3   t	
d| Y qw |  |  |g  t|S )zProvision a StyleGuide for use.

    :param \*\*kwargs:
        Keyword arguments that provide some options for the StyleGuide.
    :returns:
        An initialized StyleGuide
    zCould not update option "%s")appApplicationr   pluginsr1   itemsgetattrsetattrAttributeErrorLOGerrormake_formatterrJ   rK   r-   )rR   r   r1   keyvaluer   r   r   r      s   

r   )rR   r   r   r-   )r+   
__future__r   argparseloggingos.pathrB   typingr   flake8.discover_filesr   flake8.formattingr   rG   flake8.mainr   rS   flake8.options.parse_argsr   	getLoggerr(   rZ   __all__r	   r-   r   r   r   r   r   <module>   s    
,}