
    ܖi                        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
m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mZmZmZmZmZmZ  ej6                  e      Z G d de      Zy)zb
Functionality for using the [Ecosyste.ms](https://ecosyste.ms/) API as a `VulnerabilityService`.
    )annotationsN)Path)Anycast)	urlencode)SpecifierSet)Version)caching_session)ConnectionError
DependencyResolvedDependencyServiceErrorVulnerabilityIDVulnerabilityResultVulnerabilityServicec                  ,    e Zd ZdZ	 	 d	 	 	 ddZddZy)EcosystemsServicez
    An implementation of `VulnerabilityService` that uses Ecosyste.ms to provide Python
    package vulnerability information.
    Nc                6    t        |d      | _        || _        y)aq  
        Create a new `EcosystemsService`.

        `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)self	cache_dirr   s      [/var/www/html/content-pipeline/venv/lib/python3.12/site-packages/pip_audit/_service/esms.py__init__zEcosystemsService.__init__%   s     'y%@    c                X   d}|j                         r|g fS t        t        |      }d|j                  d}	 | j                  j                  | dt        |       | j                        }|j                          g }|j                         }|s||fS |D ]O  }|d   }	|d	   }
|
t        j!                  d
|	d    d|
        /|d   }|s|d   }|sd}|j#                  dd      }d}t%               }|d   D ]  }|d   |j                  k7  s|d   dk7  r|d   D ]s  }|d   }t'        t)        j*                  dd|            }|j-                  |j.                        sDd}|j                  d      x}|j1                  t3        |                |s|j5                  t7        j8                  |	|t;        |      | j=                  |j                  d                         R ||fS # t        j                  $ r t        d      t        j                  $ r}t        |d}~ww xY w)zz
        Queries Ecosyste.ms for the given `Dependency` specification.

        See `VulnerabilityService.query`.
        z0https://advisories.ecosyste.ms/api/v1/advisoriespypi)	ecosystempackage_name?)r   z-Could not connect to ESMS' vulnerability feedNidentifierswithdrawn_atzESMS vuln entry 'r   z' marked as withdrawn at titledescriptionzN/A
 Fpackagesr    r   versionsvulnerable_version_rangez	(^|(, ))=z\1==Tfirst_patched_version	published)idsr%   fix_versionsr,   )
is_skippedr   r   canonical_namer   getr   r   raise_for_statusrequestsConnectTimeoutr   	HTTPErrorr   jsonloggerdebugreplacesetr   resubcontainsversionaddr	   appendr   createsorted_parse_rfc3339)r   specurlqueryresponse
http_errorresultsresponse_jsonvulnr-   r#   r%   seen_vulnerabler.   affectedrecordosv_spec
vulnerablepatcheds                      r   rF   zEcosystemsService.query6   s}    A??8O&-   //

		/*.,,*:*:%q5)*+ +; +H %%' .0 =  " =	D)-m)<C  /L'0Q8QR^Q_`a w-K"=1# &--dC8K#O),L ,  ^,0C0CC,6&z2 F
 %++E$FH!-bff\7H.U!VJ%..t||< &*O#)::.E#FFS$(()9:. #NN#** +!'!5"11$((;2GH	m=	~ W}] && 	S!"QRR!! 	/J.	/s   AG- -0H)H$$H))NN)r   zPath | Noner   z
int | None)rD   r   returnz,tuple[Dependency, list[VulnerabilityResult]])__name__
__module____qualname____doc__r   rF    r   r   r   r      s,     "&" "er   r   )rV   
__future__r   loggingr;   pathlibr   typingr   r   urllib.parser   r3   packaging.specifiersr   packaging.versionr	   pip_audit._cacher
   pip_audit._service.interfacer   r   r   r   r   r   r   	getLoggerrS   r7   r   rW   r   r   <module>rb      s\    #  	   "  - % ,   
		8	$|, |r   