
    ܖiQ                         d dl Z d dlmZ d dlmZmZmZ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 dd	lmZ d
dlmZmZ d
dlmZ erd dlmZ  edd      Z e	j:                  d       G d de	j<                  j>                               Z  e	j:                  d       G d d             Z! e	j:                  d       G d d             Z" e	j:                  d       G d d             Z# e	j:                  dd       G d d             Z$y)    N)Iterable)TYPE_CHECKINGAnyOptionalUnion)	SortedSet   )bom_ref_from_str)ComparableTuple)InvalidCreIdException)'SerializationOfUnexpectedValueException   )ExternalReferenceProperty)BomRef)TypeVar_T_CreIdCreId)boundT)%ignore_unknown_during_deserializationc                   *   e Zd ZdZ ej
                  d      ZdeddfdZe	 e
j                  d       e
j                  d      defd                     Zed	edefd
       Zeddd	eddfd       ZdedefdZdedefdZdefdZdefdZdefdZy)r   z
    Helper class that allows us to perform validation on data strings that must conform to
    Common Requirements Enumeration (CRE) identifier(s).

    z^CRE:[0-9]+-[0-9]+$idreturnNc                 n    t         j                  j                  |      t        d| d      || _        y )NzSupplied value "z$ does not meet format specification.)r   _VALID_CRE_REGEXmatchr   _id)selfr   s     ^/var/www/html/content-pipeline/venv/lib/python3.12/site-packages/cyclonedx/model/definition.py__init__zCreId.__init__0   s<    !!''+3'"2$&JK      .c                     | j                   S Nr   r   s    r   r   zCreId.id7   s     xxr!   oc                 L    t        ||       rt        |      S t        d|      )Nz"Attempt to serialize a non-CreId: )
isinstancestrr   clsr'   s     r   	serializezCreId.serialize=   s,    aq6M5068 	8r!   r,   ztype[_T_CreId]r   c                 &     | t        |            S )N)r   )r*   r+   s     r   deserializezCreId.deserializeD   s    c!f~r!   otherc                 V    t        |t              r| j                  |j                  k(  S yNF)r)   r   r   r   r0   s     r   __eq__zCreId.__eq__H   s"    eU#88uyy((r!   c                 `    t        |t              r| j                  |j                  k  S t        S r$   )r)   r   r   NotImplementedr3   s     r   __lt__zCreId.__lt__M   s%    eU#88eii''r!   c                 ,    t        | j                        S r$   )hashr   r&   s    r   __hash__zCreId.__hash__R   s    DHH~r!   c                 "    d| j                    dS )Nz<CreId >r%   r&   s    r   __repr__zCreId.__repr__U   s    
!$$r!   c                     | j                   S r$   r%   r&   s    r   __str__zCreId.__str__X   s    xxr!   )__name__
__module____qualname____doc__recompiler   r*   r    propertyserializable	json_namexml_namer   classmethodr   r-   r/   boolr4   r7   intr:   r=   r?    r!   r   r   r   &   s	    "rzz"893 4  \C \3C    !  8# 8# 8 8 ) c j  C D 
C D 
# %# % r!   c                      e Zd ZdZdddddddddd	deeeef      dee   dee   dee   deee      d	eee	      d
eeeef      deee
      deee      ddfdZe ej                  e       ej                   d       ej"                  d       ej$                         defd                                   Ze ej(                  d      dee   fd              Zej,                  dee   ddfd       Ze ej(                  d      dee   fd              Zej,                  dee   ddfd       Ze ej(                  d      dee   fd              Zej,                  dee   ddfd       Ze ej2                  ej4                  j6                  d       ej(                  d      d3d                     Zej,                  dee   ddfd       Ze ej                   d       ej2                  ej4                  j:                  d       ej(                  d      d4d                             Zej,                  d	ee	   ddfd!       Ze ej                  e       ej(                  d"      dee   fd#                     Zej,                  d
