
    ܖim                        d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	 ddl
Z
ddlmZ ddlmZ ddlmZmZmZmZmZmZ  ej,                  e      Z G d	 d
e      Zy)zV
Functionality for using the [OSV](https://osv.dev/) API as a `VulnerabilityService`.
    )annotationsN)Path)Anycast)Version)caching_session)ConnectionError
DependencyResolvedDependencyServiceErrorVulnerabilityResultVulnerabilityServicec                  6    e Zd ZdZdZddef	 	 	 	 	 ddZddZy)
OsvServicez|
    An implementation of `VulnerabilityService` that uses OSV to provide Python
    package vulnerability information.
    zhttps://api.osv.dev/v1/queryNc                D    t        |d      | _        || _        || _        y)aj  
        Create a new `OsvService`.

        `cache_dir` is an optional cache directory to use, for caching and reusing OSV API
        requests. If `None`, `pip-audit` will use its own internal caching directory.

        `timeout` is an optional argument to control how many seconds the component should wait for
        responses to network requests.
        F)use_pipN)r   sessiontimeoutosv_url)self	cache_dirr   r   s       Z/var/www/html/content-pipeline/venv/lib/python3.12/site-packages/pip_audit/_service/osv.py__init__zOsvService.__init__$   s      'y%@    c                   |j                         r|g fS t        t        |      }|j                  ddt	        |j
                        d}	 | j                  j                  | j                  t        j                  |      | j                        }|j                          g }|j                         }|s||fS |d   D ]  }t%        |j'                  dd	            }|j(                  d
k7  rt*        j-                  d|        G|d   }	|j'                  d      }
|
t*        j/                  d|	 d|
        {|j'                  d      }||j'                  d      }|d}|j1                  dd      }|j'                  d      }|t*        j-                  d|	 d       g }|D ]h  }|d   }|d   |j                  k(  s|d   dk(  s$|d   D ]=  }|d   dk(  s|d   D cg c]  }d|v r|d    }}|D cg c]  }t%        |       }} h j |j3                          |j5                  t7        j8                  |	g|j'                  dg       ||| j;                  |j'                  d             !              ||fS # t        j                  $ r t        d      t        j                   $ r}t"        |d}~ww xY wc c}w c c}w )"zr
        Queries OSV for the given `Dependency` specification.

        See `VulnerabilityService.query`.
        PyPI)name	ecosystem)packageversion)urldatar   z-Could not connect to OSV's vulnerability feedNvulnsschema_versionz1.0.0   z Unsupported OSV schema version: id	withdrawnzOSV vuln entry 'z' marked as withdrawn at summarydetailszN/A
 affectedz' is missing 'affected' listr   r   r   rangestype	ECOSYSTEMeventsfixedaliases	published)idsdescriptionfix_versionsr3   )
is_skippedr   r   canonical_namestrr    r   postr   jsondumpsr   raise_for_statusrequestsConnectTimeoutr	   	HTTPErrorr   r   getmajorloggerwarningdebugreplacesortappendr   create_parse_rfc3339)r   specqueryresponse
http_errorresultsresponse_jsonvulnr$   r&   withdrawn_atr5   	affectedsr6   r,   pkgr-   r    fix_version_strsversion_strs                       r   rL   zOsvService.query7   s    ??8O&- !% 3 3&I4<<(

	/*.,,*;*;LLZZ& +< +H
 %%' .0 =  "'* D	D
 %TXX.>%HIN##q(!A.AQRSdB  88K0L'/t3L\N[\ ((9-K""hhy1"# &--dC8K ,I !1"5QRS*,L% "y)v;$"5"55#k:Jf:T"*8"4 "!&>[8 06h/?0$+#*g#5 !( 00, 0 IY,9D 4,L , ""	"& NN#**6dhhy"56 +!-"11$((;2GH	{D	L W}k && 	S!"QRR!! 	/J.	/x0,s%   AI> J=
5K
>0J:.J55J:)r   zPath | Noner   z
int | Noner   r9   )rK   r
   returnz,tuple[Dependency, list[VulnerabilityResult]])__name__
__module____qualname____doc__DEFAULT_OSV_URLr   rL    r   r   r   r      s@    
 5O "&"&	  	&jr   r   )r[   
__future__r   r;   loggingpathlibr   typingr   r   r>   packaging.versionr   pip_audit._cacher   pip_audit._service.interfacer	   r
   r   r   r   r   	getLoggerrX   rC   r   r]   r   r   <module>rf      sQ    #      % ,  
		8	$E% Er   