
    ܖi                        d Z ddlmZ ddlZddlm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mZmZmZmZmZmZ  ej,                  e      Z G d	 d
e      Zy)zx
Functionality for using the [PyPI](https://warehouse.pypa.io/api-reference/json.html)
API as a `VulnerabilityService`.
    )annotationsN)Path)cast)InvalidVersionVersion)caching_session)ConnectionError
DependencyResolvedDependencyServiceErrorSkippedDependencyVulnerabilityResultVulnerabilityServicec                  2    e Zd ZdZ	 d	 	 	 	 	 	 	 ddZddZy)PyPIServicez}
    An implementation of `VulnerabilityService` that uses PyPI to provide Python
    package vulnerability information.
    Nc                2    t        |      | _        || _        y)a  
        Create a new `PyPIService`.

        `cache_dir` is an optional cache directory to use, for caching and reusing PyPI API
        requests. If `None`, `pip-audit` will attempt to use `pip`'s cache directory before falling
        back on its own default cache directory.

        `timeout` is an optional argument to control how many seconds the component should wait for
        responses to network requests.
        N)r   sessiontimeout)self	cache_dirr   kwargss       [/var/www/html/content-pipeline/venv/lib/python3.12/site-packages/pip_audit/_service/pypi.py__init__zPyPIService.__init__#   s     'y1    c                    |j                         r|g fS t        t        |      }d|j                   dt	        |j
                         d}	 | j                  j                  || j                        }|j                          |j+                         }g }|j                  d      }|||fS |D ]  }	|	d   }
|	j                  d      }|t         j#                  d|
 d|        7	 |	d   D cg c]  }t-        |       }}|j1                          |	j                  d      }||	j                  d      }|d}|j3                  dd      }|j5                  t7        j8                  |
g|	d   ||| j;                  |	j                  d                          ||fS # t        j                  $ r t        d      t        j                  $ r t        d      t        j                  $ rk}j                  dk(  rPd|j                   d	|j
                   d
}t         j#                  |       t%        |j&                  |      g fcY d}~S t(        |d}~ww xY wc c}w # t.        $ r}t)        d|	d          |d}~ww xY w)zs
        Queries PyPI for the given `Dependency` specification.

        See `VulnerabilityService.query`.
        zhttps://pypi.org/pypi//z/json)urlr   z PyPI is not redirecting properlyz.Could not connect to PyPI's vulnerability feedi  z7Dependency not found on PyPI and could not be audited: z ())nameskip_reasonNvulnerabilitiesid	withdrawnzPyPI vuln entry 'z' marked as withdrawn at fixed_inz&Received malformed version from PyPI: summarydetailszN/A
 aliases	published)idsdescriptionfix_versionsr*   )
is_skippedr   r   canonical_namestrversionr   getr   raise_for_statusrequestsTooManyRedirectsr	   ConnectTimeout	HTTPErrorstatus_codeloggerdebugr   r   r   jsonr   r   sortreplaceappendr   create_parse_rfc3339)r   specr   response
http_errorr    response_jsonresultsvulnsvr"   withdrawn_atr$   r-   ivr,   s                   r   queryzPyPIService.query3   s    ??8O&-&t':':&;1S=N<OuU	/*.,,*:*:sDLL*:*YH%%'. !-/!!"34 ==  &	A4B 55-L'04Ml^\]eBCJ-Ph 1PP
 %%	*K"eeI."# &--dC8KNN#**+a	l+ +!-"11!%%2DE	?&	P W}M (( 	F ""DEE&& 	T ""RSS!! 	/##s*M**+2dll^1>  [)(dii[QSUUUJ.	/:  Q! e"%KAjM?#[\bddesP   7F &I-I?IAI*AII	III	I=&I88I=)NN)r   zPath | Noner   z
int | Noner   dictreturnNone)rA   r
   rL   z,tuple[Dependency, list[VulnerabilityResult]])__name__
__module____qualname____doc__r   rJ    r   r   r   r      s9     DH$6@SW	 Ur   r   )rQ   
__future__r   loggingpathlibr   typingr   r4   packaging.versionr   r   pip_audit._cacher   pip_audit._service.interfacer	   r
   r   r   r   r   r   	getLoggerrN   r9   r   rR   r   r   <module>r[      sS   
 #     5 ,   
		8	$k& kr   