eeeef      ddfd$       Ze ej2                  ej4                  j6                  d%       ej(                  d&      d5d'                     Z e j,                  dee
   ddfd(       Z e ej2                  ej4                  j6                  d)       ej(                  d*      d6d+                     Z!e!j,                  dee   ddfd,       Z!de"fd-Z#d.e$de%fd/Z&d.e'de%fd0Z(de)fd1Z*defd2Z+y)7Requirementz
    A requirement comprising a standard.

    .. note::
        See the CycloneDX Schema for hashType:
        https://cyclonedx.org/docs/1.7/json/#definitions_standards_items_requirements
    N)	bom_ref
identifiertitletextdescriptionsopen_creparent
propertiesexternal_referencesrP   rQ   rR   rS   rT   rU   rV   rW   rX   r   c       	             t        |      | _        || _        || _        || _        |xs d| _        |xs d| _        || _        |xs d| _        |	xs d| _	        y NrM   )
_bom_ref_from_str_bom_refrQ   rR   rS   rT   rU   rV   rW   rX   )
r   rP   rQ   rR   rS   rT   rU   rV   rW   rX   s
             r   r    zRequirement.__init__f   s]     *'2$
	(.B B$*#6#<" r!   bom-refc                     | j                   S )z
        An optional identifier which can be used to reference the requirement elsewhere in the BOM.
        Every bom-ref MUST be unique within the BOM.

        Returns:
            `BomRef`
        r\   r&   s    r   rP   zRequirement.bom_ref|        }}r!   r   c                     | j                   S )zI
        Returns:
            The identifier of the requirement.
        _identifierr&   s    r   rQ   zRequirement.identifier        r!   c                     || _         y r$   rb   r   rQ   s     r   rQ   zRequirement.identifier   
    %r!   r	   c                     | j                   S )zD
        Returns:
            The title of the requirement.
        _titler&   s    r   rR   zRequirement.title        {{r!   c                     || _         y r$   ri   r   rR   s     r   rR   zRequirement.title   	    r!      c                     | j                   S )zC
        Returns:
            The text of the requirement.
        _textr&   s    r   rS   zRequirement.text        zzr!   c                     || _         y r$   rq   )r   rS   s     r   rS   zRequirement.text   	    
