
    ܖi                    f    d Z ddlmZ ddlZddlmZmZ ddlmZ	 ddl
mZ ddlmZ  G d de      Zy)	zQ
Functionality for formatting vulnerability results as an array of JSON objects.
    )annotationsN)Anycast   )VulnerabilityFormatc                  b    e Zd ZdZd	dZed
d       Z	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZddZ	ddZ
y)
JsonFormatzx
    An implementation of `VulnerabilityFormat` that formats vulnerability results as an array of
    JSON objects.
    c                     || _         || _        y)a  
        Create a new `JsonFormat`.

        `output_desc` is a flag to determine whether descriptions for each vulnerability should be
        included in the output as they can be quite long and make the output difficult to read.

        `output_aliases` is a flag to determine whether aliases (such as CVEs) for each
        vulnerability should be included in the output.
        N)output_descoutput_aliases)selfr   r   s      Z/var/www/html/content-pipeline/venv/lib/python3.12/site-packages/pip_audit/_format/json.py__init__zJsonFormat.__init__   s     ',    c                     y)z8
        See `VulnerabilityFormat.is_manifest`.
        T )r   s    r   is_manifestzJsonFormat.is_manifest#   s    
 r   c                   i }g }|j                         D ]&  \  }}|j                  | j                  ||             ( ||d<   g }|D ]"  }|j                  | j                  |             $ ||d<   t	        j
                  |      S )z
        Returns a JSON formatted string for a given mapping of dependencies to vulnerability
        results.

        See `VulnerabilityFormat.format`.
        dependenciesfixes)itemsappend_format_dep_format_fixjsondumps)	r   resultr   output_jsondep_jsondepvulnsfix_jsonfs	            r   formatzJsonFormat.format*   s      ,,. 	:JCOOD,,S%89	:&.N# 	1AOOD,,Q/0	1'Gzz+&&r   c                F   |j                         r3t        t        j                  |      }|j                  |j
                  dS t        t        j                  |      }|j                  t        |j                        |D cg c]  }| j                  |       c}dS c c}w )N)nameskip_reason)r&   versionr!   )

is_skippedr   serviceSkippedDependencycanonical_namer'   ResolvedDependencystrr(   _format_vuln)r   r    r!   vulns       r   r   zJsonFormat._format_dep@   s     >>w00#6C**" 
 7--s3&&3;;':?@$d''-@
 	
 As   Bc                    |j                   |j                  D cg c]  }t        |       c}d}| j                  rt	        |j
                        |d<   | j                  r|j                  |d<   |S c c}w )N)idfix_versionsaliasesdescription)r2   r3   r.   r   listr4   r   r5   )r   r0   r(   	vuln_jsons       r   r/   zJsonFormat._format_vulnQ   sk    ''9=9J9JKgS\K
	 #'#5Ii '+'7'7Im$ Ls   A2c                   |j                         r[t        t        j                  |      }|j                  j
                  t        |j                  j                        |j                  dS t        t        j                  |      }|j                  j
                  t        |j                  j                        t        |j                        dS )N)r&   r(   r'   )r&   old_versionnew_version)
r)   r   fixSkippedFixVersionr    r,   r.   r(   r'   ResolvedFixVersion)r   fix_versions     r   r   zJsonFormat._format_fix\   s    !!#s44kBK#66{667*66 
 311;?OO22{667{223
 	
r   N)r   boolr   r?   )returnr?   )r   z;dict[service.Dependency, list[service.VulnerabilityResult]]r   zlist[fix.FixVersion]r@   r.   )r    zservice.Dependencyr!   z!list[service.VulnerabilityResult]r@   dict[str, Any])r0   zservice.VulnerabilityResultr@   rA   )r>   zfix.FixVersionr@   rA   )__name__
__module____qualname____doc__r   propertyr   r$   r   r/   r   r   r   r   r	   r	      sh    
-  'K' $' 
	',
%
.O
	
"	
r   r	   )rE   
__future__r   r   typingr   r   pip_audit._fix_fixr;   pip_audit._service_servicer*   	interfacer   r	   r   r   r   <module>rN      s-    #    $ *Y
$ Y
r   