
    ܖiG                       d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZmZ ddlmZ dd	lmZ  ed
e      ZddZ e	d       G d d             Z e	d       G d de             Z e	d       G d de             Z e	d       G d d             Z G d de      Z G d de      Z G d de      Zy)z
Interfaces for interacting with vulnerability services, i.e. sources
of vulnerability information for fully resolved Python packages.
    )annotations)ABCabstractmethod)Iterator)	dataclassreplace)datetime)AnyNewType)canonicalize_name)VersionVulnerabilityIDc                L    | j                  d      ry| j                  d      ryy)NPYSEC   CVE      )
startswith)ids    `/var/www/html/content-pipeline/venv/lib/python3.12/site-packages/pip_audit/_service/interface.py_id_comparison_keyr      s#    	}}W	u	    T)frozenc                  @    e Zd ZU dZded<   	 ddZed	d       Zd
dZy)
Dependencyz`
    Represents an abstract Python package.

    This class cannot be constructed directly.
    strnamec                    t         )z7
        A stub constructor that always fails.
        NotImplementedError)self_args_kwargss      r   __init__zDependency.__init__+   s
     "!r   c                ,    t        | j                        S )z@
        The `Dependency`'s PEP-503 canonicalized name.
        )r   r   r"   s    r   canonical_namezDependency.canonical_name2   s    
 !++r   c                &    | j                   t        u S )zJ
        Check whether the `Dependency` was skipped by the audit.
        )	__class__SkippedDependencyr'   s    r   
is_skippedzDependency.is_skipped9   s     ~~!222r   N)r#   r
   r$   r
   returnNone)r-   r   )r-   bool)	__name__
__module____qualname____doc____annotations__r%   propertyr(   r,    r   r   r   r      s1     I" , ,3r   r   c                      e Zd ZU dZded<   y)ResolvedDependencyz5
    Represents a fully resolved Python package.
    r   versionNr0   r1   r2   r3   r4   r6   r   r   r8   r8   @   s     r   r8   c                      e Zd ZU dZded<   y)r+   z[
    Represents a Python package that was unable to be audited and therefore, skipped.
    r   skip_reasonNr:   r6   r   r   r+   r+   I   s     r   r+   c                      e Zd ZU dZded<   	 ded<   	 ded<   	 ded	<   	 d
Zded<   	 e	 	 	 	 	 	 	 	 	 	 dd       ZddZddZ	ddZ
y
)VulnerabilityResultzt
    Represents a "result" from a vulnerability service, indicating a vulnerability
    in some Python package.
    r   r   r   descriptionlist[Version]fix_versionszset[VulnerabilityID]aliasesNdatetime | None	publishedc           
     d    |j                  t                | |d   ||t        |dd       |      S )z
        Instantiates a `VulnerabilityResult` with the given data, prioritizing
        PYSEC and CVE vulnerability IDs for the primary identifier.
        )keyr   r   N)sortr   set)clsidsr?   rA   rD   s        r   createzVulnerabilityResult.creater   s4     	'(3q6;c#ab'lINNr   c                    t        | j                  | j                  hz  j                  |j                  |j                  hz              S )z
        Returns whether this result is an "alias" of another result.

        Two results are said to be aliases if their respective sets of
        `{id, *aliases}` intersect at all. A result is therefore its own alias.
        )r/   rB   r   intersection)r"   others     r   alias_ofzVulnerabilityResult.alias_of   s8     T\\TWWI-;;EMMUXXJ<VWXXr   c                j    | j                   |j                   | j                  hz
  z  }t        | |      S )zS
        Merge `other`'s aliases into this result, returning a new result.
        )rB   )rB   r   r   )r"   rN   rB   s      r   merge_aliasesz!VulnerabilityResult.merge_aliases   s.     ,,$''!::tW--r   c                N    t        || j                  | j                  hz  z        S )zE
        Returns whether ids intersects with {id} | aliases.
        )r/   rB   r   )r"   rJ   s     r   
has_any_idzVulnerabilityResult.has_any_id   s#     C4<<477)3455r   )
rJ   zlist[VulnerabilityID]r?   r   rA   r@   rD   rC   r-   r>   )rN   r>   r-   r/   )rN   r>   r-   r>   )rJ   zset[str]r-   r/   )r0   r1   r2   r3   r4   rD   classmethodrK   rO   rQ   rS   r6   r   r   r>   r>   R   s    
 	    "! "&I% O"O O $	O
 #O 
O OY.6r   r>   c                  L    e Zd ZdZe	 	 	 	 dd       Z	 	 	 	 ddZedd       Zy)	VulnerabilityServicezV
    Represents an abstract provider of Python package vulnerability information.
    c                    t         )z
        Query the `VulnerabilityService` for information about the given `Dependency`,
        returning a list of `VulnerabilityResult`.
        r    )r"   specs     r   queryzVulnerabilityService.query   s
     "!r   c              #  @   K   |D ]  }| j                  |        yw)z
        Query the vulnerability service for information on multiple dependencies.

        `VulnerabilityService` implementations can override this implementation with
        a more optimized one, if they support batched or bulk requests.
        N)rY   )r"   specsrX   s      r   	query_allzVulnerabilityService.query_all   s&       	#D**T""	#s   c                    | y 	 t        j                  | d      S # t        $ r t        j                  | d      cY S w xY w)Nz%Y-%m-%dT%H:%M:%S.%fZz%Y-%m-%dT%H:%M:%SZ)r	   strptime
ValueError)dts    r   _parse_rfc3339z#VulnerabilityService._parse_rfc3339   sF    :	?$$R)@AA 	?$$R)=>>	?s    ==N)rX   r   r-   z,tuple[Dependency, list[VulnerabilityResult]])r[   zIterator[Dependency]r-   z6Iterator[tuple[Dependency, list[VulnerabilityResult]]])r`   z
str | Noner-   rC   )	r0   r1   r2   r3   r   rY   r\   staticmethodra   r6   r   r   rV   rV      sT     ""	5" "
#)
#	?
# ? ?r   rV   c                      e Zd ZdZy)ServiceErrorz
    Raised when a `VulnerabilityService` fails, for any reason.

    Concrete implementations of `VulnerabilityService` are expected to subclass
    this exception to provide more context.
    Nr0   r1   r2   r3   r6   r   r   rd   rd      s     	r   rd   c                      e Zd ZdZy)ConnectionErrorz
    A specialization of `ServiceError` specifically for cases where the
    vulnerability service is unreachable or offline.
    Nre   r6   r   r   rg   rg      s    
 	r   rg   N)r   r   r-   int)r3   
__future__r   abcr   r   collections.abcr   dataclassesr   r   r	   typingr
   r   packaging.utilsr   packaging.versionr   r   r   r   r   r8   r+   r>   rV   	Exceptionrd   rg   r6   r   r   <module>rq      s   
 # # $ *   - %+S1 $ 3  3  3F $   $
   $E6 E6 E6P'?3 '?T	9 		l 	r   