r!   description   c                     | j                   S )zV
        Returns:
            A SortedSet of descriptions of the requirement.
        )_descriptionsr&   s    r   rT   zRequirement.descriptions        !!!r!   c                 $    t        |      | _        y r$   )r   ry   )r   rT   s     r   rT   zRequirement.descriptions       &|4r!   openCre   c                     | j                   S )a  
        CRE is a structured and standardized framework for uniting security standards and guidelines. CRE links each
        section of a resource to a shared topic identifier (a Common Requirement). Through this shared topic link, all
        resources map to each other. Use of CRE promotes clear and unambiguous communication among stakeholders.

        Returns:
            The Common Requirements Enumeration (CRE) identifier(s).
            CREs must match regular expression: ^CRE:[0-9]+-[0-9]+$
        )	_open_crer&   s    r   rU   zRequirement.open_cre   s     ~~r!   c                 $    t        |      | _        y r$   )r   r   )r   rU   s     r   rU   zRequirement.open_cre   s    "8,r!      c                     | j                   S )z
        Returns:
            The optional bom-ref to a parent requirement. This establishes a hierarchy of requirements. Top-level
            requirements must not define a parent. Only child requirements should define parents.
        )_parentr&   s    r   rV   zRequirement.parent   s     ||r!   c                 (    t        |d      | _        y )NT)optional)r[   r   )r   rV   s     r   rV   zRequirement.parent   s    ($?r!   rF      c                     | j                   S )a  
        Provides the ability to document properties in a key/value store. This provides flexibility to include data not
        officially supported in the standard without having to use additional namespaces or create extensions.

        Return:
            Set of `Property`
        )_propertiesr&   s    r   rW   zRequirement.properties   s     r!   c                 $    t        |      | _        y r$   )r   r   )r   rW   s     r   rW   zRequirement.properties   s    $Z0r!   	reference   c                     | j                   S )z
        Provides the ability to document external references related to the component or to the project the component
        describes.

        Returns:
            Set of `ExternalReference`
        _external_referencesr&   s    r   rX   zRequirement.external_references   s     (((r!   c                 $    t        |      | _        y r$   r   r   r   rX   s     r   rX   zRequirement.external_references      $-.A$B!r!   c                 :   t        | j                  | j                  j                  | j                  | j
                  t        | j                        t        | j                        | j                  t        | j                        t        | j                        f	      S r$   )_ComparableTuplerQ   rP   valuerR   rS   rT   rU   rV   rW   rX   r&   s    r   __comparable_tuplezRequirement.__comparable_tuple  sn    OOT\\//JJ		T../T]]+T[[:J4??:[T556!
  	r!   r0   c                 p    t        |t              r!| j                         |j                         k  S t        S r$   )r)   rO   _Requirement__comparable_tupler6   r3   s     r   r7   zRequirement.__lt__  /    e[)**,u/G/G/IIIr!   c                 f    t        |t              r!| j                         |j                         k(  S yr2   )r)   rO   r   r3   s     r   r4   zRequirement.__eq__  ,    e[)**,0H0H0JJJr!   c                 4    t        | j                               S r$   )r9   r   r&   s    r   r:   zRequirement.__hash__      D++-..r!   c                     d| j                    d| j                   d| j                   d| j                   d| j                   dS )Nz<Requirement bom-ref=, identifier=, title=z, text=z	, parent=r<   )r\   rQ   rR   rS   rV   r&   s    r   r=   zRequirement.__repr__  sI    &t}}o]4??BS TZZL		{)DKK=K 	Kr!   )r   zSortedSet[str])r   zSortedSet[CreId])r   zSortedSet[Property]r   zSortedSet[ExternalReference]),r@   rA   rB   rC   r   r   r*   r   r   r   r   r   r    rF   rG   type_mappingrH   rI   xml_attributerP   xml_sequencerQ   setterrR   rS   	xml_arrayXmlArraySerializationTypeNESTEDrT   FLATrU   rV   rW   rX   r   r   r   rK   r7   objectr4   rL   r:   r=   rM   r!   r   rO   rO   \   s1    15$(#"04.2/337EI=%V,-= SM= }	=
 sm= x}-= 8E?+= sF{+,= Xh/0= &h/@&AB= 
=, \v&\I&\9%\!  " & ' ' 
 \q! HSM   "   &Xc] &t & & \q!x}  "  \\8C= T   \q!hsm  "  
[[# 4   \LBBII=Y\q!" " Z " 5# 54 5 5 \I&\LBBGGS\q!
 " T ' 
 __-% -T - - \v&\q!(  " '  ]]@XeCK&89 @d @ @ \LBBII:V\q!  " W   1Xh%7 1D 1 1 \LBBII;W\q!) " X ) Cx@Q7R CW[ C  C$4 C D 
F t 
/# /K# Kr!   rO   c                      e Zd ZdZdddddddeeeef      dee   dee   dee   deeeeef         d	dfd
Z	e
 ej                  e       ej                  d       ej                  d       ej                         d	efd                                   Ze
 ej"                  d      d	ee   fd              Zej&                  dee   d	dfd       Ze
 ej"                  d      d	ee   fd              Zej&                  dee   d	dfd       Ze
 ej"                  d      d	ee   fd              Zej&                  dee   d	dfd       Ze
 ej"                  d       ej,                  ej.                  j0                  d      d d                     Zej&                  deeeef      d	dfd       Zd	efdZded	efdZded	efdZ d	e!fdZ"d	efdZ#y)!Levelz
    Level of compliance for a standard.

    .. note::
        See the CycloneDX Schema for hashType: https://cyclonedx.org/docs/1.7/json/#definitions_standards_items_levels
    N)rP   rQ   rR   rv   requirementsrP   rQ   rR   rv   r   r   c                d    t        |      | _        || _        || _        || _        |xs d| _        y rZ   )r[   r\   rQ   rR   rv   r   )r   rP   rQ   rR   rv   r   s         r   r    zLevel.__init__*  s3     *'2$
&(.Br!   r]   c                     | j                   S )z
        An optional identifier which can be used to reference the level elsewhere in the BOM.
        Every bom-ref MUST be unique within the BOM.

        Returns:
            `BomRef`
        r_   r&   s    r   rP   zLevel.bom_ref8  r`   r!   r   c                     | j                   S )zC
        Returns:
            The identifier of the level.
        rb   r&   s    r   rQ   zLevel.identifierG  rd   r!   c                     || _         y r$   rb   rf   s     r   rQ   zLevel.identifierP  rg   r!   r	   c                     | j                   S )z>
        Returns:
            The title of the level.
        ri   r&   s    r   rR   zLevel.titleT  rk   r!   c                     || _         y r$   ri   rm   s     r   rR   zLevel.title]  rn   r!   ro   c                     | j                   S )zD
        Returns:
            The description of the level.
        _descriptionr&   s    r   rv   zLevel.descriptiona          r!   c                     || _         y r$   r   r   rv   s     r   rv   zLevel.descriptionj  
    'r!   rw   requirementc                     | j                   S )z]
        Returns:
            A SortedSet of requirements associated with the level.
        _requirementsr&   s    r   r   zLevel.requirementsn  rz   r!   c                 @    t        t        t        |            | _        y r$   )r   mapr[   r   r   r   s     r   r   zLevel.requirementsx  s    &s+<+7(9 :r!   c           	          t        | j                  | j                  j                  | j                  | j
                  t        | j                        f      S r$   )r   rQ   rP   r   rR   rv   r   r&   s    r   r   zLevel.__comparable_tuple}  sD    OOT\\//JJ((T../!
  	r!   r0   c                 p    t        |t              r!| j                         |j                         k  S t        S r$   )r)   r   _Level__comparable_tupler6   r3   s     r   r7   zLevel.__lt__  s/    eU#**,u/G/G/IIIr!   c                 f    t        |t              r!| j                         |j                         k(  S yr2   )r)   r   r   r3   s     r   r4   zLevel.__eq__  s,    eU#**,0H0H0JJJr!   c                 4    t        | j                               S r$   )r9   r   r&   s    r   r:   zLevel.__hash__  r   r!   c           	      p    d| j                    d| j                   d| j                   d| j                   d	S )Nz<Level bom-ref=r   r   , description=r<   )rP   rQ   rR   rv   r&   s    r   r=   zLevel.__repr__  sB     mDOO;L MZZLt/?/?.@C 	Cr!   )r   zSortedSet[BomRef])$r@   rA   rB   rC   r   r   r*   r   r   r    rF   rG   r   rH   rI   r   rP   r   rQ   r   rR   rv   r   r   r   r   r   r   r   rK   r7   r   r4   rL   r:   r=   rM   r!   r   r   r   !  s    15$(#%)?C/%V,-/ SM/ }	/
 c]/ xc6k(:;</ 
/ \v&\I&\9%\!  " & ' ' 
 \q! HSM   "   &Xc] &t & & \q!x}  "  \\8C= T   \q!!Xc] ! " ! (x} ( ( ( \q!\LBBII=Y" Z " " :%V2D)E :$ : :$4 C D 
F t 
/# /C# Cr!   r   c                      e Zd ZdZddddddddddeeeef      dee   dee   dee   dee   d	eee	      d
eee
      deed      ddfdZe ej                  e       ej                  d       ej                   d       ej"                         defd                                   Ze ej&                  d      dee   fd              Zej*                  dee   ddfd       Ze ej&                  d      dee   fd              Zej*                  dee   ddfd       Ze ej&                  d      dee   fd              Zej*                  dee   ddfd       Ze ej&                  d      dee   fd              Zej*                  dee   ddfd       Ze ej2                  ej4                  j6                  d       ej&                  d      d/d                     Zej*                  d	ee	   ddfd        Ze ej2                  ej4                  j6                  d!       ej&                  d"      d0d#                     Zej*                  d
ee
   ddfd$       Ze ej2                  ej4                  j6                  d%       ej&                  d&      d1d'                     Zej*                  dee   ddfd(       Zde fd)Z!d*e"de#fd+Z$d*e%de#fd,Z&de'fd-Z(defd.Z)y)2Standarda  
    A standard of regulations, industry or organizational-specific standards, maturity models, best practices,
    or any other requirements.

    .. note::
        See the CycloneDX Schema for hashType: https://cyclonedx.org/docs/1.7/xml/#type_standard
    N)rP   nameversionrv   ownerr   levelsrX   rP   r   r   rv   r   r   r   rX   r   r   c                    t        |      | _        || _        || _        || _        || _        |xs d| _        |xs d| _        |xs d| _        y rZ   )	r[   r\   r   r   rv   r   r   r   rX   )	r   rP   r   r   rv   r   r   r   rX   s	            r   r    zStandard.__init__  sR     *'2	&
(.Bl#6#<" r!   r]   c                     | j                   S )z
        An optional identifier which can be used to reference the standard elsewhere in the BOM. Every bom-ref MUST be
        unique within the BOM.

        Returns:
            `BomRef`
        r_   r&   s    r   rP   zStandard.bom_ref  r`   r!   r   c                     | j                   S )z?
        Returns:
            The name of the standard
        _namer&   s    r   r   zStandard.name  rs   r!   c                     || _         y r$   r   )r   r   s     r   r   zStandard.name  ru   r!   r	   c                     | j                   S )zB
        Returns:
            The version of the standard
        _versionr&   s    r   r   zStandard.version  s     }}r!   c                     || _         y r$   r   )r   r   s     r   r   zStandard.version  s	    r!   ro   c                     | j                   S )zF
        Returns:
            The description of the standard
        r   r&   s    r   rv   zStandard.description  r   r!   c                     || _         y r$   r   r   s     r   rv   zStandard.description  r   r!   rw   c                     | j                   S )zo
        Returns:
            The owner of the standard, often the entity responsible for its release.
        _ownerr&   s    r   r   zStandard.owner  rk   r!   c                     || _         y r$   r   )r   r   s     r   r   zStandard.owner  rn   r!   r   r~   c                     | j                   S )z[
        Returns:
            A SortedSet of requirements comprising the standard.
        r   r&   s    r   r   zStandard.requirements  rz   r!   c                 $    t        |      | _        y r$   )r   r   r   s     r   r   zStandard.requirements  r|   r!   levelr   c                     | j                   S )z
        Returns:
            A SortedSet of levels associated with the standard. Some standards have different levels of compliance.
        )_levelsr&   s    r   r   zStandard.levels  s     ||r!   c                 $    t        |      | _        y r$   )r   r   )r   r   s     r   r   zStandard.levels  s     (r!   r   r   c                     | j                   S )zg
        Returns:
            A SortedSet of external references associated with the standard.
        r   r&   s    r   rX   zStandard.external_references  s     (((r!   c                 $    t        |      | _        y r$   r   r   s     r   rX   zStandard.external_references   r   r!   c                    t        | j                  | j                  | j                  j                  | j
                  | j                  t        | j                        t        | j                        t        | j                        f      S r$   )
r   r   r   rP   r   rv   r   r   r   rX   r&   s    r   r   zStandard.__comparable_tuple.  se    IIt||LLdjjT../1A$++1NT556!
  	r!   r0   c                 p    t        |t              r!| j                         |j                         k  S t        S r$   )r)   r   _Standard__comparable_tupler6   r3   s     r   r7   zStandard.__lt__8  s/    eX&**,u/G/G/IIIr!   c                 f    t        |t              r!| j                         |j                         k(  S yr2   )r)   r   r   r3   s     r   r4   zStandard.__eq__=  s,    eX&**,0H0H0JJJr!   c                 4    t        | j                               S r$   )r9   r   r&   s    r   r:   zStandard.__hash__B  r   r!   c                     d| j                    d| j                   d| j                   d| j                   d| j                   dS )Nz<Standard bom-ref=z, name=z
, version=r   z, owner=r<   )rP   r   r   rv   r   r&   s    r   r=   zStandard.__repr__E  sN    #DLL> 2II;j 7++,HTZZLC 	Cr!   )r   zSortedSet[Requirement])r   zSortedSet[Level]r   )*r@   rA   rB   rC   r   r   r*   r   r   rO   r   r    rF   rG   r   rH   rI   r   rP   r   r   r   r   rv   r   r   r   r   r   r   rX   r   r   r   r   rK   r7   r   r4   rL   r:   r=   rM   r!   r   r   r     s_    15"!%%)#8<,0GK=%V,-= sm= #	=
 c]= }= x45= %)= &h/B&CD= 
=, \v&\I&\9%\!  " & ' ' 
 \q!hsm  "  
[[# 4   \q!#  "  ^^ x}       \q!!Xc] ! " ! (x} ( ( ( \q!x}  "  \\8C= T   \LBBII=Y\q!" " Z " 5+)> 54 5 5 \LBBII7S\q! " T  ]])Xe_ ) ) ) \LBBII;W\q!) " X ) Cx@Q7R CW[ C  C$4 C D 
F t 
/# /C# Cr!   r   definitions)r   r   c                   F   e Zd ZdZdddeee      ddfdZe e	j                  e	j                  j                  d       e	j                  d      dd	                     Zej                  dee   ddfd
       ZdefdZdefdZdedefdZdedefdZdefdZdefdZy)Definitionsz
    The repository for definitions

    .. note::
        See the CycloneDX Schema for hashType: https://cyclonedx.org/docs/1.7/xml/#type_definitionsType
    N	standardsr   r   c                    |xs d| _         y rZ   r   r   r   s     r   r    zDefinitions.__init__W  s     #br!   standardr   c                     | j                   S )z?
        Returns:
            A SortedSet of Standards
        )
_standardsr&   s    r   r   zDefinitions.standards]  s     r!   c                 $    t        |      | _        y r$   )r   r   r   s     r   r   zDefinitions.standardsg  s    #I.r!   c                 2    t        | j                        dkD  S )Nr   )lenr   r&   s    r   __bool__zDefinitions.__bool__k  s    4??#a''r!   c                 ,    t        | j                        S r$   )r   r   r&   s    r   r   zDefinitions.__comparable_tuplen  s    00r!   r0   c                 f    t        |t              r!| j                         |j                         k(  S yr2   )r)   r   _Definitions__comparable_tupler3   s     r   r4   zDefinitions.__eq__r  r   r!   c                 p    t        |t              r!| j                         |j                         k  S t        S r$   )r)   r   r   r6   r3   s     r   r7   zDefinitions.__lt__w  r   r!   c                 4    t        | j                               S r$   )r9   r   r&   s    r   r:   zDefinitions.__hash__|  r   r!   c                 "    d| j                   dS )Nz<Definitions standards=z >r   r&   s    r   r=   zDefinitions.__repr__  s    ((:"==r!   )r   zSortedSet[Standard])r@   rA   rB   rC   r   r   r   r    rF   rG   r   r   r   r   r   r   rK   r   r   r   r   r4   r   r7   rL   r:   r*   r=   rM   r!   r   r   r   K  s    
 37)HX./) 
) \LBBII:V\q! " W  /8H#5 /$ / /($ (1$4 1F t 
C D 
/# /># >r!   r   )%rD   collections.abcr   typingr   r   r   r   py_serializablerG   sortedcontainersr   _internal.bom_refr
   r[   _internal.comparer   r   exception.modelr   exception.serializationr    r   r   rP   r   r   r   serializable_classhelpers
BaseHelperr   rO   r   r   r   rM   r!   r   <module>r     s)  $ 
 $ 6 6 & & E C 3 M ) z1H !  tL2L  ++ 2 M2j !  tLAK AK MAKH !  tLrC rC MrCj !  tLpC pC MpCf !  	*.1> 1>	1>r!   